summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2010-03-02 20:07:41 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2010-03-02 20:07:41 +0000
commit6d10aea822f85b47d2b15d7a5036e6b9ff2f2da0 (patch)
tree4fb5e19b55c37e203cacf39d748f1e4f1fa5eb9b
parentf880806ff2eba23567bb1ea4f73d4db4ce7aae75 (diff)
Use realpath to clean path
SVN revision: 46801
-rw-r--r--legacy/efreet/src/lib/efreet_base.c34
-rw-r--r--legacy/efreet/src/lib/efreet_desktop.c21
2 files changed, 17 insertions, 38 deletions
diff --git a/legacy/efreet/src/lib/efreet_base.c b/legacy/efreet/src/lib/efreet_base.c
index edb9f7659c..6fc7f04805 100644
--- a/legacy/efreet/src/lib/efreet_base.c
+++ b/legacy/efreet/src/lib/efreet_base.c
@@ -35,7 +35,6 @@ static int _efreet_base_log_dom = -1;
35static const char *efreet_dir_get(const char *key, const char *fallback); 35static const char *efreet_dir_get(const char *key, const char *fallback);
36static Eina_List *efreet_dirs_get(const char *key, 36static Eina_List *efreet_dirs_get(const char *key,
37 const char *fallback); 37 const char *fallback);
38static const char *efreet_path_clean(const char *path);
39 38
40/** 39/**
41 * @internal 40 * @internal
@@ -93,7 +92,7 @@ efreet_home_dir_get(void)
93 if (!efreet_home_dir || efreet_home_dir[0] == '\0') 92 if (!efreet_home_dir || efreet_home_dir[0] == '\0')
94 efreet_home_dir = "/tmp"; 93 efreet_home_dir = "/tmp";
95 94
96 efreet_home_dir = efreet_path_clean(efreet_home_dir); 95 efreet_home_dir = eina_stringshare_add(efreet_home_dir);
97 96
98 return efreet_home_dir; 97 return efreet_home_dir;
99} 98}
@@ -204,10 +203,10 @@ efreet_dir_get(const char *key, const char *fallback)
204 dir = malloc(sizeof(char) * len); 203 dir = malloc(sizeof(char) * len);
205 snprintf(dir, len, "%s%s", user, fallback); 204 snprintf(dir, len, "%s%s", user, fallback);
206 205
207 t = efreet_path_clean(dir); 206 t = eina_stringshare_add(dir);
208 FREE(dir); 207 FREE(dir);
209 } 208 }
210 else t = efreet_path_clean(dir); 209 else t = eina_stringshare_add(dir);
211 210
212 return t; 211 return t;
213} 212}
@@ -240,37 +239,14 @@ efreet_dirs_get(const char *key, const char *fallback)
240 { 239 {
241 *p = '\0'; 240 *p = '\0';
242 if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s)) 241 if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
243 dirs = eina_list_append(dirs, (void *)efreet_path_clean(s)); 242 dirs = eina_list_append(dirs, (void *)eina_stringshare_add(s));
244 243
245 s = ++p; 244 s = ++p;
246 p = strchr(s, EFREET_PATH_SEP); 245 p = strchr(s, EFREET_PATH_SEP);
247 } 246 }
248 if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s)) 247 if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
249 dirs = eina_list_append(dirs, (void *)efreet_path_clean(s)); 248 dirs = eina_list_append(dirs, (void *)eina_stringshare_add(s));
250 FREE(tmp); 249 FREE(tmp);
251 250
252 return dirs; 251 return dirs;
253} 252}
254
255static const char *
256efreet_path_clean(const char *path)
257{
258 char *p, *pp;
259 const char *ret;
260
261 if (!path) return eina_stringshare_add("");
262 if (!*path) return eina_stringshare_add("");
263
264 p = strdup(path);
265 if (!p) return eina_stringshare_add("");
266 for (pp = p; *pp; pp++)
267 {
268 if (*pp == '/' && *(pp + 1) == '/')
269 memmove(pp, pp + 1, strlen(pp + 1) + 1);
270 if (*pp == '/' && *(pp + 1) == '\0')
271 *pp = '\0';
272 }
273 ret = eina_stringshare_add(p);
274 free(p);
275 return ret;
276}
diff --git a/legacy/efreet/src/lib/efreet_desktop.c b/legacy/efreet/src/lib/efreet_desktop.c
index abf8ed9bce..5b4a0aa7e9 100644
--- a/legacy/efreet/src/lib/efreet_desktop.c
+++ b/legacy/efreet/src/lib/efreet_desktop.c
@@ -358,15 +358,18 @@ efreet_desktop_new(const char *file)
358{ 358{
359 /* TODO: Need file monitor on file and events to notify change */ 359 /* TODO: Need file monitor on file and events to notify change */
360 Efreet_Desktop *desktop = NULL; 360 Efreet_Desktop *desktop = NULL;
361 char *rp = NULL;
361 362
363 rp = ecore_file_realpath(file);
362 if (cache) 364 if (cache)
363 { 365 {
364 /* TODO: Check if the cached version is out of date */ 366 /* TODO: Check if the cached version is out of date */
365 desktop = eet_data_read(cache, desktop_edd, file); 367 desktop = eet_data_read(cache, desktop_edd, rp);
366 if (desktop) 368 if (desktop)
367 { 369 {
368 desktop->ref = 1; 370 desktop->ref = 1;
369 desktop->eet = 1; 371 desktop->eet = 1;
372 free(rp);
370 return desktop; 373 return desktop;
371 } 374 }
372 } 375 }
@@ -375,22 +378,22 @@ efreet_desktop_new(const char *file)
375 * efreet_desktop_cache_create can add it to the cache 378 * efreet_desktop_cache_create can add it to the cache
376 */ 379 */
377 380
378 if (!ecore_file_exists(file)) return NULL; 381 if (!ecore_file_exists(rp)) goto error;
379 382
380 desktop = NEW(Efreet_Desktop, 1); 383 desktop = NEW(Efreet_Desktop, 1);
381 if (!desktop) return NULL; 384 if (!desktop) goto error;
382 385
383 desktop->orig_path = strdup(file); 386 desktop->orig_path = rp;
384 387
385 if (!efreet_desktop_read(desktop)) 388 if (!efreet_desktop_read(desktop)) goto error;
386 {
387 efreet_desktop_free(desktop);
388 return NULL;
389 }
390 389
391 desktop->ref = 1; 390 desktop->ref = 1;
392 391
393 return desktop; 392 return desktop;
393error:
394 if (desktop) efreet_desktop_free(desktop);
395 if (rp) free(rp);
396 return NULL;
394} 397}
395 398
396/** 399/**