Lines 43-48
static gboolean force_update = FALSE;
Link Here
|
43 |
static gboolean ignore_theme_index = FALSE; |
43 |
static gboolean ignore_theme_index = FALSE; |
44 |
static gboolean quiet = FALSE; |
44 |
static gboolean quiet = FALSE; |
45 |
static gboolean index_only = FALSE; |
45 |
static gboolean index_only = FALSE; |
|
|
46 |
static gboolean check_subdirs = FALSE; |
46 |
static gchar *var_name = "-"; |
47 |
static gchar *var_name = "-"; |
47 |
|
48 |
|
48 |
#define CACHE_NAME "icon-theme.cache" |
49 |
#define CACHE_NAME "icon-theme.cache" |
Lines 61-68
static gchar *var_name = "-";
Link Here
|
61 |
#define ALIGN_VALUE(this, boundary) \ |
62 |
#define ALIGN_VALUE(this, boundary) \ |
62 |
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) |
63 |
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) |
63 |
|
64 |
|
|
|
65 |
/* returns >0 if dir is newer than time, 0 if dir is older than time, |
66 |
* <0 if stat fails */ |
67 |
int |
68 |
dir_check (const gchar *path, time_t cache_time) |
69 |
{ |
70 |
struct stat path_stat; |
71 |
|
72 |
if (g_stat (path, &path_stat) < 0) |
73 |
{ |
74 |
return -1; |
75 |
} |
76 |
return cache_time < path_stat.st_mtime; |
77 |
} |
78 |
|
79 |
/* Check the subdirectories of the cache dir to see if the cache is up-to-date |
80 |
* We check first and second level subdirs. */ |
81 |
gboolean |
82 |
is_cache_up_to_date_subdirs (const gchar *toppath, time_t cache_time) |
83 |
{ |
84 |
GDir *topdir, *subdir; |
85 |
const gchar *name, *subname; |
86 |
gchar *path, *subpath; |
87 |
int dir_state; |
88 |
|
89 |
topdir = g_dir_open (toppath, 0, NULL); |
90 |
if (!topdir) |
91 |
{ |
92 |
/* we can't open dir, assume updated cache */ |
93 |
return TRUE; |
94 |
} |
95 |
|
96 |
while ((name = g_dir_read_name (topdir))) |
97 |
{ |
98 |
path = g_build_filename (toppath, name, NULL); |
99 |
dir_state = dir_check (path, cache_time); |
100 |
if (dir_state < 0) |
101 |
{ |
102 |
/* cannot stat dir, for some reason; skip */ |
103 |
g_free (path); |
104 |
continue; |
105 |
} |
106 |
else if (dir_state > 0) |
107 |
{ |
108 |
/* cache is out of date */ |
109 |
g_free (path); |
110 |
return FALSE; |
111 |
} |
112 |
|
113 |
subdir = g_dir_open (path, 0, NULL); |
114 |
if (!subdir) |
115 |
{ |
116 |
/* Cannot open subdir; skip */ |
117 |
g_free (path); |
118 |
continue; |
119 |
} |
120 |
while ((subname = g_dir_read_name (subdir))) |
121 |
{ |
122 |
subpath = g_build_filename (path, subname, NULL); |
123 |
dir_state = dir_check (subpath, cache_time); |
124 |
g_free (subpath); |
125 |
|
126 |
if (dir_state > 0) |
127 |
{ |
128 |
/* Cache out of date */ |
129 |
return FALSE; |
130 |
} |
131 |
} |
132 |
g_free (path); |
133 |
} |
134 |
|
135 |
/* If we get here, the cache is up to date */ |
136 |
return TRUE; |
137 |
} |
138 |
|
64 |
gboolean |
139 |
gboolean |
65 |
is_cache_up_to_date (const gchar *path) |
140 |
is_cache_up_to_date (const gchar *path, gboolean check_subdirs) |
66 |
{ |
141 |
{ |
67 |
struct stat path_stat, cache_stat; |
142 |
struct stat path_stat, cache_stat; |
68 |
gchar *cache_path; |
143 |
gchar *cache_path; |
Lines 88-94
is_cache_up_to_date (const gchar *path)
Link Here
|
88 |
} |
163 |
} |
89 |
|
164 |
|
90 |
/* Check mtime */ |
165 |
/* Check mtime */ |
91 |
return cache_stat.st_mtime >= path_stat.st_mtime; |
166 |
if (cache_stat.st_mtime < path_stat.st_mtime) |
|
|
167 |
{ |
168 |
/* Cache is out of date */ |
169 |
return FALSE; |
170 |
} |
171 |
if (check_subdirs) |
172 |
{ |
173 |
return is_cache_up_to_date_subdirs (path, cache_stat.st_mtime); |
174 |
} |
175 |
|
176 |
/* Cache is up to date */ |
177 |
return TRUE; |
92 |
} |
178 |
} |
93 |
|
179 |
|
94 |
gboolean |
180 |
gboolean |
Lines 1284-1289
static GOptionEntry args[] = {
Link Here
|
1284 |
{ "index-only", 'i', 0, G_OPTION_ARG_NONE, &index_only, N_("Don't include image data in the cache"), NULL }, |
1370 |
{ "index-only", 'i', 0, G_OPTION_ARG_NONE, &index_only, N_("Don't include image data in the cache"), NULL }, |
1285 |
{ "source", 'c', 0, G_OPTION_ARG_STRING, &var_name, N_("Output a C header file"), "NAME" }, |
1371 |
{ "source", 'c', 0, G_OPTION_ARG_STRING, &var_name, N_("Output a C header file"), "NAME" }, |
1286 |
{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Turn off verbose output"), NULL }, |
1372 |
{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Turn off verbose output"), NULL }, |
|
|
1373 |
{ "check-subdirs", 's', 0, G_OPTION_ARG_NONE, &check_subdirs, N_("Check subdirectories when determining if cache is up-to-date"), NULL }, |
1287 |
{ NULL } |
1374 |
{ NULL } |
1288 |
}; |
1375 |
}; |
1289 |
|
1376 |
|
Lines 1316-1322
main (int argc, char **argv)
Link Here
|
1316 |
return 1; |
1403 |
return 1; |
1317 |
} |
1404 |
} |
1318 |
|
1405 |
|
1319 |
if (!force_update && is_cache_up_to_date (path)) |
1406 |
if (!force_update && is_cache_up_to_date (path, check_subdirs)) |
1320 |
return 0; |
1407 |
return 0; |
1321 |
|
1408 |
|
1322 |
g_type_init (); |
1409 |
g_type_init (); |