summaryrefslogtreecommitdiff
path: root/gtk/updateiconcache.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2005-11-06 06:27:01 +0000
committerTor Lillqvist <tml@src.gnome.org>2005-11-06 06:27:01 +0000
commit30edb631342d826c4e4221aaa982d4ed3187a1b3 (patch)
treee52f992623333da128ab569be254d3622d2f42c6 /gtk/updateiconcache.c
parentbd9e367de7faaee29d326a7a7c4a8eaf99f79d64 (diff)
downloadgdk-pixbuf-30edb631342d826c4e4221aaa982d4ed3187a1b3.tar.gz
Can't rename a file if the target exists on Win32. First rename the target
2005-11-06 Tor Lillqvist <tml@novell.com> * gtk/updateiconcache.c (build_cache): Can't rename a file if the target exists on Win32. First rename the target temporarily, then if the renaming of the source to target fails, restore the original name for the target. * gtk/Makefile.am: Use EXEEXT in the dependency on gtk-update-icon-cache.
Diffstat (limited to 'gtk/updateiconcache.c')
-rw-r--r--gtk/updateiconcache.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c
index 31906f952..9453e7397 100644
--- a/gtk/updateiconcache.c
+++ b/gtk/updateiconcache.c
@@ -1143,6 +1143,9 @@ void
build_cache (const gchar *path)
{
gchar *cache_path, *tmp_cache_path;
+#ifdef G_OS_WIN32
+ gchar *bak_cache_path = NULL;
+#endif
GHashTable *files;
gboolean retval;
FILE *cache;
@@ -1188,11 +1191,42 @@ build_cache (const gchar *path)
cache_path = g_build_filename (path, CACHE_NAME, NULL);
+#ifdef G_OS_WIN32
+ if (g_file_test (cache_path, G_FILE_TEST_EXISTS))
+ {
+ bak_cache_path = g_strconcat (cache_path, ".bak", NULL);
+ g_unlink (bak_cache_path);
+ if (g_rename (cache_path, bak_cache_path) == -1)
+ {
+ g_printerr ("Could not rename %s to %s: %s, removing %s then.\n",
+ cache_path, bak_cache_path,
+ g_strerror (errno),
+ cache_path);
+ g_unlink (cache_path);
+ bak_cache_path = NULL;
+ }
+ }
+#endif
+
if (g_rename (tmp_cache_path, cache_path) == -1)
{
+ g_printerr ("Could not rename %s to %s: %s\n",
+ tmp_cache_path, cache_path,
+ g_strerror (errno));
g_unlink (tmp_cache_path);
+#ifdef G_OS_WIN32
+ if (bak_cache_path != NULL)
+ if (g_rename (bak_cache_path, cache_path) == -1)
+ g_printerr ("Could not rename %s back to %s: %s.\n",
+ bak_cache_path, cache_path,
+ g_strerror (errno));
+#endif
exit (1);
}
+#ifdef G_OS_WIN32
+ if (bak_cache_path != NULL)
+ g_unlink (bak_cache_path);
+#endif
/* Update time */
/* FIXME: What do do if an error occurs here? */