Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
xdg
shared-mime-info
Commits
da5d7650
Commit
da5d7650
authored
Mar 03, 2003
by
Thomas Leonard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that all changes to generated files happen atomically.
parent
6534fb95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
NEWS
NEWS
+2
-0
update-mime-database.c
update-mime-database.c
+30
-11
No files found.
NEWS
View file @
da5d7650
...
...
@@ -3,6 +3,8 @@ shared-mime-info Thomas Leonard <tal00r@ecs.soton.ac.uk>
Version 0.10 (03-Mar-2003)
* Ensure that all changes to generated files happen atomically.
* Change to half-text, half-binary format to make parsing the magic file
much easier.
...
...
update-mime-database.c
View file @
da5d7650
...
...
@@ -433,11 +433,29 @@ static void write_out_glob(gpointer key, gpointer value, gpointer data)
fprintf
(
stream
,
"%s/%s:%s
\n
"
,
type
->
media
,
type
->
subtype
,
pattern
);
}
/* Renames pathname by removing the .new extension */
static
void
atomic_update
(
const
guchar
*
pathname
)
{
guchar
*
new_name
;
int
len
;
len
=
strlen
(
pathname
);
g_return_if_fail
(
strcmp
(
pathname
+
len
-
4
,
".new"
)
==
0
);
new_name
=
g_strndup
(
pathname
,
len
-
4
);
if
(
rename
(
pathname
,
new_name
))
g_warning
(
"Failed to rename %s as %s
\n
"
,
pathname
,
new_name
);
g_free
(
new_name
);
}
static
void
write_out_type
(
gpointer
key
,
gpointer
value
,
gpointer
data
)
{
Type
*
type
=
(
Type
*
)
value
;
const
char
*
mime_dir
=
(
char
*
)
data
;
char
*
media
,
*
filename
,
*
new_name
;
char
*
media
,
*
filename
;
media
=
g_strconcat
(
mime_dir
,
"/"
,
type
->
media
,
NULL
);
mkdir
(
media
,
0755
);
...
...
@@ -449,13 +467,9 @@ static void write_out_type(gpointer key, gpointer value, gpointer data)
if
(
save_xml_file
(
type
->
output
,
filename
)
!=
0
)
g_warning
(
"Failed to write out '%s'
\n
"
,
filename
);
new_name
=
g_strndup
(
filename
,
strlen
(
filename
)
-
4
);
if
(
rename
(
filename
,
new_name
))
g_warning
(
"Failed to rename %s as %s
\n
"
,
filename
,
new_name
);
atomic_update
(
filename
);
g_free
(
filename
);
g_free
(
new_name
);
}
static
int
get_priority
(
xmlNode
*
node
)
...
...
@@ -968,27 +982,29 @@ int main(int argc, char **argv)
{
FILE
*
globs
;
char
*
globs_path
;
globs_path
=
g_strconcat
(
mime_dir
,
"/globs"
,
NULL
);
globs_path
=
g_strconcat
(
mime_dir
,
"/globs
.new
"
,
NULL
);
globs
=
fopen
(
globs_path
,
"wb"
);
if
(
!
globs
)
g_error
(
"Failed to open '%s' for writing
\n
"
,
globs_path
);
g_free
(
globs_path
);
fprintf
(
globs
,
"# This file was automatically generated by the
\n
"
"# update-mime-database command. DO NOT EDIT!
\n
"
);
g_hash_table_foreach
(
globs_hash
,
write_out_glob
,
globs
);
fclose
(
globs
);
atomic_update
(
globs_path
);
g_free
(
globs_path
);
}
{
FILE
*
stream
;
char
*
magic_path
;
int
i
;
magic_path
=
g_strconcat
(
mime_dir
,
"/magic"
,
NULL
);
magic_path
=
g_strconcat
(
mime_dir
,
"/magic
.new
"
,
NULL
);
stream
=
fopen
(
magic_path
,
"wb"
);
if
(
!
stream
)
g_error
(
"Failed to open '%s' for writing
\n
"
,
magic_path
);
g_free
(
magic_path
);
g_error
(
"Failed to open '%s' for writing
\n
"
,
magic_path
);
fwrite
(
"MIME-Magic
\0\n
"
,
1
,
12
,
stream
);
if
(
magic
->
len
)
...
...
@@ -1000,6 +1016,9 @@ int main(int argc, char **argv)
write_magic
(
stream
,
node
);
}
fclose
(
stream
);
atomic_update
(
magic_path
);
g_free
(
magic_path
);
}
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment