summaryrefslogtreecommitdiff
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-10-23 12:34:53 -0700
committerCedric BAIL <cedric@osg.samsung.com>2015-10-23 12:34:53 -0700
commit0cd59bb199d8704bba9707721fbe41bf5c7c0b03 (patch)
tree96ffc1e35a58e116d1ac7d0c1b34bc4f07db528b /src/bin/efreet
parent58b194e0ad56fe83cce3946a5deb0045ee0cbce2 (diff)
efreet: make sure that we use the right directory and ef for the cache.
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c122
1 files changed, 79 insertions, 43 deletions
diff --git a/src/bin/efreet/efreet_desktop_cache_create.c b/src/bin/efreet/efreet_desktop_cache_create.c
index 4ab9fc6488..db14d46293 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -23,8 +23,6 @@ static int _efreet_desktop_cache_log_dom = -1;
23#include "efreet_cache_private.h" 23#include "efreet_cache_private.h"
24 24
25static Eet_Data_Descriptor *edd = NULL; 25static Eet_Data_Descriptor *edd = NULL;
26static Eet_File *ef = NULL;
27static Eet_File *util_ef = NULL;
28 26
29static Eina_Hash *desktops = NULL; 27static Eina_Hash *desktops = NULL;
30 28
@@ -43,7 +41,7 @@ static Eina_Hash *environments = NULL;
43static Eina_Hash *keywords = NULL; 41static Eina_Hash *keywords = NULL;
44 42
45static int 43static int
46cache_add(const char *path, const char *file_id, int priority EINA_UNUSED, int *changed) 44cache_add(Eet_File *ef, const char *path, const char *file_id, int priority EINA_UNUSED, int *changed)
47{ 45{
48 Efreet_Desktop *desk; 46 Efreet_Desktop *desk;
49 char *ext; 47 char *ext;
@@ -145,7 +143,8 @@ stat_cmp(const void *a, const void *b)
145} 143}
146 144
147static int 145static int
148cache_scan(Eina_Inarray *stack, const char *path, const char *base_id, 146cache_scan(Eet_File *ef,
147 Eina_Inarray *stack, const char *path, const char *base_id,
149 int priority, int recurse, int *changed) 148 int priority, int recurse, int *changed)
150{ 149{
151 char *file_id = NULL; 150 char *file_id = NULL;
@@ -184,13 +183,13 @@ cache_scan(Eina_Inarray *stack, const char *path, const char *base_id,
184 { 183 {
185 if (recurse) 184 if (recurse)
186 { 185 {
187 ret = cache_scan(stack, info->path, file_id, priority, recurse, changed); 186 ret = cache_scan(ef, stack, info->path, file_id, priority, recurse, changed);
188 if (!ret) break; 187 if (!ret) break;
189 } 188 }
190 } 189 }
191 else 190 else
192 { 191 {
193 ret = cache_add(info->path, file_id, priority, changed); 192 ret = cache_add(ef, info->path, file_id, priority, changed);
194 if (!ret) break; 193 if (!ret) break;
195 } 194 }
196 } 195 }
@@ -257,6 +256,47 @@ changed:
257 return 1; 256 return 1;
258} 257}
259 258
259static Eet_File *
260_open_temp_eet(Eina_Tmpstr **path, const char *rel)
261{
262 Eet_File *ef;
263 int tmpfd;
264 char buffer[PATH_MAX];
265
266 {
267 char *tmp;
268
269 tmp = strdup(rel);
270 snprintf(buffer, sizeof(buffer), "%s.XXXXXX.cache", basename(tmp));
271 free(tmp);
272 }
273
274 tmpfd = eina_file_mkstemp(buffer, path);
275 if (tmpfd < 0) return NULL;
276 close(tmpfd);
277
278 ef = eet_open(*path, EET_FILE_MODE_READ_WRITE);
279 if (!ef) goto on_error;
280
281 return ef;
282
283 on_error:
284 eina_tmpstr_del(*path);
285 *path = NULL;
286
287 return NULL;
288}
289
290static Eina_Bool
291_file_move(const char *src, const char *dst)
292{
293 if (rename(src, dst) == 0) return EINA_TRUE;
294
295 return eina_file_copy(src, dst,
296 EINA_FILE_COPY_DATA | EINA_FILE_COPY_PERMISSION,
297 NULL, NULL);
298}
299
260int 300int
261main(int argc, char **argv) 301main(int argc, char **argv)
262{ 302{
@@ -272,15 +312,17 @@ main(int argc, char **argv)
272 Eina_List *extra_dirs = NULL; 312 Eina_List *extra_dirs = NULL;
273 Eina_List *l = NULL; 313 Eina_List *l = NULL;
274 Eina_Inarray *stack = NULL; 314 Eina_Inarray *stack = NULL;
315 Eet_File *ef = NULL;
316 Eet_File *util_ef = NULL;
275 int priority = 0; 317 int priority = 0;
276 char *dir = NULL; 318 char *dir = NULL;
277 char *path; 319 char *path;
278 int lockfd = -1, tmpfd; 320 int lockfd = -1;
279 int changed = 0; 321 int changed = 0;
280 int i; 322 int i;
281 char file[PATH_MAX] = { '\0' }; 323 char buffer[PATH_MAX];
282 char util_file[PATH_MAX] = { '\0' }; 324 Eina_Tmpstr *tmpc = NULL;
283 Eina_Tmpstr *tmpstr = NULL; 325 Eina_Tmpstr *tmpuc = NULL;
284 326
285 if (!eina_init()) goto eina_error; 327 if (!eina_init()) goto eina_error;
286 _efreet_desktop_cache_log_dom = 328 _efreet_desktop_cache_log_dom =
@@ -328,11 +370,11 @@ main(int argc, char **argv)
328 if (!efreet_init()) goto efreet_error; 370 if (!efreet_init()) goto efreet_error;
329 371
330 /* create homedir */ 372 /* create homedir */
331 snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get()); 373 snprintf(buffer, sizeof(buffer), "%s/efreet", efreet_cache_home_get());
332 if (!ecore_file_exists(file)) 374 if (!ecore_file_exists(buffer))
333 { 375 {
334 if (!ecore_file_mkpath(file)) goto efreet_error; 376 if (!ecore_file_mkpath(buffer)) goto efreet_error;
335 efreet_setowner(file); 377 efreet_setowner(buffer);
336 } 378 }
337 379
338 /* lock process, so that we only run one copy of this program */ 380 /* lock process, so that we only run one copy of this program */
@@ -351,22 +393,10 @@ main(int argc, char **argv)
351 } 393 }
352 394
353 /* create cache */ 395 /* create cache */
354 snprintf(file, sizeof(file), "%s.XXXXXX.cache", efreet_desktop_cache_file()); 396 ef = _open_temp_eet(&tmpc, efreet_desktop_cache_file());
355 tmpfd = eina_file_mkstemp(file, &tmpstr);
356 if (tmpfd < 0) goto error;
357 close(tmpfd);
358 ef = eet_open(tmpstr, EET_FILE_MODE_READ_WRITE);
359 eina_tmpstr_del(tmpstr);
360 tmpstr = NULL;
361 if (!ef) goto error; 397 if (!ef) goto error;
362 398
363 snprintf(util_file, sizeof(util_file), "%s.XXXXXX.cache", efreet_desktop_util_cache_file()); 399 util_ef = _open_temp_eet(&tmpuc, efreet_desktop_util_cache_file());
364 tmpfd = eina_file_mkstemp(util_file, &tmpstr);
365 if (tmpfd < 0) goto error;
366 close(tmpfd);
367 util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
368 eina_tmpstr_del(tmpstr);
369 tmpstr = NULL;
370 if (!util_ef) goto error; 400 if (!util_ef) goto error;
371 401
372 /* write cache version */ 402 /* write cache version */
@@ -395,6 +425,7 @@ main(int argc, char **argv)
395 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(), 425 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
396 "applications"); 426 "applications");
397 if (!dirs) goto error; 427 if (!dirs) goto error;
428
398 stack = eina_inarray_new(sizeof(struct stat), 16); 429 stack = eina_inarray_new(sizeof(struct stat), 16);
399 if (!stack) goto error; 430 if (!stack) goto error;
400 431
@@ -403,7 +434,7 @@ main(int argc, char **argv)
403 char file_id[PATH_MAX] = { '\0' }; 434 char file_id[PATH_MAX] = { '\0' };
404 435
405 eina_inarray_flush(stack); 436 eina_inarray_flush(stack);
406 if (!cache_scan(stack, path, file_id, priority++, 1, &changed)) 437 if (!cache_scan(ef, stack, path, file_id, priority++, 1, &changed))
407 goto error; 438 goto error;
408 systemdirs = eina_list_append(systemdirs, path); 439 systemdirs = eina_list_append(systemdirs, path);
409 } 440 }
@@ -411,7 +442,7 @@ main(int argc, char **argv)
411 EINA_LIST_FOREACH(extra_dirs, l, path) 442 EINA_LIST_FOREACH(extra_dirs, l, path)
412 { 443 {
413 eina_inarray_flush(stack); 444 eina_inarray_flush(stack);
414 if (!cache_scan(stack, path, NULL, priority, 0, &changed)) goto error; 445 if (!cache_scan(ef, stack, path, NULL, priority, 0, &changed)) goto error;
415 } 446 }
416 447
417 /* store util */ 448 /* store util */
@@ -490,18 +521,18 @@ main(int argc, char **argv)
490 521
491 /* unlink old cache files */ 522 /* unlink old cache files */
492 if (changed) 523 if (changed)
493 { 524 {
494 /* rename tmp files to real files */ 525 /* rename tmp files to real files */
495 if (rename(util_file, efreet_desktop_util_cache_file()) < 0) goto error; 526 if (!_file_move(tmpuc, efreet_desktop_util_cache_file())) goto error;
496 efreet_setowner(efreet_desktop_util_cache_file()); 527 efreet_setowner(efreet_desktop_util_cache_file());
497 if (rename(file, efreet_desktop_cache_file()) < 0) goto error; 528 if (!_file_move(tmpc, efreet_desktop_cache_file())) goto error;
498 efreet_setowner(efreet_desktop_cache_file()); 529 efreet_setowner(efreet_desktop_cache_file());
499 } 530 }
500 else 531 else
501 { 532 {
502 unlink(util_file); 533 unlink(tmpuc);
503 unlink(file); 534 unlink(tmpc);
504 } 535 }
505 536
506 { 537 {
507 char c = 'n'; 538 char c = 'n';
@@ -510,8 +541,10 @@ main(int argc, char **argv)
510 printf("%c\n", c); 541 printf("%c\n", c);
511 } 542 }
512 543
544 eina_tmpstr_del(tmpuc);
545 eina_tmpstr_del(tmpc);
513 EINA_LIST_FREE(systemdirs, dir) 546 EINA_LIST_FREE(systemdirs, dir)
514 eina_stringshare_del(dir); 547 eina_stringshare_del(dir);
515 eina_list_free(extra_dirs); 548 eina_list_free(extra_dirs);
516 eina_inarray_free(stack); 549 eina_inarray_free(stack);
517 efreet_shutdown(); 550 efreet_shutdown();
@@ -521,8 +554,11 @@ main(int argc, char **argv)
521 eina_shutdown(); 554 eina_shutdown();
522 close(lockfd); 555 close(lockfd);
523 return 0; 556 return 0;
557
524error: 558error:
525 eina_tmpstr_del(tmpstr); 559 eina_tmpstr_del(tmpuc);
560 eina_tmpstr_del(tmpc);
561
526 if (stack) eina_inarray_free(stack); 562 if (stack) eina_inarray_free(stack);
527 IF_FREE(dir); 563 IF_FREE(dir);
528edd_error: 564edd_error: