efreet: Only update cache files if changed

SVN revision: 47546
This commit is contained in:
Sebastian Dransfeld 2010-03-28 20:46:27 +00:00
parent 13b51829ae
commit 6d0651d4f2
1 changed files with 30 additions and 23 deletions

View File

@ -33,7 +33,7 @@ strcmplen(const void *data1, const void *data2)
} }
static int static int
cache_add(const char *path, const char *file_id, int priority __UNUSED__) cache_add(const char *path, const char *file_id, int priority __UNUSED__, int *changed)
{ {
Efreet_Desktop *desk; Efreet_Desktop *desk;
char *ext; char *ext;
@ -42,20 +42,20 @@ cache_add(const char *path, const char *file_id, int priority __UNUSED__)
ext = strrchr(path, '.'); ext = strrchr(path, '.');
if (!ext || (strcmp(ext, ".desktop") && strcmp(ext, ".directory"))) return 1; if (!ext || (strcmp(ext, ".desktop") && strcmp(ext, ".directory"))) return 1;
desk = efreet_desktop_get(path); desk = efreet_desktop_get(path);
if (!desk) return 1;
mtime = ecore_file_mod_time(path);
if (mtime != desk->load_time)
{
efreet_desktop_free(desk);
desk = efreet_desktop_uncached_new(path);
}
if (!desk || (desk->type != EFREET_DESKTOP_TYPE_APPLICATION && if (!desk || (desk->type != EFREET_DESKTOP_TYPE_APPLICATION &&
desk->type != EFREET_DESKTOP_TYPE_DIRECTORY)) desk->type != EFREET_DESKTOP_TYPE_DIRECTORY))
{ {
if (desk) efreet_desktop_free(desk); if (desk) efreet_desktop_free(desk);
return 1; return 1;
} }
mtime = ecore_file_mod_time(path);
if (mtime != desk->load_time)
{
efreet_desktop_free(desk);
*changed = 1;
desk = efreet_desktop_uncached_new(path);
}
if (!desk) return 1;
if (!eina_hash_find(paths, desk->orig_path)) if (!eina_hash_find(paths, desk->orig_path))
{ {
if (!eet_data_write(ef, edd, desk->orig_path, desk, 0)) if (!eet_data_write(ef, edd, desk->orig_path, desk, 0))
@ -132,7 +132,7 @@ cache_add(const char *path, const char *file_id, int priority __UNUSED__)
static int static int
cache_scan(const char *path, const char *base_id, int priority, int recurse) cache_scan(const char *path, const char *base_id, int priority, int recurse, int *changed)
{ {
char *file_id = NULL; char *file_id = NULL;
char id[PATH_MAX]; char id[PATH_MAX];
@ -162,11 +162,11 @@ cache_scan(const char *path, const char *base_id, int priority, int recurse)
if (ecore_file_is_dir(buf)) if (ecore_file_is_dir(buf))
{ {
if (recurse) if (recurse)
cache_scan(buf, file_id, priority, recurse); cache_scan(buf, file_id, priority, recurse, changed);
} }
else else
{ {
if (!cache_add(buf, file_id, priority)) return 0; if (!cache_add(buf, file_id, priority, changed)) return 0;
} }
} }
closedir(files); closedir(files);
@ -179,8 +179,6 @@ main()
/* TODO: /* TODO:
* - Add file monitor on files, so that we catch changes on files * - Add file monitor on files, so that we catch changes on files
* during whilst this program runs. * during whilst this program runs.
* - Use return value to signal calling process wheter cache was
* updated or not.
*/ */
char file[PATH_MAX]; char file[PATH_MAX];
char util_file[PATH_MAX]; char util_file[PATH_MAX];
@ -190,6 +188,7 @@ main()
char *map = MAP_FAILED; char *map = MAP_FAILED;
int fd = -1, tmpfd, dirsfd = -1; int fd = -1, tmpfd, dirsfd = -1;
struct stat st; struct stat st;
int changed = 0;
/* init external subsystems */ /* init external subsystems */
if (!eina_init()) goto eina_error; if (!eina_init()) goto eina_error;
@ -275,7 +274,7 @@ main()
path = eina_list_data_get(dirs); path = eina_list_data_get(dirs);
if (path) if (path)
{ {
if (!cache_scan(path, file_id, priority++, 1)) goto error; if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error;
l = eina_list_search_unsorted_list(user_dirs, strcmplen, path); l = eina_list_search_unsorted_list(user_dirs, strcmplen, path);
if (l) if (l)
{ {
@ -294,7 +293,7 @@ main()
write(dirsfd, &size, sizeof(int)); write(dirsfd, &size, sizeof(int));
write(dirsfd, dir, size); write(dirsfd, dir, size);
} }
if (!cache_scan(dir, NULL, priority, 0)) goto error; if (!cache_scan(dir, NULL, priority, 0, &changed)) goto error;
free(dir); free(dir);
} }
eina_hash_free(file_ids); eina_hash_free(file_ids);
@ -305,17 +304,25 @@ main()
eet_close(ef); eet_close(ef);
/* unlink old cache files */ /* unlink old cache files */
if (unlink(efreet_desktop_cache_file()) < 0) if (changed)
{ {
if (errno != ENOENT) goto error; if (unlink(efreet_desktop_cache_file()) < 0)
{
if (errno != ENOENT) goto error;
}
if (unlink(efreet_desktop_util_cache_file()) < 0)
{
if (errno != ENOENT) goto error;
}
/* rename tmp files to real files */
if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error;
if (rename(file, efreet_desktop_cache_file()) < 0) goto error;
} }
if (unlink(efreet_desktop_util_cache_file()) < 0) else
{ {
if (errno != ENOENT) goto error; unlink(util_file);
unlink(file);
} }
/* rename tmp files to real files */
if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error;
if (rename(file, efreet_desktop_cache_file()) < 0) goto error;
efreet_desktop_edd_shutdown(edd); efreet_desktop_edd_shutdown(edd);
efreet_shutdown(); efreet_shutdown();