Index: gtk/updateiconcache.c =================================================================== --- gtk/updateiconcache.c.orig +++ gtk/updateiconcache.c @@ -49,6 +49,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. @@ -1470,6 +1471,8 @@ 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 */ @@ -1477,6 +1480,9 @@ build_cache (const gchar *path) fclose (cache); close (fd); g_unlink (tmp_cache_path); + if (remove_empty_cache) + g_unlink (cache_path); + g_free (cache_path); exit (0); } @@ -1491,6 +1497,7 @@ build_cache (const gchar *path) if (!retval) { g_unlink (tmp_cache_path); + g_free (cache_path); exit (1); } @@ -1501,8 +1508,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)) { @@ -1515,6 +1520,7 @@ build_cache (const gchar *path) g_strerror (errno), cache_path); g_unlink (cache_path); + g_free (cache_path); bak_cache_path = NULL; } } @@ -1526,6 +1532,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) @@ -1544,7 +1551,10 @@ 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; @@ -1554,6 +1564,8 @@ build_cache (const gchar *path) utime (path, &utime_buf); #endif + g_free (cache_path); + if (!quiet) g_printerr (_("Cache file created successfully.\n")); } @@ -1597,6 +1609,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 },