summaryrefslogtreecommitdiff
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2013-12-04 09:03:56 +0100
committerSebastian Dransfeld <sd@tango.flipp.net>2013-12-04 09:12:31 +0100
commit70474a4bc52b46f36d55c9dd343ff4758a6b030b (patch)
treec8c1c38dc36b93528ee2af6bdce9c1f20be88690 /src/bin/efreet
parent8bc17db6fa8d347b0420a142707fe5837190e41a (diff)
efreet: Create stack at start of recursion
No need to check for NULL stack, we know where we start our recursive scan, so create the stack there. Also fixes CID1132751 and CID1132752
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreetd_cache.c83
1 files changed, 40 insertions, 43 deletions
diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c
index 6ca556ad25..94e48f1dda 100644
--- a/src/bin/efreet/efreetd_cache.c
+++ b/src/bin/efreet/efreetd_cache.c
@@ -248,29 +248,26 @@ desktop_changes_monitor_add(const char *path)
248 eina_hash_add(desktop_change_monitors, path, mon); 248 eina_hash_add(desktop_change_monitors, path, mon);
249} 249}
250 250
251static int
252stat_cmp(const void *a, const void *b)
253{
254 const struct stat *st1 = a;
255 const struct stat *st2 = b;
256
257 if ((st2->st_dev == st1->st_dev) && (st2->st_ino == st1->st_ino))
258 return 0;
259 return 1;
260}
261
251static void 262static void
252icon_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Bool base) 263icon_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Bool base)
253{ 264{
254 Eina_Iterator *it; 265 Eina_Iterator *it;
255 Eina_File_Direct_Info *info; 266 Eina_File_Direct_Info *info;
256 Eina_Bool free_stack = EINA_FALSE;
257 struct stat st; 267 struct stat st;
258 unsigned int i;
259 268
260 if (!stack)
261 {
262 free_stack = EINA_TRUE;
263 stack = eina_inarray_new(sizeof(struct stat), 16);
264 if (!stack) return;
265 }
266 if (stat(path, &st) == -1) return; 269 if (stat(path, &st) == -1) return;
267 for (i = 0; i < eina_inarray_count(stack); i++) 270 if (eina_inarray_search(stack, &st, stat_cmp) >= 0) return;
268 {
269 struct stat *st2 = eina_inarray_nth(stack, i);
270
271 if ((st2->st_dev == st.st_dev) && (st2->st_ino == st.st_ino))
272 return;
273 }
274 eina_inarray_push(stack, &st); 271 eina_inarray_push(stack, &st);
275 272
276 if ((!ecore_file_is_dir(path)) && (base)) 273 if ((!ecore_file_is_dir(path)) && (base))
@@ -285,7 +282,7 @@ icon_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Bool b
285 } 282 }
286 if (ecore_file_is_dir(path)) icon_changes_monitor_add(path); 283 if (ecore_file_is_dir(path)) icon_changes_monitor_add(path);
287 it = eina_file_stat_ls(path); 284 it = eina_file_stat_ls(path);
288 if (!it) goto end; 285 if (!it) return;
289 EINA_ITERATOR_FOREACH(it, info) 286 EINA_ITERATOR_FOREACH(it, info)
290 { 287 {
291 if (info->path[info->name_start] == '.') continue; 288 if (info->path[info->name_start] == '.') continue;
@@ -294,8 +291,6 @@ icon_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Bool b
294 icon_changes_listen_recursive(stack, info->path, EINA_FALSE); 291 icon_changes_listen_recursive(stack, info->path, EINA_FALSE);
295 } 292 }
296 eina_iterator_free(it); 293 eina_iterator_free(it);
297end:
298 if (free_stack) eina_inarray_free(stack);
299} 294}
300 295
301static void 296static void
@@ -303,24 +298,10 @@ desktop_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Boo
303{ 298{
304 Eina_Iterator *it; 299 Eina_Iterator *it;
305 Eina_File_Direct_Info *info; 300 Eina_File_Direct_Info *info;
306 Eina_Bool free_stack = EINA_FALSE;
307 struct stat st; 301 struct stat st;
308 unsigned int i;
309 302
310 if (!stack)
311 {
312 free_stack = EINA_TRUE;
313 stack = eina_inarray_new(sizeof(struct stat), 16);
314 if (!stack) return;
315 }
316 if (stat(path, &st) == -1) return; 303 if (stat(path, &st) == -1) return;
317 for (i = 0; i < eina_inarray_count(stack); i++) 304 if (eina_inarray_search(stack, &st, stat_cmp) >= 0) return;
318 {
319 struct stat *st2 = eina_inarray_nth(stack, i);
320
321 if ((st2->st_dev == st.st_dev) && (st2->st_ino == st.st_ino))
322 return;
323 }
324 eina_inarray_push(stack, &st); 305 eina_inarray_push(stack, &st);
325 if ((!ecore_file_is_dir(path)) && (base)) 306 if ((!ecore_file_is_dir(path)) && (base))
326 { 307 {
@@ -334,7 +315,7 @@ desktop_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Boo
334 } 315 }
335 if (ecore_file_is_dir(path)) desktop_changes_monitor_add(path); 316 if (ecore_file_is_dir(path)) desktop_changes_monitor_add(path);
336 it = eina_file_stat_ls(path); 317 it = eina_file_stat_ls(path);
337 if (!it) goto end; 318 if (!it) return;
338 EINA_ITERATOR_FOREACH(it, info) 319 EINA_ITERATOR_FOREACH(it, info)
339 { 320 {
340 if (info->path[info->name_start] == '.') continue; 321 if (info->path[info->name_start] == '.') continue;
@@ -343,8 +324,6 @@ desktop_changes_listen_recursive(Eina_Inarray *stack, const char *path, Eina_Boo
343 desktop_changes_listen_recursive(stack, info->path, EINA_FALSE); 324 desktop_changes_listen_recursive(stack, info->path, EINA_FALSE);
344 } 325 }
345 eina_iterator_free(it); 326 eina_iterator_free(it);
346end:
347 if (free_stack) eina_inarray_free(stack);
348} 327}
349 328
350static void 329static void
@@ -354,29 +333,37 @@ icon_changes_listen(void)
354 Eina_List *xdg_dirs; 333 Eina_List *xdg_dirs;
355 char buf[PATH_MAX]; 334 char buf[PATH_MAX];
356 const char *dir; 335 const char *dir;
336 Eina_Inarray *stack;
357 337
358 icon_changes_listen_recursive(NULL, efreet_icon_deprecated_user_dir_get(), EINA_TRUE); 338 stack = eina_inarray_new(sizeof(struct stat), 16);
359 icon_changes_listen_recursive(NULL, efreet_icon_user_dir_get(), EINA_TRUE); 339 if (!stack) return;
340 icon_changes_listen_recursive(stack, efreet_icon_deprecated_user_dir_get(), EINA_TRUE);
341 eina_inarray_flush(stack);
342 icon_changes_listen_recursive(stack, efreet_icon_user_dir_get(), EINA_TRUE);
360 EINA_LIST_FOREACH(icon_extra_dirs, l, dir) 343 EINA_LIST_FOREACH(icon_extra_dirs, l, dir)
361 { 344 {
362 icon_changes_listen_recursive(NULL, dir, EINA_TRUE); 345 eina_inarray_flush(stack);
346 icon_changes_listen_recursive(stack, dir, EINA_TRUE);
363 } 347 }
364 348
365 xdg_dirs = efreet_data_dirs_get(); 349 xdg_dirs = efreet_data_dirs_get();
366 EINA_LIST_FOREACH(xdg_dirs, l, dir) 350 EINA_LIST_FOREACH(xdg_dirs, l, dir)
367 { 351 {
368 snprintf(buf, sizeof(buf), "%s/icons", dir); 352 snprintf(buf, sizeof(buf), "%s/icons", dir);
369 icon_changes_listen_recursive(NULL, buf, EINA_TRUE); 353 eina_inarray_flush(stack);
354 icon_changes_listen_recursive(stack, buf, EINA_TRUE);
370 } 355 }
371 356
372#ifndef STRICT_SPEC 357#ifndef STRICT_SPEC
373 EINA_LIST_FOREACH(xdg_dirs, l, dir) 358 EINA_LIST_FOREACH(xdg_dirs, l, dir)
374 { 359 {
375 snprintf(buf, sizeof(buf), "%s/pixmaps", dir); 360 snprintf(buf, sizeof(buf), "%s/pixmaps", dir);
376 icon_changes_listen_recursive(NULL, buf, EINA_TRUE); 361 eina_inarray_flush(stack);
362 icon_changes_listen_recursive(stack, buf, EINA_TRUE);
377 } 363 }
378#endif 364#endif
379 icon_changes_monitor_add("/usr/share/pixmaps"); 365 icon_changes_monitor_add("/usr/share/pixmaps");
366 eina_inarray_free(stack);
380} 367}
381 368
382static void 369static void
@@ -384,11 +371,21 @@ desktop_changes_listen(void)
384{ 371{
385 Eina_List *l; 372 Eina_List *l;
386 const char *path; 373 const char *path;
374 Eina_Inarray *stack;
387 375
376 stack = eina_inarray_new(sizeof(struct stat), 16);
377 if (!stack) return;
388 EINA_LIST_FOREACH(desktop_system_dirs, l, path) 378 EINA_LIST_FOREACH(desktop_system_dirs, l, path)
389 desktop_changes_listen_recursive(NULL, path, EINA_TRUE); 379 {
380 eina_inarray_flush(stack);
381 desktop_changes_listen_recursive(stack, path, EINA_TRUE);
382 }
390 EINA_LIST_FOREACH(desktop_extra_dirs, l, path) 383 EINA_LIST_FOREACH(desktop_extra_dirs, l, path)
391 desktop_changes_listen_recursive(NULL, path, EINA_TRUE); 384 {
385 eina_inarray_flush(stack);
386 desktop_changes_listen_recursive(stack, path, EINA_TRUE);
387 }
388 eina_inarray_free(stack);
392} 389}
393 390
394static void 391static void