|
Lines 43-48
static gboolean force_update = FALSE;
|
Link Here
|
|---|
|
static gboolean ignore_theme_index = FALSE; | static gboolean ignore_theme_index = FALSE; |
static gboolean quiet = FALSE; | static gboolean quiet = FALSE; |
static gboolean index_only = FALSE; | static gboolean index_only = FALSE; |
|
static gboolean check_subdirs = FALSE; |
static gchar *var_name = "-"; | static gchar *var_name = "-"; |
| |
#define CACHE_NAME "icon-theme.cache" | #define CACHE_NAME "icon-theme.cache" |
|
Lines 61-68
static gchar *var_name = "-";
|
Link Here
|
|---|
|
#define ALIGN_VALUE(this, boundary) \ | #define ALIGN_VALUE(this, boundary) \ |
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) | (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) |
| |
|
/* returns >0 if dir is newer than time, 0 if dir is older than time, |
|
* <0 if stat fails */ |
|
int |
|
dir_check (const gchar *path, time_t cache_time) |
|
{ |
|
struct stat path_stat; |
|
|
|
if (g_stat (path, &path_stat) < 0) |
|
{ |
|
return -1; |
|
} |
|
return cache_time < path_stat.st_mtime; |
|
} |
|
|
|
/* Check the subdirectories of the cache dir to see if the cache is up-to-date |
|
* We check first and second level subdirs. */ |
|
gboolean |
|
is_cache_up_to_date_subdirs (const gchar *toppath, time_t cache_time) |
|
{ |
|
GDir *topdir, *subdir; |
|
const gchar *name, *subname; |
|
gchar *path, *subpath; |
|
int dir_state; |
|
|
|
topdir = g_dir_open (toppath, 0, NULL); |
|
if (!topdir) |
|
{ |
|
/* we can't open dir, assume updated cache */ |
|
return TRUE; |
|
} |
|
|
|
while ((name = g_dir_read_name (topdir))) |
|
{ |
|
path = g_build_filename (toppath, name, NULL); |
|
dir_state = dir_check (path, cache_time); |
|
if (dir_state < 0) |
|
{ |
|
/* cannot stat dir, for some reason; skip */ |
|
g_free (path); |
|
continue; |
|
} |
|
else if (dir_state > 0) |
|
{ |
|
/* cache is out of date */ |
|
g_free (path); |
|
return FALSE; |
|
} |
|
|
|
subdir = g_dir_open (path, 0, NULL); |
|
if (!subdir) |
|
{ |
|
/* Cannot open subdir; skip */ |
|
g_free (path); |
|
continue; |
|
} |
|
while ((subname = g_dir_read_name (subdir))) |
|
{ |
|
subpath = g_build_filename (path, subname, NULL); |
|
dir_state = dir_check (subpath, cache_time); |
|
g_free (subpath); |
|
|
|
if (dir_state > 0) |
|
{ |
|
/* Cache out of date */ |
|
return FALSE; |
|
} |
|
} |
|
g_free (path); |
|
} |
|
|
|
/* If we get here, the cache is up to date */ |
|
return TRUE; |
|
} |
|
|
gboolean | gboolean |
is_cache_up_to_date (const gchar *path) |
is_cache_up_to_date (const gchar *path, gboolean check_subdirs) |
{ | { |
struct stat path_stat, cache_stat; | struct stat path_stat, cache_stat; |
gchar *cache_path; | gchar *cache_path; |
|
Lines 88-94
is_cache_up_to_date (const gchar *path)
|
Link Here
|
|---|
|
} | } |
| |
/* Check mtime */ | /* Check mtime */ |
return cache_stat.st_mtime >= path_stat.st_mtime; |
if (cache_stat.st_mtime < path_stat.st_mtime) |
|
{ |
|
/* Cache is out of date */ |
|
return FALSE; |
|
} |
|
if (check_subdirs) |
|
{ |
|
return is_cache_up_to_date_subdirs (path, cache_stat.st_mtime); |
|
} |
|
|
|
/* Cache is up to date */ |
|
return TRUE; |
} | } |
| |
gboolean | gboolean |
|
Lines 1284-1289
static GOptionEntry args[] = {
|
Link Here
|
|---|
|
{ "index-only", 'i', 0, G_OPTION_ARG_NONE, &index_only, N_("Don't include image data in the cache"), 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" }, | { "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 }, | { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Turn off verbose output"), NULL }, |
|
{ "check-subdirs", 's', 0, G_OPTION_ARG_NONE, &check_subdirs, N_("Check subdirectories when determining if cache is up-to-date"), NULL }, |
{ NULL } | { NULL } |
}; | }; |
| |
|
Lines 1316-1322
main (int argc, char **argv)
|
Link Here
|
|---|
|
return 1; | return 1; |
} | } |
| |
if (!force_update && is_cache_up_to_date (path)) |
if (!force_update && is_cache_up_to_date (path, check_subdirs)) |
return 0; | return 0; |
| |
g_type_init (); | g_type_init (); |