summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2014-09-24 21:08:37 +0200
committerSebastian Dransfeld <sd@tango.flipp.net>2014-09-24 21:28:32 +0200
commita939cd569c48a3a56c5178c220a101ff7d979754 (patch)
tree641f83f7446e729518e37fac27b7f525578955c0
parent4d2b4a8a65cc1cd1e88d9912e517df726ee15e57 (diff)
efreet: add check for cache version
If version differs between new and old cache, signal change
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/bin/efreet/efreet_desktop_cache_create.c b/src/bin/efreet/efreet_desktop_cache_create.c
index 849d47c6d4..ff0a106437 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -221,6 +221,38 @@ cache_lock_file(void)
221 return lockfd; 221 return lockfd;
222} 222}
223 223
224/* check if old and new caches contain the same number of entries,
225 * and are the same version */
226static int
227check_changed(const char *old_name, Eet_File *new_ef,
228 unsigned char major, unsigned char minor)
229{
230 Eet_File *old_ef;
231 Efreet_Cache_Version *old_version = NULL;
232
233 old_ef = eet_open(old_name, EET_FILE_MODE_READ);
234 if (!old_ef) return 1;
235 if (eet_num_entries(old_ef) != eet_num_entries(new_ef))
236 goto changed;
237
238 old_version = eet_data_read(old_ef, efreet_version_edd(), EFREET_CACHE_VERSION);
239 if (!old_version)
240 goto changed;
241
242 if ((old_version->major != major) ||
243 (old_version->minor != minor))
244 goto changed;
245
246 free(old_version);
247 eet_close(old_ef);
248 return 0;
249
250changed:
251 free(old_version);
252 eet_close(old_ef);
253 return 1;
254}
255
224int 256int
225main(int argc, char **argv) 257main(int argc, char **argv)
226{ 258{
@@ -432,17 +464,19 @@ main(int argc, char **argv)
432 464
433 eina_hash_free(desktops); 465 eina_hash_free(desktops);
434 466
435 /* check if old and new caches contain the same number of entries */ 467 /* check if old and new caches are equal */
436 if (!changed) 468 if (!changed)
437 { 469 {
438 Eet_File *old; 470 if (check_changed(efreet_desktop_cache_file(), ef,
439 471 EFREET_DESKTOP_CACHE_MAJOR, EFREET_DESKTOP_CACHE_MINOR))
440 old = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_READ); 472 changed = 1;
441 if (!old || eet_num_entries(old) != eet_num_entries(ef)) changed = 1; 473 }
442 if (old) eet_close(old); 474 if (!changed)
443 old = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ); 475 {
444 if (!old || eet_num_entries(old) != eet_num_entries(util_ef)) changed = 1; 476 if (check_changed(efreet_desktop_util_cache_file(), util_ef,
445 if (old) eet_close(old); 477 EFREET_DESKTOP_UTILS_CACHE_MAJOR, EFREET_DESKTOP_UTILS_CACHE_MINOR))
478 changed = 1;
479
446 } 480 }
447 481
448 /* cleanup */ 482 /* cleanup */