summaryrefslogtreecommitdiff
path: root/src/bin/efreet
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2013-12-04 08:36:46 +0100
committerSebastian Dransfeld <sd@tango.flipp.net>2013-12-04 09:12:31 +0100
commit8bc17db6fa8d347b0420a142707fe5837190e41a (patch)
tree054665607998285b7f9a7b1df31bd11c8631e70d /src/bin/efreet
parentc5db264e0a98234d32553ec1b43e612e0da1eeb3 (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.
Diffstat (limited to 'src/bin/efreet')
-rw-r--r--src/bin/efreet/efreet_desktop_cache_create.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/bin/efreet/efreet_desktop_cache_create.c b/src/bin/efreet/efreet_desktop_cache_create.c
index fd8c613305..9ddf26dbb6 100644
--- a/src/bin/efreet/efreet_desktop_cache_create.c
+++ b/src/bin/efreet/efreet_desktop_cache_create.c
@@ -126,6 +126,16 @@ cache_add(const char *path, const char *file_id, int priority EINA_UNUSED, int *
126 return 1; 126 return 1;
127} 127}
128 128
129static int
130stat_cmp(const void *a, const void *b)
131{
132 const struct stat *st1 = a;
133 const struct stat *st2 = b;
134
135 if ((st2->st_dev == st1->st_dev) && (st2->st_ino == st1->st_ino))
136 return 0;
137 return 1;
138}
129 139
130static int 140static int
131cache_scan(Eina_Inarray *stack, const char *path, const char *base_id, 141cache_scan(Eina_Inarray *stack, const char *path, const char *base_id,
@@ -135,31 +145,15 @@ cache_scan(Eina_Inarray *stack, const char *path, const char *base_id,
135 char id[PATH_MAX]; 145 char id[PATH_MAX];
136 Eina_Iterator *it; 146 Eina_Iterator *it;
137 Eina_File_Direct_Info *info; 147 Eina_File_Direct_Info *info;
138 Eina_Bool free_stack = EINA_FALSE;
139 struct stat st; 148 struct stat st;
140 unsigned int i;
141 int ret = 1;
142 149
143 if (!ecore_file_is_dir(path)) return 1; 150 if (!ecore_file_is_dir(path)) return 1;
144 151 if (stat(path, &st) == -1) return 1;
145 if (!stack) 152 if (eina_inarray_search(stack, &st, stat_cmp) >= 0) return 1;
146 {
147 free_stack = EINA_TRUE;
148 stack = eina_inarray_new(sizeof(struct stat), 16);
149 if (!stack) goto end;
150 }
151 if (stat(path, &st) == -1) goto end;
152 for (i = 0; i < eina_inarray_count(stack); i++)
153 {
154 struct stat *st2 = eina_inarray_nth(stack, i);
155
156 if ((st2->st_dev == st.st_dev) && (st2->st_ino == st.st_ino))
157 goto end;
158 }
159 eina_inarray_push(stack, &st); 153 eina_inarray_push(stack, &st);
160 154
161 it = eina_file_stat_ls(path); 155 it = eina_file_stat_ls(path);
162 if (!it) goto end; 156 if (!it) return 1;
163 id[0] = '\0'; 157 id[0] = '\0';
164 EINA_ITERATOR_FOREACH(it, info) 158 EINA_ITERATOR_FOREACH(it, info)
165 { 159 {
@@ -188,15 +182,12 @@ cache_scan(Eina_Inarray *stack, const char *path, const char *base_id,
188 if (!cache_add(info->path, file_id, priority, changed)) 182 if (!cache_add(info->path, file_id, priority, changed))
189 { 183 {
190 eina_iterator_free(it); 184 eina_iterator_free(it);
191 ret = 0; 185 return 0;
192 goto end;
193 } 186 }
194 } 187 }
195 } 188 }
196 eina_iterator_free(it); 189 eina_iterator_free(it);
197end: 190 return 1;
198 if (free_stack) eina_inarray_free(stack);
199 return ret;
200} 191}
201 192
202static int 193static int
@@ -238,6 +229,7 @@ main(int argc, char **argv)
238 Eina_List *systemdirs = NULL; 229 Eina_List *systemdirs = NULL;
239 Eina_List *extra_dirs = NULL; 230 Eina_List *extra_dirs = NULL;
240 Eina_List *l = NULL; 231 Eina_List *l = NULL;
232 Eina_Inarray *stack = NULL;
241 int priority = 0; 233 int priority = 0;
242 char *dir = NULL; 234 char *dir = NULL;
243 char *path; 235 char *path;
@@ -361,18 +353,24 @@ main(int argc, char **argv)
361 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(), 353 dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
362 "applications"); 354 "applications");
363 if (!dirs) goto error; 355 if (!dirs) goto error;
356 stack = eina_inarray_new(sizeof(struct stat), 16);
357 if (!stack) goto error;
364 358
365 EINA_LIST_FREE(dirs, path) 359 EINA_LIST_FREE(dirs, path)
366 { 360 {
367 char file_id[PATH_MAX] = { '\0' }; 361 char file_id[PATH_MAX] = { '\0' };
368 362
369 if (!cache_scan(NULL, path, file_id, priority++, 1, &changed)) 363 eina_inarray_flush(stack);
364 if (!cache_scan(stack, path, file_id, priority++, 1, &changed))
370 goto error; 365 goto error;
371 systemdirs = eina_list_append(systemdirs, path); 366 systemdirs = eina_list_append(systemdirs, path);
372 } 367 }
373 368
374 EINA_LIST_FOREACH(extra_dirs, l, path) 369 EINA_LIST_FOREACH(extra_dirs, l, path)
375 if (!cache_scan(NULL, path, NULL, priority, 0, &changed)) goto error; 370 {
371 eina_inarray_flush(stack);
372 if (!cache_scan(stack, path, NULL, priority, 0, &changed)) goto error;
373 }
376 374
377 /* store util */ 375 /* store util */
378#define STORE_HASH_ARRAY(_hash) \ 376#define STORE_HASH_ARRAY(_hash) \
@@ -475,6 +473,7 @@ main(int argc, char **argv)
475 EINA_LIST_FREE(systemdirs, dir) 473 EINA_LIST_FREE(systemdirs, dir)
476 eina_stringshare_del(dir); 474 eina_stringshare_del(dir);
477 eina_list_free(extra_dirs); 475 eina_list_free(extra_dirs);
476 eina_inarray_free(stack);
478 efreet_shutdown(); 477 efreet_shutdown();
479 ecore_shutdown(); 478 ecore_shutdown();
480 eet_shutdown(); 479 eet_shutdown();
@@ -483,6 +482,7 @@ main(int argc, char **argv)
483 close(lockfd); 482 close(lockfd);
484 return 0; 483 return 0;
485error: 484error:
485 if (stack) eina_inarray_free(stack);
486 IF_FREE(dir); 486 IF_FREE(dir);
487edd_error: 487edd_error:
488 if (old_file_ids) 488 if (old_file_ids)