summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--legacy/efreet/ChangeLog1
-rw-r--r--legacy/efreet/src/bin/efreet_desktop_cache_create.c135
-rw-r--r--legacy/efreet/src/lib/efreet_cache.c90
-rw-r--r--legacy/efreet/src/lib/efreet_cache_private.h1
-rw-r--r--legacy/efreet/src/lib/efreet_desktop.c136
-rw-r--r--legacy/efreet/src/lib/efreet_private.h6
6 files changed, 166 insertions, 203 deletions
diff --git a/legacy/efreet/ChangeLog b/legacy/efreet/ChangeLog
index 63e7d58a49..218652045f 100644
--- a/legacy/efreet/ChangeLog
+++ b/legacy/efreet/ChangeLog
@@ -73,3 +73,4 @@
73 * Free hashes on init error 73 * Free hashes on init error
74 * efreet_cache_icon -> efreet_icon for functions in efreet_icon.c 74 * efreet_cache_icon -> efreet_icon for functions in efreet_icon.c
75 * Fix memleak in desktop cache create 75 * Fix memleak in desktop cache create
76 * Pass dirs to desktop cache process as arguments
diff --git a/legacy/efreet/src/bin/efreet_desktop_cache_create.c b/legacy/efreet/src/bin/efreet_desktop_cache_create.c
index 2b5df70f06..83a275c575 100644
--- a/legacy/efreet/src/bin/efreet_desktop_cache_create.c
+++ b/legacy/efreet/src/bin/efreet_desktop_cache_create.c
@@ -44,7 +44,7 @@ static int verbose = 0;
44static int 44static int
45strcmplen(const void *data1, const void *data2) 45strcmplen(const void *data1, const void *data2)
46{ 46{
47 return strncmp(data1, data2, eina_stringshare_strlen(data2)); 47 return strncmp(data1, data2, eina_stringshare_strlen(data1));
48} 48}
49 49
50static int 50static int
@@ -223,17 +223,21 @@ main(int argc, char **argv)
223 */ 223 */
224 Efreet_Cache_Hash hash; 224 Efreet_Cache_Hash hash;
225 Efreet_Cache_Version version; 225 Efreet_Cache_Version version;
226 Eina_List *dirs = NULL, *user_dirs = NULL; 226 Eina_List *dirs = NULL;
227 Eina_List *scanned = NULL;
228 Efreet_Cache_Array_String *user_dirs = NULL;
229 Eina_List *extra_dirs = NULL;
230 Eina_List *store_dirs = NULL;
227 int priority = 0; 231 int priority = 0;
228 char *dir = NULL; 232 char *dir = NULL;
229 char *path; 233 char *path;
230 int lockfd = -1, tmpfd, dirsfd = -1; 234 int lockfd = -1, tmpfd;
231 struct stat st;
232 int changed = 0; 235 int changed = 0;
233 int i; 236 int i;
234 char file[PATH_MAX] = { '\0' }; 237 char file[PATH_MAX] = { '\0' };
235 char util_file[PATH_MAX] = { '\0' }; 238 char util_file[PATH_MAX] = { '\0' };
236 239
240 if (!eina_init()) goto eina_error;
237 241
238 for (i = 1; i < argc; i++) 242 for (i = 1; i < argc; i++)
239 { 243 {
@@ -244,12 +248,19 @@ main(int argc, char **argv)
244 (!strcmp(argv[i], "--help"))) 248 (!strcmp(argv[i], "--help")))
245 { 249 {
246 printf("Options:\n"); 250 printf("Options:\n");
247 printf(" -v Verbose mode\n"); 251 printf(" -v Verbose mode\n");
252 printf(" -d dir1 dir2 Extra dirs\n");
248 exit(0); 253 exit(0);
249 } 254 }
255 else if (!strcmp(argv[i], "-d"))
256 {
257 while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
258 extra_dirs = eina_list_append(extra_dirs, argv[++i]);
259 }
250 } 260 }
261 extra_dirs = eina_list_sort(extra_dirs, -1, EINA_COMPARE_CB(strcmp));
262
251 /* init external subsystems */ 263 /* init external subsystems */
252 if (!eina_init()) goto eina_error;
253 if (!eet_init()) goto eet_error; 264 if (!eet_init()) goto eet_error;
254 if (!ecore_init()) goto ecore_error; 265 if (!ecore_init()) goto ecore_error;
255 266
@@ -272,6 +283,14 @@ main(int argc, char **argv)
272 edd = efreet_desktop_edd(); 283 edd = efreet_desktop_edd();
273 if (!edd) goto edd_error; 284 if (!edd) goto edd_error;
274 285
286 /* read user dirs from old cache */
287 ef = eet_open(efreet_desktop_cache_file(), EET_FILE_MODE_READ);
288 if (ef)
289 {
290 user_dirs = eet_data_read(ef, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS);
291 eet_close(ef);
292 }
293
275 /* create cache */ 294 /* create cache */
276 snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file()); 295 snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
277 tmpfd = mkstemp(file); 296 tmpfd = mkstemp(file);
@@ -312,66 +331,74 @@ main(int argc, char **argv)
312 "applications"); 331 "applications");
313 if (!dirs) goto error; 332 if (!dirs) goto error;
314 333
315 dirsfd = open(efreet_desktop_cache_dirs(), O_APPEND | O_RDWR, S_IRUSR | S_IWUSR); 334 EINA_LIST_FREE(dirs, path)
316 if (dirsfd >= 0) 335 {
336 char file_id[PATH_MAX] = { '\0' };
337
338 if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error;
339 scanned = eina_list_append(scanned, path);
340 }
341
342 if (user_dirs)
317 { 343 {
318 if ((fstat(dirsfd, &st) == 0) && (st.st_size > 0)) 344 unsigned int j;
345
346 for (j = 0; j < user_dirs->array_count; j++)
319 { 347 {
320 char *p; 348 Eina_List *l;
321 char *map;
322 349
323 map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, dirsfd, 0); 350 l = eina_list_search_unsorted_list(scanned, strcmplen, user_dirs->array[j]);
324 if (map == MAP_FAILED) goto error; 351 if (l) continue;
325 p = map; 352 if (!ecore_file_is_dir(user_dirs->array[j])) continue;
326 while (p < map + st.st_size) 353 if (!cache_scan(user_dirs->array[j], NULL, priority, 0, &changed)) goto error;
327 { 354 scanned = eina_list_append(scanned, eina_stringshare_add(user_dirs->array[j]));
328 unsigned int size = *(unsigned int *)p; 355
329 p += sizeof(unsigned int); 356 store_dirs = eina_list_append(store_dirs, user_dirs->array[j]);
330 user_dirs = eina_list_append(user_dirs, eina_stringshare_add(p));
331 p += size;
332 }
333 munmap(map, st.st_size);
334 } 357 }
335 close(dirsfd); 358 store_dirs = eina_list_sort(store_dirs, -1, EINA_COMPARE_CB(strcmp));
336 dirsfd = -1;
337 unlink(efreet_desktop_cache_dirs());
338 } 359 }
339 360
340 EINA_LIST_FREE(dirs, path) 361 if (extra_dirs)
341 { 362 {
342 char file_id[PATH_MAX] = { '\0' };
343 Eina_List *l; 363 Eina_List *l;
344 364
345 if (!cache_scan(path, file_id, priority++, 1, &changed)) goto error; 365 EINA_LIST_FOREACH(extra_dirs, l, path)
346 l = eina_list_search_unsorted_list(user_dirs, strcmplen, path);
347 if (l)
348 { 366 {
349 eina_stringshare_del(eina_list_data_get(l)); 367 Eina_List *ll;
350 user_dirs = eina_list_remove_list(user_dirs, l); 368
369 ll = eina_list_search_unsorted_list(scanned, strcmplen, path);
370 if (ll) continue;
371 if (!ecore_file_is_dir(path)) continue;
372
373 /* If we scan a passed dir, we must have changed */
374 changed = 1;
375 if (!cache_scan(path, NULL, priority, 0, &changed)) goto error;
376
377 store_dirs = eina_list_append(store_dirs, path);
351 } 378 }
352 eina_stringshare_del(path); 379 store_dirs = eina_list_sort(store_dirs, -1, EINA_COMPARE_CB(strcmp));
353 } 380 }
381
354 if (user_dirs) 382 if (user_dirs)
355 { 383 {
356 dirsfd = open(efreet_desktop_cache_dirs(), O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR); 384 IF_FREE(user_dirs->array);
357 if (dirsfd < 0) goto error; 385 free(user_dirs);
358 efreet_fsetowner(dirsfd); 386 }
359 EINA_LIST_FREE(user_dirs, dir)
360 {
361 unsigned int size = strlen(dir) + 1;
362 size_t count;
363 387
364 count = write(dirsfd, &size, sizeof(int)); 388 /* store user dirs */
365 count += write(dirsfd, dir, size); 389 if (store_dirs)
390 {
391 Eina_List *l;
366 392
367 if (count != sizeof (int) + size) 393 user_dirs = NEW(Efreet_Cache_Array_String, 1);
368 printf("Didn't write all data on dirsfd"); 394 user_dirs->array = NEW(char *, eina_list_count(store_dirs));
395 user_dirs->array_count = 0;
396 EINA_LIST_FOREACH(store_dirs, l, path)
397 user_dirs->array[user_dirs->array_count++] = path;
369 398
370 if (!cache_scan(dir, NULL, priority, 0, &changed)) goto error; 399 eet_data_write(ef, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS, user_dirs, 1);
371 eina_stringshare_del(dir); 400 IF_FREE(user_dirs->array);
372 } 401 free(user_dirs);
373 close(dirsfd);
374 dirsfd = -1;
375 } 402 }
376 403
377 /* store util */ 404 /* store util */
@@ -473,6 +500,10 @@ main(int argc, char **argv)
473 if (write(tmpfd, "a", 1) != 1) perror("write"); 500 if (write(tmpfd, "a", 1) != 1) perror("write");
474 close(tmpfd); 501 close(tmpfd);
475 } 502 }
503 EINA_LIST_FREE(scanned, dir)
504 eina_stringshare_del(dir);
505 eina_list_free(extra_dirs);
506 eina_list_free(store_dirs);
476 efreet_shutdown(); 507 efreet_shutdown();
477 ecore_shutdown(); 508 ecore_shutdown();
478 eet_shutdown(); 509 eet_shutdown();
@@ -480,15 +511,19 @@ main(int argc, char **argv)
480 close(lockfd); 511 close(lockfd);
481 return 0; 512 return 0;
482error: 513error:
483 if (dirsfd >= 0) close(dirsfd);
484 IF_FREE(dir); 514 IF_FREE(dir);
485edd_error: 515edd_error:
516 if (user_dirs) efreet_cache_array_string_free(user_dirs);
486 efreet_shutdown(); 517 efreet_shutdown();
487efreet_error: 518efreet_error:
488 ecore_shutdown(); 519 ecore_shutdown();
489ecore_error: 520ecore_error:
490 eet_shutdown(); 521 eet_shutdown();
491eet_error: 522eet_error:
523 EINA_LIST_FREE(scanned, dir)
524 eina_stringshare_del(dir);
525 eina_list_free(extra_dirs);
526 eina_list_free(store_dirs);
492 eina_shutdown(); 527 eina_shutdown();
493eina_error: 528eina_error:
494 if (lockfd >= 0) close(lockfd); 529 if (lockfd >= 0) close(lockfd);
diff --git a/legacy/efreet/src/lib/efreet_cache.c b/legacy/efreet/src/lib/efreet_cache.c
index 006241a3a4..d8a63e9783 100644
--- a/legacy/efreet/src/lib/efreet_cache.c
+++ b/legacy/efreet/src/lib/efreet_cache.c
@@ -7,6 +7,7 @@
7 * browsing. 7 * browsing.
8 */ 8 */
9 9
10#include <libgen.h>
10#include <unistd.h> 11#include <unistd.h>
11#include <fcntl.h> 12#include <fcntl.h>
12#include <sys/stat.h> 13#include <sys/stat.h>
@@ -61,8 +62,8 @@ static Eet_Data_Descriptor *hash_array_string_edd = NULL;
61static Eet_Data_Descriptor *array_string_edd = NULL; 62static Eet_Data_Descriptor *array_string_edd = NULL;
62static Eet_Data_Descriptor *hash_string_edd = NULL; 63static Eet_Data_Descriptor *hash_string_edd = NULL;
63 64
65static Efreet_Cache_Array_String *desktop_dirs = NULL;
64static Eet_File *desktop_cache = NULL; 66static Eet_File *desktop_cache = NULL;
65static const char *desktop_cache_dirs = NULL;
66static const char *desktop_cache_file = NULL; 67static const char *desktop_cache_file = NULL;
67 68
68static Ecore_File_Monitor *cache_monitor = NULL; 69static Ecore_File_Monitor *cache_monitor = NULL;
@@ -175,9 +176,10 @@ efreet_cache_shutdown(void)
175 IF_FREE_HASH(icons); 176 IF_FREE_HASH(icons);
176 IF_FREE_HASH(fallbacks); 177 IF_FREE_HASH(fallbacks);
177 178
179 efreet_cache_array_string_free(desktop_dirs);
180 desktop_dirs = NULL;
178 desktop_cache = efreet_cache_close(desktop_cache); 181 desktop_cache = efreet_cache_close(desktop_cache);
179 IF_RELEASE(desktop_cache_file); 182 IF_RELEASE(desktop_cache_file);
180 IF_RELEASE(desktop_cache_dirs);
181 183
182 if (cache_exe_handler) ecore_event_handler_del(cache_exe_handler); 184 if (cache_exe_handler) ecore_event_handler_del(cache_exe_handler);
183 cache_exe_handler = NULL; 185 cache_exe_handler = NULL;
@@ -401,22 +403,6 @@ efreet_desktop_cache_file(void)
401 return desktop_cache_file; 403 return desktop_cache_file;
402} 404}
403 405
404/*
405 * Needs EAPI because of helper binaries
406 */
407EAPI const char *
408efreet_desktop_cache_dirs(void)
409{
410 char tmp[PATH_MAX] = { '\0' };
411
412 if (desktop_cache_dirs) return desktop_cache_dirs;
413
414 snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_dirs.cache", efreet_cache_home_get());
415
416 desktop_cache_dirs = eina_stringshare_add(tmp);
417 return desktop_cache_dirs;
418}
419
420#define EDD_SHUTDOWN(Edd) \ 406#define EDD_SHUTDOWN(Edd) \
421 if (Edd) eet_data_descriptor_free(Edd); \ 407 if (Edd) eet_data_descriptor_free(Edd); \
422Edd = NULL; 408Edd = NULL;
@@ -826,6 +812,55 @@ efreet_cache_desktop_free(Efreet_Desktop *desktop)
826} 812}
827 813
828void 814void
815efreet_cache_desktop_add(Efreet_Desktop *desktop)
816{
817 char buf[PATH_MAX];
818 char *p;
819 Efreet_Cache_Array_String *arr;
820 const char **tmp;
821
822 /*
823 * Read file from disk, save path in cache so it will be included in next
824 * cache update
825 */
826 strncpy(buf, desktop->orig_path, PATH_MAX);
827 buf[PATH_MAX - 1] = '\0';
828 p = dirname(buf);
829 arr = efreet_cache_desktop_dirs();
830 if (arr)
831 {
832 unsigned int i;
833
834 for (i = 0; i < arr->array_count; i++)
835 {
836 /* Check if we already have this dir in cache */
837 if (!strcmp(p, arr->array[i]))
838 return;
839 }
840 }
841 /* TODO: We leak this data, remember and clean up on shutdown */
842 if (!arr)
843 desktop_dirs = arr = NEW(Efreet_Cache_Array_String, 1);
844 tmp = realloc(arr->array, sizeof (char *) * (arr->array_count + 1));
845 if (!tmp) return;
846 arr->array = tmp;
847 arr->array[arr->array_count++] = strdup(p);
848
849 efreet_cache_desktop_update();
850}
851
852Efreet_Cache_Array_String *
853efreet_cache_desktop_dirs(void)
854{
855 if (desktop_dirs) return desktop_dirs;
856
857 if (!efreet_cache_check(&desktop_cache, efreet_desktop_cache_file(), EFREET_DESKTOP_CACHE_MAJOR)) return NULL;
858
859 desktop_dirs = eet_data_read(desktop_cache, efreet_array_string_edd(), EFREET_CACHE_DESKTOP_DIRS);
860 return desktop_dirs;
861}
862
863void
829efreet_cache_desktop_update(void) 864efreet_cache_desktop_update(void)
830{ 865{
831 if (!efreet_cache_update) return; 866 if (!efreet_cache_update) return;
@@ -991,6 +1026,8 @@ cache_update_cb(void *data __UNUSED__, Ecore_File_Monitor *em __UNUSED__,
991 d->ef = desktop_cache; 1026 d->ef = desktop_cache;
992 old_desktop_caches = eina_list_append(old_desktop_caches, d); 1027 old_desktop_caches = eina_list_append(old_desktop_caches, d);
993 1028
1029 efreet_cache_array_string_free(desktop_dirs);
1030 desktop_dirs = NULL;
994 efreet_desktop_cache = eina_hash_string_superfast_new(NULL); 1031 efreet_desktop_cache = eina_hash_string_superfast_new(NULL);
995 desktop_cache = NULL; 1032 desktop_cache = NULL;
996 1033
@@ -1066,8 +1103,6 @@ desktop_cache_update_cache_job(void *data __UNUSED__)
1066 /* TODO: Retry update cache later */ 1103 /* TODO: Retry update cache later */
1067 if (desktop_cache_exe_lock > 0) return; 1104 if (desktop_cache_exe_lock > 0) return;
1068 1105
1069 if (!efreet_desktop_write_cache_dirs_file()) return;
1070
1071 snprintf(file, sizeof(file), "%s/efreet/desktop_exec.lock", efreet_cache_home_get()); 1106 snprintf(file, sizeof(file), "%s/efreet/desktop_exec.lock", efreet_cache_home_get());
1072 1107
1073 desktop_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); 1108 desktop_cache_exe_lock = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
@@ -1079,7 +1114,20 @@ desktop_cache_update_cache_job(void *data __UNUSED__)
1079 if (fcntl(desktop_cache_exe_lock, F_SETLK, &fl) < 0) goto error; 1114 if (fcntl(desktop_cache_exe_lock, F_SETLK, &fl) < 0) goto error;
1080 prio = ecore_exe_run_priority_get(); 1115 prio = ecore_exe_run_priority_get();
1081 ecore_exe_run_priority_set(19); 1116 ecore_exe_run_priority_set(19);
1082 desktop_cache_exe = ecore_exe_run(PACKAGE_LIB_DIR "/efreet/efreet_desktop_cache_create", NULL); 1117 eina_strlcpy(file, PACKAGE_LIB_DIR "/efreet/efreet_desktop_cache_create", sizeof(file));
1118 if (desktop_dirs && desktop_dirs->array_count > 0)
1119 {
1120 unsigned int i;
1121
1122 eina_strlcat(file, " -d", sizeof(file));
1123 for (i = 0; i < desktop_dirs->array_count; i++)
1124 {
1125 eina_strlcat(file, " ", sizeof(file));
1126 eina_strlcat(file, desktop_dirs->array[i], sizeof(file));
1127 }
1128 }
1129 printf("Run desktop cache creation: %s\n", file);
1130 desktop_cache_exe = ecore_exe_run(file, NULL);
1083 ecore_exe_run_priority_set(prio); 1131 ecore_exe_run_priority_set(prio);
1084 if (!desktop_cache_exe) goto error; 1132 if (!desktop_cache_exe) goto error;
1085 1133
diff --git a/legacy/efreet/src/lib/efreet_cache_private.h b/legacy/efreet/src/lib/efreet_cache_private.h
index 72711f3f9f..811d29da87 100644
--- a/legacy/efreet/src/lib/efreet_cache_private.h
+++ b/legacy/efreet/src/lib/efreet_cache_private.h
@@ -11,6 +11,7 @@
11 11
12#define EFREET_CACHE_VERSION "__efreet//version" 12#define EFREET_CACHE_VERSION "__efreet//version"
13#define EFREET_CACHE_ICON_FALLBACK "__efreet_fallback" 13#define EFREET_CACHE_ICON_FALLBACK "__efreet_fallback"
14#define EFREET_CACHE_DESKTOP_DIRS "__efreet//desktop_dirs"
14 15
15EAPI const char *efreet_desktop_util_cache_file(void); 16EAPI const char *efreet_desktop_util_cache_file(void);
16EAPI const char *efreet_desktop_cache_file(void); 17EAPI const char *efreet_desktop_cache_file(void);
diff --git a/legacy/efreet/src/lib/efreet_desktop.c b/legacy/efreet/src/lib/efreet_desktop.c
index a0ae66dede..a21b0c0762 100644
--- a/legacy/efreet/src/lib/efreet_desktop.c
+++ b/legacy/efreet/src/lib/efreet_desktop.c
@@ -20,7 +20,6 @@ extern "C"
20void *alloca (size_t); 20void *alloca (size_t);
21#endif 21#endif
22 22
23#include <libgen.h>
24#include <unistd.h> 23#include <unistd.h>
25#include <sys/stat.h> 24#include <sys/stat.h>
26#include <sys/mman.h> 25#include <sys/mman.h>
@@ -53,11 +52,6 @@ Eina_Hash *efreet_desktop_cache = NULL;
53static const char *desktop_environment = NULL; 52static const char *desktop_environment = NULL;
54 53
55/** 54/**
56 * A cache of all unknown desktop dirs
57 */
58static Eina_List *efreet_desktop_dirs = NULL;
59
60/**
61 * A list of the desktop types available 55 * A list of the desktop types available
62 */ 56 */
63static Eina_List *efreet_desktop_types = NULL; 57static Eina_List *efreet_desktop_types = NULL;
@@ -164,14 +158,11 @@ void
164efreet_desktop_shutdown(void) 158efreet_desktop_shutdown(void)
165{ 159{
166 Efreet_Desktop_Type_Info *info; 160 Efreet_Desktop_Type_Info *info;
167 char *dir;
168 161
169 IF_RELEASE(desktop_environment); 162 IF_RELEASE(desktop_environment);
170 IF_FREE_HASH(efreet_desktop_cache); 163 IF_FREE_HASH(efreet_desktop_cache);
171 EINA_LIST_FREE(efreet_desktop_types, info) 164 EINA_LIST_FREE(efreet_desktop_types, info)
172 efreet_desktop_type_info_free(info); 165 efreet_desktop_type_info_free(info);
173 EINA_LIST_FREE(efreet_desktop_dirs, dir)
174 eina_stringshare_del(dir);
175 IF_FREE_HASH(change_monitors); 166 IF_FREE_HASH(change_monitors);
176#ifdef HAVE_EVIL 167#ifdef HAVE_EVIL
177 evil_sockets_shutdown(); 168 evil_sockets_shutdown();
@@ -223,21 +214,7 @@ efreet_desktop_get(const char *file)
223 if (!desktop) return NULL; 214 if (!desktop) return NULL;
224 215
225 if (!desktop->eet) 216 if (!desktop->eet)
226 { 217 efreet_cache_desktop_add(desktop);
227 char buf[PATH_MAX];
228 char *p;
229
230 /*
231 * Read file from disk, save path in cache so it will be included in next
232 * cache update
233 */
234 strncpy(buf, desktop->orig_path, PATH_MAX);
235 buf[PATH_MAX - 1] = '\0';
236 p = dirname(buf);
237 if (!eina_list_search_unsorted(efreet_desktop_dirs, EINA_COMPARE_CB(strcmp), p))
238 efreet_desktop_dirs = eina_list_append(efreet_desktop_dirs, eina_stringshare_add(p));
239 efreet_cache_desktop_update();
240 }
241 218
242 if (efreet_desktop_cache) eina_hash_direct_add(efreet_desktop_cache, desktop->orig_path, desktop); 219 if (efreet_desktop_cache) eina_hash_direct_add(efreet_desktop_cache, desktop->orig_path, desktop);
243 desktop->cached = 1; 220 desktop->cached = 1;
@@ -777,83 +754,6 @@ efreet_desktop_string_list_join(Eina_List *list)
777 return string; 754 return string;
778} 755}
779 756
780int
781efreet_desktop_write_cache_dirs_file(void)
782{
783 char file[PATH_MAX];
784 int fd = -1;
785 int cachefd = -1;
786 char *dir;
787 struct stat st;
788 struct flock fl;
789
790 if (!efreet_desktop_dirs) return 1;
791
792 snprintf(file, sizeof(file), "%s/desktop_data.lock", efreet_cache_home_get());
793 fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
794 if (fd < 0) return 0;
795 efreet_fsetowner(fd);
796 /* TODO: Retry update cache later */
797 memset(&fl, 0, sizeof(struct flock));
798 fl.l_type = F_WRLCK;
799 fl.l_whence = SEEK_SET;
800 if (fcntl(fd, F_SETLK, &fl) < 0) goto error;
801
802 cachefd = open(efreet_desktop_cache_dirs(), O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR);
803 if (cachefd < 0) goto error;
804 efreet_fsetowner(cachefd);
805 if (fstat(cachefd, &st) < 0) goto error;
806 if (st.st_size > 0)
807 {
808 Eina_List *l, *ln;
809 char *p;
810 char *map;
811
812 map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, cachefd, 0);
813 if (map == MAP_FAILED) goto error;
814 p = map;
815 while (p < map + st.st_size)
816 {
817 unsigned int size = *(unsigned int *)p;
818 p += sizeof(unsigned int);
819 EINA_LIST_FOREACH_SAFE(efreet_desktop_dirs, l, ln, dir)
820 {
821 if (!strcmp(dir, p))
822 {
823 efreet_desktop_dirs = eina_list_remove_list(efreet_desktop_dirs, l);
824 eina_stringshare_del(dir);
825 break;
826 }
827 }
828 p += size;
829 }
830 munmap(map, st.st_size);
831 }
832 EINA_LIST_FREE(efreet_desktop_dirs, dir)
833 {
834 unsigned int size = strlen(dir) + 1;
835 size_t count;
836
837 count = write(cachefd, &size, sizeof(int));
838 count += write(cachefd, dir, size);
839
840 if (count != sizeof(int) + size)
841 DBG("Didn't write all data on cachefd");
842
843 efreet_desktop_changes_monitor_add(dir);
844 eina_stringshare_del(dir);
845 }
846 efreet_desktop_dirs = NULL;
847 if (fd >= 0) close(fd);
848 if (cachefd >= 0) close(cachefd);
849 return 1;
850
851error:
852 if (fd >= 0) close(fd);
853 if (cachefd >= 0) close(cachefd);
854 return 0;
855}
856
857/** 757/**
858 * @internal 758 * @internal
859 * @param desktop The desktop to check 759 * @param desktop The desktop to check
@@ -1267,10 +1167,9 @@ efreet_desktop_environment_check(Efreet_Desktop *desktop)
1267static void 1167static void
1268efreet_desktop_changes_listen(void) 1168efreet_desktop_changes_listen(void)
1269{ 1169{
1270 int dirsfd = -1; 1170 Efreet_Cache_Array_String *arr;
1271 Eina_List *dirs; 1171 Eina_List *dirs;
1272 char *path; 1172 const char *path;
1273 struct stat st;
1274 1173
1275 if (!efreet_cache_update) return; 1174 if (!efreet_cache_update) return;
1276 1175
@@ -1287,33 +1186,14 @@ efreet_desktop_changes_listen(void)
1287 eina_stringshare_del(path); 1186 eina_stringshare_del(path);
1288 } 1187 }
1289 1188
1290 dirsfd = open(efreet_desktop_cache_dirs(), O_RDONLY, S_IRUSR | S_IWUSR); 1189 arr = efreet_cache_desktop_dirs();
1291 if (dirsfd >= 0) 1190 if (arr)
1292 { 1191 {
1293 if ((fstat(dirsfd, &st) == 0) && (st.st_size > 0)) 1192 unsigned int i;
1294 {
1295 char *p;
1296 char *map;
1297 1193
1298 map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, dirsfd, 0); 1194 for (i = 0; i < arr->array_count; i++)
1299 if (map == MAP_FAILED) goto error; 1195 efreet_desktop_changes_monitor_add(arr->array[i]);
1300 p = map;
1301 while (p < map + st.st_size)
1302 {
1303 unsigned int size = *(unsigned int *)p;
1304 p += sizeof(unsigned int);
1305 if (ecore_file_is_dir(p))
1306 efreet_desktop_changes_monitor_add(p);
1307 p += size;
1308 }
1309 munmap(map, st.st_size);
1310 }
1311 close(dirsfd);
1312 } 1196 }
1313
1314 return;
1315error:
1316 if (dirsfd >= 0) close(dirsfd);
1317} 1197}
1318 1198
1319static void 1199static void
diff --git a/legacy/efreet/src/lib/efreet_private.h b/legacy/efreet/src/lib/efreet_private.h
index 2613a88851..ff73e322cf 100644
--- a/legacy/efreet/src/lib/efreet_private.h
+++ b/legacy/efreet/src/lib/efreet_private.h
@@ -180,15 +180,13 @@ size_t efreet_array_cat(char *buffer, size_t size, const char *strs[]);
180 180
181const char *efreet_desktop_environment_get(void); 181const char *efreet_desktop_environment_get(void);
182 182
183/* TODO: Find the best placement for these */
184EAPI const char *efreet_desktop_cache_dirs(void);
185int efreet_desktop_write_cache_dirs_file(void);
186
187void efreet_cache_desktop_update(void); 183void efreet_cache_desktop_update(void);
188void efreet_cache_icon_update(void); 184void efreet_cache_icon_update(void);
189 185
190Efreet_Desktop *efreet_cache_desktop_find(const char *file); 186Efreet_Desktop *efreet_cache_desktop_find(const char *file);
191void efreet_cache_desktop_free(Efreet_Desktop *desktop); 187void efreet_cache_desktop_free(Efreet_Desktop *desktop);
188void efreet_cache_desktop_add(Efreet_Desktop *desktop);
189Efreet_Cache_Array_String *efreet_cache_desktop_dirs(void);
192 190
193Efreet_Cache_Icon *efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *icon); 191Efreet_Cache_Icon *efreet_cache_icon_find(Efreet_Icon_Theme *theme, const char *icon);
194Efreet_Cache_Fallback_Icon *efreet_cache_icon_fallback_find(const char *icon); 192Efreet_Cache_Fallback_Icon *efreet_cache_icon_fallback_find(const char *icon);