Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 144330 Details for
Bug 170335
gtk2: create/maintain icon cache
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
patch
delay.patch (text/plain), 25.23 KB, created by
Matthias Clasen
on 2006-12-23 06:58:56 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Matthias Clasen
Created:
2006-12-23 06:58:56 UTC
Size:
25.23 KB
patch
obsolete
>Index: gtk/updateiconcache.c >=================================================================== >RCS file: /cvs/gnome/gtk+/gtk/updateiconcache.c,v >retrieving revision 1.20 >diff -u -r1.20 updateiconcache.c >--- gtk/updateiconcache.c 19 Jun 2006 22:32:02 -0000 1.20 >+++ gtk/updateiconcache.c 23 Dec 2006 06:52:34 -0000 >@@ -27,6 +27,7 @@ > #ifdef HAVE_UNISTD_H > #include <unistd.h> > #endif >+#include <utime.h> > #include <errno.h> > #ifdef _MSC_VER > #include <sys/utime.h> >@@ -44,6 +45,7 @@ > static gboolean quiet = FALSE; > static gboolean index_only = FALSE; > static gchar *var_name = "-"; >+static gint delay = 0; > > #define CACHE_NAME "icon-theme.cache" > >@@ -846,24 +848,24 @@ > > /* Directory index */ > if (!write_card16 (cache, image->dir_index)) >- return FALSE; >- >+ return FALSE; >+ > /* Flags */ > if (!write_card16 (cache, image->flags)) >- return FALSE; >+ return FALSE; > > /* Image data offset */ > if (image_data_size > 0) >- { >- if (!write_card32 (cache, data_offset)) >- return FALSE; >- data_offset += image_data_size; >- } >+ { >+ if (!write_card32 (cache, data_offset)) >+ return FALSE; >+ data_offset += image_data_size; >+ } > else >- { >- if (!write_card32 (cache, 0)) >- return FALSE; >- } >+ { >+ if (!write_card32 (cache, 0)) >+ return FALSE; >+ } > > list = list->next; > } >@@ -871,426 +873,547 @@ > /* Now write the image data */ > list = node->image_list; > for (i = 0; i < len; i++, list = list->next) >- { >- Image *image = list->data; >- int pixel_data_size = get_image_pixel_data_size (image); >- int meta_data_size = get_image_meta_data_size (image); >- >- if (get_image_data_size (image) == 0) >- continue; >- >- /* Pixel data */ >- if (pixel_data_size > 0) >- { >- if (!write_card32 (cache, image_data_offset + 8)) >- return FALSE; >- >- image->image_data->offset = image_data_offset + 8; >- } >- else >- { >- gint offset; >- >- if (image->image_data) >- offset = image->image_data->offset; >- else >- offset = 0; >- >- if (!write_card32 (cache, offset)) >- return FALSE; >- } >- >- if (meta_data_size > 0) >- { >- if (!write_card32 (cache, image_data_offset + pixel_data_size + 8)) >- return FALSE; >- } >- else >- { >- if (!write_card32 (cache, 0)) >- return FALSE; >- } >- >- if (pixel_data_size > 0) >- { >- if (!write_pixdata (cache, &image->image_data->pixdata)) >- return FALSE; >- } >- >- if (meta_data_size > 0) >- { >- int ofs = image_data_offset + pixel_data_size + 20; >+ { >+ Image *image = list->data; >+ int pixel_data_size = get_image_pixel_data_size (image); >+ int meta_data_size = get_image_meta_data_size (image); >+ >+ if (get_image_data_size (image) == 0) >+ continue; >+ >+ /* Pixel data */ >+ if (pixel_data_size > 0) >+ { >+ if (!write_card32 (cache, image_data_offset + 8)) >+ return FALSE; > >- if (image->has_embedded_rect) >- { >- if (!write_card32 (cache, ofs)) >- return FALSE; >- >- ofs += 8; >- } >+ image->image_data->offset = image_data_offset + 8; >+ } > else >- { >- if (!write_card32 (cache, 0)) >- return FALSE; >- } >- >- if (image->n_attach_points > 0) >- { >- if (!write_card32 (cache, ofs)) >- return FALSE; >+ { >+ gint offset; > >- ofs += 4 + 4 * image->n_attach_points; >- } >+ if (image->image_data) >+ offset = image->image_data->offset; >+ else >+ offset = 0; >+ >+ if (!write_card32 (cache, offset)) >+ return FALSE; >+ } >+ >+ if (meta_data_size > 0) >+ { >+ if (!write_card32 (cache, image_data_offset + pixel_data_size + 8)) >+ return FALSE; >+ } > else >- { >- if (!write_card32 (cache, 0)) >- return FALSE; >- } >- >- if (image->n_display_names > 0) >- { >- if (!write_card32 (cache, ofs)) >- return FALSE; >- } >- else >- { >- if (!write_card32 (cache, 0)) >- return FALSE; >- } >- >- if (image->has_embedded_rect) >- { >- if (!write_card16 (cache, image->x0) || >- !write_card16 (cache, image->y0) || >- !write_card16 (cache, image->x1) || >- !write_card16 (cache, image->y1)) >- return FALSE; >- } >- >- if (image->n_attach_points > 0) >- { >- if (!write_card32 (cache, image->n_attach_points)) >- return FALSE; >- >- for (j = 0; j < 2 * image->n_attach_points; j++) >- { >- if (!write_card16 (cache, image->attach_points[j])) >- return FALSE; >- } >- } >+ { >+ if (!write_card32 (cache, 0)) >+ return FALSE; >+ } >+ >+ if (pixel_data_size > 0) >+ { >+ if (!write_pixdata (cache, &image->image_data->pixdata)) >+ return FALSE; >+ } >+ >+ if (meta_data_size > 0) >+ { >+ int ofs = image_data_offset + pixel_data_size + 20; >+ >+ if (image->has_embedded_rect) >+ { >+ if (!write_card32 (cache, ofs)) >+ return FALSE; >+ >+ ofs += 8; >+ } >+ else >+ { >+ if (!write_card32 (cache, 0)) >+ return FALSE; >+ } >+ >+ if (image->n_attach_points > 0) >+ { >+ if (!write_card32 (cache, ofs)) >+ return FALSE; >+ >+ ofs += 4 + 4 * image->n_attach_points; >+ } >+ else >+ { >+ if (!write_card32 (cache, 0)) >+ return FALSE; >+ } >+ >+ if (image->n_display_names > 0) >+ { >+ if (!write_card32 (cache, ofs)) >+ return FALSE; >+ } >+ else >+ { >+ if (!write_card32 (cache, 0)) >+ return FALSE; >+ } >+ >+ if (image->has_embedded_rect) >+ { >+ if (!write_card16 (cache, image->x0) || >+ !write_card16 (cache, image->y0) || >+ !write_card16 (cache, image->x1) || >+ !write_card16 (cache, image->y1)) >+ return FALSE; >+ } >+ >+ if (image->n_attach_points > 0) >+ { >+ if (!write_card32 (cache, image->n_attach_points)) >+ return FALSE; >+ >+ for (j = 0; j < 2 * image->n_attach_points; j++) >+ { >+ if (!write_card16 (cache, image->attach_points[j])) >+ return FALSE; >+ } >+ } >+ >+ if (image->n_display_names > 0) >+ { >+ if (!write_card32 (cache, image->n_display_names)) >+ return FALSE; >+ >+ ofs += 4 + 8 * image->n_display_names; >+ >+ for (j = 0; j < 2 * image->n_display_names; j++) >+ { >+ if (!write_card32 (cache, ofs)) >+ return FALSE; >+ >+ ofs += ALIGN_VALUE (strlen (image->display_names[j]) + 1, 4); >+ } >+ >+ for (j = 0; j < 2 * image->n_display_names; j++) >+ { >+ if (!write_string (cache, image->display_names[j])) >+ return FALSE; >+ } >+ } >+ } > >- if (image->n_display_names > 0) >- { >- if (!write_card32 (cache, image->n_display_names)) >- return FALSE; >- >- ofs += 4 + 8 * image->n_display_names; >- >- for (j = 0; j < 2 * image->n_display_names; j++) >- { >- if (!write_card32 (cache, ofs)) >- return FALSE; >- >- ofs += ALIGN_VALUE (strlen (image->display_names[j]) + 1, 4); >- } >- >- for (j = 0; j < 2 * image->n_display_names; j++) >- { >- if (!write_string (cache, image->display_names[j])) >- return FALSE; >- } >- } >- } >+ image_data_offset += pixel_data_size + meta_data_size + 8; >+ } > >- image_data_offset += pixel_data_size + meta_data_size + 8; >- } >- > *offset = next_offset; > node = node->next; > } >- >+ > return TRUE; > } > > gboolean > write_hash_table (FILE *cache, HashContext *context, int *new_offset) > { >- int offset = HASH_OFFSET; >- int node_offset; >- int i; >+ int offset = HASH_OFFSET; >+ int node_offset; >+ int i; > >- if (!(write_card32 (cache, context->size))) >- return FALSE; >+ if (!(write_card32 (cache, context->size))) >+ return FALSE; > >- /* Size int + size * 4 */ >- node_offset = offset + 4 + context->size * 4; >- >- for (i = 0; i < context->size; i++) >- { >- if (context->nodes[i] != NULL) >- { >- if (!write_card32 (cache, node_offset)) >- return FALSE; >- >- node_offset += get_bucket_size (context->nodes[i]); >- } >- else >+ /* Size int + size * 4 */ >+ node_offset = offset + 4 + context->size * 4; >+ >+ for (i = 0; i < context->size; i++) > { >- if (!write_card32 (cache, 0xffffffff)) >- { >- return FALSE; >- } >+ if (context->nodes[i] != NULL) >+ { >+ if (!write_card32 (cache, node_offset)) >+ return FALSE; >+ >+ node_offset += get_bucket_size (context->nodes[i]); >+ } >+ else >+ { >+ if (!write_card32 (cache, 0xffffffff)) >+ { >+ return FALSE; >+ } >+ } > } >- } > >- *new_offset = node_offset; >+ *new_offset = node_offset; > >- /* Now write the buckets */ >- node_offset = offset + 4 + context->size * 4; >- >- for (i = 0; i < context->size; i++) >- { >- if (!context->nodes[i]) >- continue; >+ /* Now write the buckets */ >+ node_offset = offset + 4 + context->size * 4; > >- if (!write_bucket (cache, context->nodes[i], &node_offset)) >- return FALSE; >- } >+ for (i = 0; i < context->size; i++) >+ { >+ if (!context->nodes[i]) >+ continue; > >- return TRUE; >+ if (!write_bucket (cache, context->nodes[i], &node_offset)) >+ return FALSE; >+ } >+ >+ return TRUE; > } > > gboolean > write_dir_index (FILE *cache, int offset, GList *directories) > { >- int n_dirs; >- GList *d; >- char *dir; >+ int n_dirs; >+ GList *d; >+ char *dir; > >- n_dirs = g_list_length (directories); >+ n_dirs = g_list_length (directories); > >- if (!write_card32 (cache, n_dirs)) >- return FALSE; >+ if (!write_card32 (cache, n_dirs)) >+ return FALSE; > >- offset += 4 + n_dirs * 4; >+ offset += 4 + n_dirs * 4; > >- for (d = directories; d; d = d->next) >- { >- dir = d->data; >- if (!write_card32 (cache, offset)) >- return FALSE; >- >- offset += ALIGN_VALUE (strlen (dir) + 1, 4); >- } >+ for (d = directories; d; d = d->next) >+ { >+ dir = d->data; >+ if (!write_card32 (cache, offset)) >+ return FALSE; > >- for (d = directories; d; d = d->next) >- { >- dir = d->data; >+ offset += ALIGN_VALUE (strlen (dir) + 1, 4); >+ } > >- if (!write_string (cache, dir)) >- return FALSE; >- } >- >- return TRUE; >+ for (d = directories; d; d = d->next) >+ { >+ dir = d->data; >+ >+ if (!write_string (cache, dir)) >+ return FALSE; >+ } >+ >+ return TRUE; > } > > gboolean > write_file (FILE *cache, GHashTable *files, GList *directories) > { >- HashContext context; >- int new_offset; >+ HashContext context; >+ int new_offset; > >- /* Convert the hash table into something looking a bit more >- * like what we want to write to disk. >- */ >- context.size = g_spaced_primes_closest (g_hash_table_size (files) / 3); >- context.nodes = g_new0 (HashNode *, context.size); >- >- g_hash_table_foreach_remove (files, convert_to_hash, &context); >- >- /* Now write the file */ >- /* We write 0 as the directory list offset and go >- * back and change it later */ >- if (!write_header (cache, 0)) >- { >- g_printerr (_("Failed to write header\n")); >- return FALSE; >- } >+ /* Convert the hash table into something looking a bit more >+ * like what we want to write to disk. >+ */ >+ context.size = g_spaced_primes_closest (g_hash_table_size (files) / 3); >+ context.nodes = g_new0 (HashNode *, context.size); >+ >+ g_hash_table_foreach_remove (files, convert_to_hash, &context); >+ >+ /* Now write the file */ >+ /* We write 0 as the directory list offset and go >+ * back and change it later */ >+ if (!write_header (cache, 0)) >+ { >+ g_printerr (_("Failed to write header\n")); >+ return FALSE; >+ } > >- if (!write_hash_table (cache, &context, &new_offset)) >- { >- g_printerr (_("Failed to write hash table\n")); >- return FALSE; >- } >+ if (!write_hash_table (cache, &context, &new_offset)) >+ { >+ g_printerr (_("Failed to write hash table\n")); >+ return FALSE; >+ } > >- if (!write_dir_index (cache, new_offset, directories)) >- { >- g_printerr (_("Failed to write directory index\n")); >- return FALSE; >- } >- >- rewind (cache); >+ if (!write_dir_index (cache, new_offset, directories)) >+ { >+ g_printerr (_("Failed to write directory index\n")); >+ return FALSE; >+ } > >- if (!write_header (cache, new_offset)) >- { >- g_printerr (_("Failed to rewrite header\n")); >- return FALSE; >- } >- >- return TRUE; >+ rewind (cache); >+ >+ if (!write_header (cache, new_offset)) >+ { >+ g_printerr (_("Failed to rewrite header\n")); >+ return FALSE; >+ } >+ >+ return TRUE; > } > > void > build_cache (const gchar *path) > { >- gchar *cache_path, *tmp_cache_path; >+ gchar *cache_path, *tmp_cache_path; > #ifdef G_OS_WIN32 >- gchar *bak_cache_path = NULL; >+ gchar *bak_cache_path = NULL; > #endif >- GHashTable *files; >- gboolean retval; >- FILE *cache; >- struct stat path_stat, cache_stat; >- struct utimbuf utime_buf; >- GList *directories = NULL; >- >- tmp_cache_path = g_build_filename (path, "."CACHE_NAME, NULL); >- cache = g_fopen (tmp_cache_path, "wb"); >- >- if (!cache) >- { >- g_printerr (_("Failed to write cache file: %s\n"), g_strerror (errno)); >- exit (1); >- } >+ GHashTable *files; >+ gboolean retval; >+ FILE *cache; >+ struct stat path_stat, cache_stat; >+ struct utimbuf utime_buf; >+ GList *directories = NULL; > >- files = g_hash_table_new (g_str_hash, g_str_equal); >- image_data_hash = g_hash_table_new (g_str_hash, g_str_equal); >- >- directories = scan_directory (path, NULL, files, NULL, 0); >+ tmp_cache_path = g_build_filename (path, "."CACHE_NAME, NULL); >+ cache = g_fopen (tmp_cache_path, "wb"); > >- if (g_hash_table_size (files) == 0) >- { >- /* Empty table, just close and remove the file */ >+ if (!cache) >+ { >+ g_printerr (_("Failed to write cache file: %s\n"), g_strerror (errno)); >+ exit (1); >+ } > >- fclose (cache); >- g_unlink (tmp_cache_path); >- exit (0); >- } >- >- /* FIXME: Handle failure */ >- retval = write_file (cache, files, directories); >- fclose (cache); >+ files = g_hash_table_new (g_str_hash, g_str_equal); >+ image_data_hash = g_hash_table_new (g_str_hash, g_str_equal); > >- g_list_foreach (directories, (GFunc)g_free, NULL); >- g_list_free (directories); >- >- if (!retval) >- { >- g_unlink (tmp_cache_path); >- exit (1); >- } >+ 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); >+ exit (0); >+ } >+ >+ /* FIXME: Handle failure */ >+ retval = write_file (cache, files, directories); >+ fclose (cache); >+ >+ g_list_foreach (directories, (GFunc)g_free, NULL); >+ g_list_free (directories); >+ >+ if (!retval) >+ { >+ g_unlink (tmp_cache_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)) >- { >- 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; >+ 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); >+ 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)); >+ 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); >- } >+ exit (1); >+ } > #ifdef G_OS_WIN32 >- if (bak_cache_path != NULL) >- g_unlink (bak_cache_path); >+ if (bak_cache_path != NULL) >+ g_unlink (bak_cache_path); > #endif > >- /* Update time */ >- /* FIXME: What do do if an error occurs here? */ >- if (g_stat (path, &path_stat) < 0 || >- g_stat (cache_path, &cache_stat)) >- exit (1); >- >- utime_buf.actime = path_stat.st_atime; >- utime_buf.modtime = cache_stat.st_mtime; >- utime (path, &utime_buf); >- >- if (!quiet) >- g_printerr (_("Cache file created successfully.\n")); >+ /* Update time */ >+ /* FIXME: What do do if an error occurs here? */ >+ if (g_stat (path, &path_stat) < 0 || >+ g_stat (cache_path, &cache_stat)) >+ exit (1); >+ >+ utime_buf.actime = path_stat.st_atime; >+ utime_buf.modtime = cache_stat.st_mtime; >+ utime (path, &utime_buf); >+ >+ if (!quiet) >+ g_printerr (_("Cache file created successfully.\n")); > } > > void > write_csource (const gchar *path) > { >- gchar *cache_path; >- gchar *data; >- gsize len; >- gint i; >+ gchar *cache_path; >+ gchar *data; >+ gsize len; >+ gint i; >+ >+ cache_path = g_build_filename (path, CACHE_NAME, NULL); >+ if (!g_file_get_contents (cache_path, &data, &len, NULL)) >+ exit (1); >+ >+ g_printf ("#ifdef __SUNPRO_C\n"); >+ g_printf ("#pragma align 4 (%s)\n", var_name); >+ g_printf ("#endif\n"); >+ >+ g_printf ("#ifdef __GNUC__\n"); >+ g_printf ("static const guint8 %s[] __attribute__ ((__aligned__ (4))) = \n", var_name); >+ g_printf ("#else\n"); >+ g_printf ("static const guint8 %s[] = \n", var_name); >+ g_printf ("#endif\n"); > >- cache_path = g_build_filename (path, CACHE_NAME, NULL); >- if (!g_file_get_contents (cache_path, &data, &len, NULL)) >- exit (1); >- >- g_printf ("#ifdef __SUNPRO_C\n"); >- g_printf ("#pragma align 4 (%s)\n", var_name); >- g_printf ("#endif\n"); >- >- g_printf ("#ifdef __GNUC__\n"); >- g_printf ("static const guint8 %s[] __attribute__ ((__aligned__ (4))) = \n", var_name); >- g_printf ("#else\n"); >- g_printf ("static const guint8 %s[] = \n", var_name); >- g_printf ("#endif\n"); >+ g_printf ("{\n"); >+ for (i = 0; i < len - 1; i++) >+ { >+ if (i %12 == 0) >+ g_printf (" "); >+ g_printf ("0x%02x, ", (guint8)data[i]); >+ if (i % 12 == 11) >+ g_printf ("\n"); >+ } > >- g_printf ("{\n"); >- for (i = 0; i < len - 1; i++) >- { >- if (i %12 == 0) >- g_printf (" "); >- g_printf ("0x%02x, ", (guint8)data[i]); >- if (i % 12 == 11) >- g_printf ("\n"); >- } >- >- g_printf ("0x%02x\n};\n", (guint8)data[i]); >+ g_printf ("0x%02x\n};\n", (guint8)data[i]); >+} >+ >+gboolean >+update_cache (const gchar *path) >+{ >+ if (!ignore_theme_index && !has_theme_index (path)) >+ { >+ g_printerr (_("No theme index file in '%s'.\n" >+ "If you really want to create an icon cache here, use --ignore-theme-index.\n"), path); >+ return FALSE; >+ } >+ >+ if (force_update || !is_cache_up_to_date (path)) >+ build_cache (path); >+ >+ return TRUE; >+} >+ >+#define ICONTHEMEDIR "/usr/share/icons" >+ >+static void >+for_all_icon_theme_dirs (void (*func) (const gchar *, gpointer), >+ gpointer data) >+{ >+ GDir *dir; >+ const gchar *name; >+ gchar *path; >+ >+ dir = g_dir_open (ICONTHEMEDIR, 0, NULL); >+ >+ while ((name = g_dir_read_name (dir)) != NULL) >+ { >+ path = g_build_filename (ICONTHEMEDIR, name, NULL); >+ if (has_theme_index (path)) >+ (*func) (path, data); >+ g_free (path); >+ } >+ >+ g_dir_close (dir); >+} >+ >+static void >+update_mtime (const gchar *path, >+ gpointer data) >+{ >+ glong *mtime = data; >+ struct stat statbuf; >+ >+ if (stat (path, &statbuf) == 0) >+ *mtime = MAX (*mtime, statbuf.st_mtime); >+} >+ >+#define PIDFILE "/var/run/gtk-update-icon-cache.pid" >+ >+static void >+write_pidfile (void) >+{ >+ gchar *pid; >+ >+ pid = g_strdup_printf ("%d\n", getpid ()); >+ if (!g_file_set_contents (PIDFILE, pid, -1, NULL)) >+ { >+ g_printerr ("Could not write %s\n", PIDFILE); >+ exit (1); >+ } >+ g_free (pid); >+} >+ >+static void >+delayed_update (gint argc, gchar *argv[]) >+{ >+ glong elapsed; >+ gint i; >+ gboolean daemonized = FALSE; >+ >+ for (i = 1; i < argc; i++) >+ { >+ if (!ignore_theme_index && !has_theme_index (argv[i])) >+ { >+ g_printerr (_("No theme index file in '%s'.\n" >+ "I you really want to create an icon cache here, use --ignore-theme-index.\n"), argv[i]); >+ continue; >+ } >+ utime (argv[i], NULL); >+ } >+ >+ if (g_file_test (PIDFILE, G_FILE_TEST_EXISTS)) >+ { >+ if (!quiet) >+ g_printerr ("Delayed instance already running\n"); >+ exit (0); >+ } >+ >+ elapsed = 0; >+ while (elapsed < delay) >+ { >+ GTimeVal now; >+ glong mtime; >+ >+ g_get_current_time (&now); >+ mtime = now.tv_sec - delay; >+ >+ for_all_icon_theme_dirs (update_mtime, &mtime); >+ >+ elapsed = now.tv_sec - mtime; >+ >+ if (elapsed < delay && !daemonized) >+ { >+ if (!quiet) >+ g_printerr ("Daemonizing for delayed operation\n"); >+ daemon (0, 0); >+ daemonized = TRUE; >+ write_pidfile (); >+ } >+ >+ sleep (delay - elapsed); >+ } >+ if (daemonized) >+ unlink (PIDFILE); >+ >+ for_all_icon_theme_dirs (update_cache, NULL); > } > > static GOptionEntry args[] = { >- { "force", 'f', 0, G_OPTION_ARG_NONE, &force_update, N_("Overwrite an existing cache, even if uptodate"), 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 }, >- { "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 }, >- { NULL } >+ { "force", 'f', 0, G_OPTION_ARG_NONE, &force_update, N_("Overwrite an existing cache, even if uptodate"), 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 }, >+ { "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 }, >+ { "delay", 'd', 0, G_OPTION_ARG_INT, &delay, N_("Delay update for N seconds"), "N" }, >+ { NULL } > }; > > int >-main (int argc, char **argv) >+main (int argc, char *argv[]) > { >- gchar *path; > GOptionContext *context; > > if (argc < 2) >@@ -1299,31 +1422,26 @@ > bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR); > bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); > >+ g_type_init (); >+ > context = g_option_context_new ("ICONPATH"); > g_option_context_add_main_entries (context, args, GETTEXT_PACKAGE); >- > g_option_context_parse (context, &argc, &argv, NULL); >- >- path = argv[1]; >-#ifdef G_OS_WIN32 >- path = g_locale_to_utf8 (path, -1, NULL, NULL, NULL); >-#endif >- >- if (!ignore_theme_index && !has_theme_index (path)) >+ >+ if (delay > 0) > { >- g_printerr (_("No theme index file in '%s'.\n" >- "If you really want to create an icon cache here, use --ignore-theme-index.\n"), path); >- return 1; >+ delayed_update (argc, argv); >+ return 0; > } >- >- if (!force_update && is_cache_up_to_date (path)) >- return 0; >- >- g_type_init (); >- build_cache (path); >+ >+ if (!update_cache (argv[1])) >+ return 1; > > if (strcmp (var_name, "-") != 0) >- write_csource (path); >+ { >+ write_csource (argv[1]); >+ var_name = "-"; >+ } > > return 0; > } >Index: docs/reference/gtk/gtk-update-icon-cache.xml >=================================================================== >RCS file: /cvs/gnome/gtk+/docs/reference/gtk/gtk-update-icon-cache.xml,v >retrieving revision 1.6 >diff -u -r1.6 gtk-update-icon-cache.xml >--- docs/reference/gtk/gtk-update-icon-cache.xml 7 Nov 2005 14:30:35 -0000 1.6 >+++ docs/reference/gtk/gtk-update-icon-cache.xml 23 Dec 2006 06:52:34 -0000 >@@ -18,6 +18,7 @@ > <arg choice="opt">--index-only</arg> > <arg choice="opt">--source<arg>name</arg></arg> > <arg choice="opt">--quiet</arg> >+<arg choice="opt">--delay=N</arg> > <arg choice="req">iconpath</arg> > </cmdsynopsis> > </refsynopsisdiv> >@@ -38,6 +39,12 @@ > Since the format of the cache files allows them to be mmap()ed shared between > multiple applications, the overall memory consumption is reduced as well. > </para> >+<para> >+When using the --delay option, gtk-update-icon-cache waits in the background >+until the icon theme directories have not been changed for a given number of >+seconds before updating their caches. In this mode, it updates the icon caches >+of all icon themes found below <filename>/usr/share/icons</filename>. >+</para> > </refsect1> > > <refsect1><title>Options</title> >@@ -78,6 +85,13 @@ > <term>--quiet</term> > <term>-q</term> > <listitem><para>Turn off verbose output. >+ </para></listitem> >+ </varlistentry> >+ >+ <varlistentry> >+ <term>--delay=N</term> >+ <term>-d N</term> >+ <listitem><para>Delay update for N seconds. > </para></listitem> > </varlistentry> > </variablelist>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 170335
:
144330
|
144436