Add an icon cache validator.
2007-05-01 Matthias Clasen <mclasen@redhat.com> * gtk/gtkiconcachvalidator.[hc]: Add an icon cache validator. * gtk/updateiconcache.c: Validate the generated cache before moving it in place. Also add a --validate option to validate an existing icon cache. * gtk/gtkiconcache.c: Validate icon caches before using them. * gtk/Makefile.am: Integrate it. svn path=/trunk/; revision=17753
This commit is contained in:
committed by
Matthias Clasen
parent
6bade15e60
commit
2a80113304
@ -21,6 +21,7 @@
|
||||
|
||||
#include "gtkdebug.h"
|
||||
#include "gtkiconcache.h"
|
||||
#include "gtkiconcachevalidator.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
@ -58,7 +59,7 @@ struct _GtkIconCache {
|
||||
GtkIconCache *
|
||||
_gtk_icon_cache_ref (GtkIconCache *cache)
|
||||
{
|
||||
cache->ref_count ++;
|
||||
cache->ref_count++;
|
||||
return cache;
|
||||
}
|
||||
|
||||
@ -89,6 +90,7 @@ _gtk_icon_cache_new_for_path (const gchar *path)
|
||||
struct stat st;
|
||||
struct stat path_st;
|
||||
gchar *buffer = NULL;
|
||||
CacheInfo info;
|
||||
|
||||
/* Check if we have a cache file */
|
||||
cache_filename = g_build_filename (path, "icon-theme.cache", NULL);
|
||||
@ -121,25 +123,26 @@ _gtk_icon_cache_new_for_path (const gchar *path)
|
||||
if (!map)
|
||||
goto done;
|
||||
|
||||
/* Verify version */
|
||||
buffer = g_mapped_file_get_contents (map);
|
||||
if (GET_UINT16 (buffer, 0) != MAJOR_VERSION ||
|
||||
GET_UINT16 (buffer, 2) != MINOR_VERSION)
|
||||
info.cache = g_mapped_file_get_contents (map);
|
||||
info.cache_size = g_mapped_file_get_length (map);
|
||||
info.n_directories = 0;
|
||||
info.flags = CHECK_OFFSETS|CHECK_STRINGS;
|
||||
|
||||
g_print ("validating %s\n", cache_filename);
|
||||
if (!_gtk_icon_cache_validate (&info))
|
||||
{
|
||||
g_mapped_file_free (map);
|
||||
|
||||
GTK_NOTE (ICONTHEME,
|
||||
g_print ("wrong cache version\n"));
|
||||
GTK_NOTE (ICONTHEME, g_print ("invalid icon cache\n"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
GTK_NOTE (ICONTHEME,
|
||||
g_print ("found cache for %s\n", path));
|
||||
GTK_NOTE (ICONTHEME, g_print ("found cache for %s\n", path));
|
||||
|
||||
cache = g_new0 (GtkIconCache, 1);
|
||||
cache->ref_count = 1;
|
||||
cache->map = map;
|
||||
cache->buffer = buffer;
|
||||
cache->buffer = g_mapped_file_get_contents (map);
|
||||
|
||||
done:
|
||||
g_free (cache_filename);
|
||||
@ -440,7 +443,7 @@ _gtk_icon_cache_get_icon (GtkIconCache *cache,
|
||||
length = GET_UINT32 (cache->buffer, pixel_data_offset + 4);
|
||||
|
||||
if (!gdk_pixdata_deserialize (&pixdata, length,
|
||||
cache->buffer + pixel_data_offset + 8,
|
||||
(guchar *)(cache->buffer + pixel_data_offset + 8),
|
||||
&error))
|
||||
{
|
||||
GTK_NOTE (ICONTHEME,
|
||||
|
||||
Reference in New Issue
Block a user