File gtk2-remove-empty-cache.patch of Package gtk2

Index: gtk/updateiconcache.c
===================================================================
--- gtk/updateiconcache.c.orig
+++ gtk/updateiconcache.c
@@ -47,6 +47,7 @@ static gboolean quiet = FALSE;
 static gboolean index_only = FALSE;
 static gboolean validate = FALSE;
 static gchar *var_name = "-";
+static gboolean remove_empty_cache = FALSE;
 
 /* Quite ugly - if we just add the c file to the
  * list of sources in Makefile.am, libtool complains.
@@ -1452,12 +1453,17 @@ build_cache (const gchar *path)
  
   directories = scan_directory (path, NULL, files, NULL, 0);
 
+  cache_path = g_build_filename (path, CACHE_NAME, NULL);
+
   if (g_hash_table_size (files) == 0)
     {
       /* Empty table, just close and remove the file */
 
       fclose (cache);
       g_unlink (tmp_cache_path);
+      if (remove_empty_cache)
+	  g_unlink (cache_path);
+      g_free (cache_path);
       exit (0);
     }
     
@@ -1471,6 +1477,7 @@ build_cache (const gchar *path)
   if (!retval)
     {
       g_unlink (tmp_cache_path);
+      g_free (cache_path);
       exit (1);
     }
 
@@ -1481,8 +1488,6 @@ build_cache (const gchar *path)
       exit (1);
     }
 
-  cache_path = g_build_filename (path, CACHE_NAME, NULL);
-
 #ifdef G_OS_WIN32
   if (g_file_test (cache_path, G_FILE_TEST_EXISTS))
     {
@@ -1495,6 +1500,7 @@ build_cache (const gchar *path)
 		      g_strerror (errno),
 		      cache_path);
 	  g_unlink (cache_path);
+	  g_free (cache_path);
 	  bak_cache_path = NULL;
 	}
     }
@@ -1506,6 +1512,7 @@ build_cache (const gchar *path)
 		  tmp_cache_path, cache_path,
 		  g_strerror (errno));
       g_unlink (tmp_cache_path);
+      g_free (cache_path);
 #ifdef G_OS_WIN32
       if (bak_cache_path != NULL)
 	if (g_rename (bak_cache_path, cache_path) == -1)
@@ -1524,12 +1531,17 @@ build_cache (const gchar *path)
   /* FIXME: What do do if an error occurs here? */
   if (g_stat (path, &path_stat) < 0 ||
       g_stat (cache_path, &cache_stat))
-    exit (1);
+    {
+      g_free (cache_path);
+      exit (1);
+    }
 
   utime_buf.actime = path_stat.st_atime;
   utime_buf.modtime = cache_stat.st_mtime;
   utime (path, &utime_buf);
   
+  g_free (cache_path);
+
   if (!quiet)
     g_printerr (_("Cache file created successfully.\n"));
 }
@@ -1573,6 +1585,7 @@ static GOptionEntry args[] = {
   { "force", 'f', 0, G_OPTION_ARG_NONE, &force_update, N_("Overwrite an existing cache, even if up to date"), NULL },
   { "ignore-theme-index", 't', 0, G_OPTION_ARG_NONE, &ignore_theme_index, N_("Don't check for the existence of index.theme"), NULL },
   { "index-only", 'i', 0, G_OPTION_ARG_NONE, &index_only, N_("Don't include image data in the cache"), NULL },
+  { "remove-empty-cache", 'r', 0, G_OPTION_ARG_NONE, &remove_empty_cache, "Remove the cache file if there is nothing to cache", NULL },
   { "source", 'c', 0, G_OPTION_ARG_STRING, &var_name, N_("Output a C header file"), "NAME" },
   { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Turn off verbose output"), NULL },
   { "validate", 'v', 0, G_OPTION_ARG_NONE, &validate, N_("Validate existing icon cache"), NULL },
openSUSE Build Service is sponsored by