summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-06-09 14:03:47 -0400
committerColin Walters <walters@verbum.org>2009-06-09 14:03:47 -0400
commit87db94d98c133998f4f8156719256bbeedfdd5c0 (patch)
tree6bc516feb1c9efb1bd1854e311976d831ac8572e /tools
parentb23ca1ec2afeed3c5ab914c996c1dd73870ecab6 (diff)
downloadgobject-introspection-87db94d98c133998f4f8156719256bbeedfdd5c0.tar.gz
Bug 577534 - Use rename to write new typelibs, instead of in-place overwrite
This avoids having processes with the typelibs currently open exploding immediately.
Diffstat (limited to 'tools')
-rw-r--r--tools/compiler.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/tools/compiler.c b/tools/compiler.c
index 6c6bae63..7e0a6004 100644
--- a/tools/compiler.c
+++ b/tools/compiler.c
@@ -23,6 +23,7 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#ifdef G_OS_WIN32
#include <io.h>
@@ -97,34 +98,38 @@ write_out_typelib (gchar *prefix,
{
FILE *file;
gsize written;
+ GFile *file_obj;
+ gchar *filename;
+ GFile *tmp_file_obj;
+ gchar *tmp_filename;
+ GError *error = NULL;
if (output == NULL)
{
file = stdout;
+ filename = NULL;
+ tmp_filename = NULL;
#ifdef G_OS_WIN32
setmode (fileno (file), _O_BINARY);
#endif
}
else
{
- gchar *filename;
-
if (prefix)
filename = g_strdup_printf ("%s-%s", prefix, output);
else
filename = g_strdup (output);
- file = g_fopen (filename, "wb");
+ file_obj = g_file_new_for_path (filename);
+ tmp_filename = g_strdup_printf ("%s.tmp", filename);
+ tmp_file_obj = g_file_new_for_path (tmp_filename);
+ file = g_fopen (tmp_filename, "wb");
if (file == NULL)
{
g_fprintf (stderr, "failed to open '%s': %s\n",
- filename, g_strerror (errno));
- g_free (filename);
-
- return;
+ tmp_filename, g_strerror (errno));
+ goto out;
}
-
- g_free (filename);
}
if (!code)
@@ -133,7 +138,7 @@ write_out_typelib (gchar *prefix,
if (written < typelib->len) {
g_error ("ERROR: Could not write the whole output: %s",
strerror(errno));
- return;
+ goto out;
}
}
else
@@ -146,7 +151,18 @@ write_out_typelib (gchar *prefix,
}
if (output != NULL)
- fclose (file);
+ fclose (file);
+ if (tmp_filename != NULL)
+ {
+ if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))
+ {
+ g_error ("ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message);
+ g_clear_error (&error);
+ }
+ }
+out:
+ g_free (filename);
+ g_free (tmp_filename);
}
GLogLevelFlags logged_levels;