From 5cbf023d1db850b9a28410e886ba1ba1403d3553 Mon Sep 17 00:00:00 2001 From: Stephen 'Okra' Houston Date: Fri, 10 Feb 2017 14:12:43 -0600 Subject: [PATCH] Ephoto - Cleanup ecore_file_realpath usage. --- src/bin/ephoto_config.c | 5 +- src/bin/ephoto_directory_browser.c | 92 +++++++++++++++++++++++------- src/bin/ephoto_main.c | 43 +++++++++----- src/bin/ephoto_thumb_browser.c | 5 +- 4 files changed, 106 insertions(+), 39 deletions(-) diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c index 92d08c1..47fdcd5 100644 --- a/src/bin/ephoto_config.c +++ b/src/bin/ephoto_config.c @@ -30,12 +30,13 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED, if (strcmp(path, ephoto->config->directory) && strcmp(path, "Last") && ecore_file_exists(path)) { + char *realpath = ecore_file_realpath(path); ephoto_directory_browser_clear(ephoto); ephoto_thumb_browser_clear(ephoto); - eina_stringshare_replace(&ephoto->config->directory, - ecore_file_realpath(path)); + eina_stringshare_replace(&ephoto->config->directory, realpath); ephoto_directory_browser_top_dir_set(ephoto, ephoto->config->directory); ephoto_directory_browser_initialize_structure(ephoto); + free(realpath); } ephoto->config->prompts = elm_check_state_get(ephoto->config->show_prompts); ephoto->config->drop = elm_check_state_get(ephoto->config->move_drop); diff --git a/src/bin/ephoto_directory_browser.c b/src/bin/ephoto_directory_browser.c index d1b30e0..82ae600 100644 --- a/src/bin/ephoto_directory_browser.c +++ b/src/bin/ephoto_directory_browser.c @@ -388,12 +388,19 @@ _check_for_subdirs(Ephoto_Entry *entry) return EINA_FALSE; EINA_ITERATOR_FOREACH(ls, info) { + char *realpath = ecore_file_realpath(info->path); if (info->type != EINA_FILE_DIR && info->type != EINA_FILE_LNK) - continue; - if (info->type == EINA_FILE_LNK && !ecore_file_is_dir( - ecore_file_realpath(info->path))) - continue; + { + free(realpath); + continue; + } + if (info->type == EINA_FILE_LNK && !ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + continue; + } eina_iterator_free(ls); + free(realpath); return EINA_TRUE; } eina_iterator_free(ls); @@ -700,7 +707,9 @@ _todo_items_free(Ephoto_Directory_Browser *db) static void _monitor_add(Ephoto_Entry *e) { - e->monitor = eio_monitor_add(ecore_file_realpath(e->path)); + char *realpath = ecore_file_realpath(e->path); + + e->monitor = eio_monitor_add(realpath); e->monitor_handlers = eina_list_append(e->monitor_handlers, ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, @@ -725,6 +734,8 @@ _monitor_add(Ephoto_Entry *e) eina_list_append(e->monitor_handlers, ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, _monitor_cb, e)); + + free(realpath); } static Eina_Bool @@ -749,11 +760,17 @@ _monitor_cb(void *data, int type, return ECORE_CALLBACK_PASS_ON; if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED) { - if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) - return ECORE_CALLBACK_PASS_ON; + char *realpath = ecore_file_realpath(ev->filename); + if (!ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } if (ephoto_entry_exists(entry->ephoto, ev->filename)) - return ECORE_CALLBACK_PASS_ON; - + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } if (elm_genlist_item_type_get(entry->item) == ELM_GENLIST_ITEM_TREE && elm_genlist_item_expanded_get(entry->item) == EINA_TRUE) { @@ -787,6 +804,7 @@ _monitor_cb(void *data, int type, entry->item = parent; entry->no_delete = EINA_FALSE; } + free(realpath); return ECORE_CALLBACK_PASS_ON; } else if (type == EIO_MONITOR_DIRECTORY_DELETED || type == EIO_MONITOR_FILE_DELETED) @@ -835,8 +853,12 @@ _monitor_cb(void *data, int type, } else if (type == EIO_MONITOR_DIRECTORY_MODIFIED || type == EIO_MONITOR_FILE_MODIFIED) { - if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) - return ECORE_CALLBACK_PASS_ON; + char *realpath = ecore_file_realpath(ev->filename); + if (!ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } if ((elm_genlist_item_expanded_get(entry->item) == EINA_TRUE)) { item = elm_genlist_first_item_get(entry->genlist); @@ -851,6 +873,7 @@ _monitor_cb(void *data, int type, item = elm_genlist_item_next_get(item); } } + free(realpath); return ECORE_CALLBACK_PASS_ON; } return ECORE_CALLBACK_PASS_ON; @@ -876,10 +899,17 @@ _top_monitor_cb(void *data, int type, return ECORE_CALLBACK_PASS_ON; if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED) { - if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) - return ECORE_CALLBACK_PASS_ON; + char *realpath = ecore_file_realpath(ev->filename); + if (!ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } if (ephoto_entry_exists(db->ephoto, ev->filename)) - return ECORE_CALLBACK_PASS_ON; + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } snprintf(buf, PATH_MAX, "%s", ev->filename); e = ephoto_entry_new(db->ephoto, ev->filename, basename(buf), EINA_FILE_DIR); @@ -890,6 +920,7 @@ _top_monitor_cb(void *data, int type, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); if (e->item) _monitor_add(e); + free(realpath); return ECORE_CALLBACK_PASS_ON; } else if (type == EIO_MONITOR_DIRECTORY_DELETED || type == EIO_MONITOR_FILE_DELETED) @@ -912,8 +943,12 @@ _top_monitor_cb(void *data, int type, } else if (type == EIO_MONITOR_DIRECTORY_MODIFIED || type == EIO_MONITOR_FILE_MODIFIED) { - if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) - return ECORE_CALLBACK_PASS_ON; + char *realpath = ecore_file_realpath(ev->filename); + if (!ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + return ECORE_CALLBACK_PASS_ON; + } item = elm_genlist_first_item_get(db->fsel); while (item) { @@ -925,6 +960,7 @@ _top_monitor_cb(void *data, int type, } item = elm_genlist_item_next_get(item); } + free(realpath); return ECORE_CALLBACK_PASS_ON; } return ECORE_CALLBACK_PASS_ON; @@ -1039,14 +1075,16 @@ _ephoto_dir_entry_create(void *data, int type EINA_UNUSED, void *event) Ephoto_Directory_Browser *db = data; Ephoto_Event_Entry_Create *ev = event; Ephoto_Entry *e; + char *realpath; e = ev->entry; + realpath = ecore_file_realpath(e->path); if (e->is_dir) { db->todo_items = eina_list_append(db->todo_items, e); db->animator.count++; } - else if (ecore_file_is_dir(ecore_file_realpath(e->path))) + else if (ecore_file_is_dir((const char *)realpath)) { db->todo_items = eina_list_append(db->todo_items, e); db->animator.count++; @@ -1054,6 +1092,7 @@ _ephoto_dir_entry_create(void *data, int type EINA_UNUSED, void *event) if (!db->animator.todo_items) db->animator.todo_items = ecore_animator_add(_todo_items_process, db); + free(realpath); return ECORE_CALLBACK_PASS_ON; } @@ -1102,6 +1141,7 @@ ephoto_directory_browser_top_dir_set(Ephoto *ephoto, const char *dir) Ephoto_Directory_Browser *db = evas_object_data_get(ephoto->dir_browser, "directory_browser"); Ecore_Event_Handler *handler; + char *realpath = ecore_file_realpath(dir); if (db->monitor) { @@ -1113,7 +1153,7 @@ ephoto_directory_browser_top_dir_set(Ephoto *ephoto, const char *dir) eina_stringshare_replace(&ephoto->top_directory, dir); else ephoto->top_directory = eina_stringshare_add(dir); - db->monitor = eio_monitor_add(ecore_file_realpath(dir)); + db->monitor = eio_monitor_add(realpath); db->monitor_handlers = eina_list_append(db->monitor_handlers, ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, @@ -1138,6 +1178,7 @@ ephoto_directory_browser_top_dir_set(Ephoto *ephoto, const char *dir) eina_list_append(db->monitor_handlers, ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, _top_monitor_cb, db)); + free(realpath); } void @@ -1181,11 +1222,17 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto) cur = next; EINA_ITERATOR_FOREACH(it, finfo) { + char *realpath = ecore_file_realpath(finfo->path); if (finfo->type != EINA_FILE_DIR && finfo->type != EINA_FILE_LNK) - continue; - if (finfo->type == EINA_FILE_LNK && !ecore_file_is_dir( - ecore_file_realpath(finfo->path))) - continue; + { + free(realpath); + continue; + } + if (finfo->type == EINA_FILE_LNK && !ecore_file_is_dir((const char *)realpath)) + { + free(realpath); + continue; + } if (strncmp(finfo->path + finfo->name_start, ".", 1)) { Ephoto_Entry *entry = ephoto_entry_new(ephoto, finfo->path, @@ -1229,6 +1276,7 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto) } } } + free(realpath); } count++; free(dir); diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 1e6e8ac..25c362c 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -671,16 +671,18 @@ ephoto_window_add(const char *path) if (ecore_file_is_dir(path)) { - eina_stringshare_replace(&ephoto->config->directory, - ecore_file_realpath(path)); + char *realpath = ecore_file_realpath(path); + eina_stringshare_replace(&ephoto->config->directory, realpath); + free(realpath); _ephoto_thumb_browser_show(ephoto, NULL); } else { char *dir = ecore_file_dir_get(path); + char *realpath = ecore_file_realpath(path); - eina_stringshare_replace(&ephoto->config->directory, - ecore_file_realpath(dir)); + eina_stringshare_replace(&ephoto->config->directory, realpath); + free(realpath); free(dir); ephoto_single_browser_path_pending_set(ephoto->single_browser, path); elm_naviframe_item_simple_promote(ephoto->pager, @@ -823,24 +825,33 @@ _ephoto_populate_filter(void *data, Eio_File *handler EINA_UNUSED, { Ephoto_Dir_Data *ed = data; const char *bname = info->path + info->name_start; + char *realpath; if (bname[0] == '.') return EINA_FALSE; + realpath = ecore_file_realpath(info->path); if (info->type == EINA_FILE_DIR && !ed->thumbs_only) { + free(realpath); return EINA_TRUE; } - else if (info->type == EINA_FILE_LNK && ecore_file_is_dir( - ecore_file_realpath(info->path))) + else if (info->type == EINA_FILE_LNK && ecore_file_is_dir((const char *)realpath)) { if (ed->thumbs_only) - return EINA_FALSE; + { + free(realpath); + return EINA_FALSE; + } + free(realpath); return ecore_file_is_dir(ecore_file_realpath(info->path)); } else if (!ed->dirs_only) - return _ephoto_eina_file_direct_info_image_useful(info); - else - return EINA_FALSE; + { + free(realpath); + return _ephoto_eina_file_direct_info_image_useful(info); + } + free(realpath); + return EINA_FALSE; } static void @@ -986,6 +997,7 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded, Ephoto_Dir_Data *ed; Ecore_Event_Handler *handler; Evas_Object *o; + char *realpath; ed = malloc(sizeof(Ephoto_Dir_Data)); ed->ephoto = ephoto; @@ -1003,8 +1015,8 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded, evas_object_del(o); ephoto_title_set(ephoto, NULL); - eina_stringshare_replace(&ephoto->config->directory, - ecore_file_realpath(path)); + realpath = ecore_file_realpath(path); + eina_stringshare_replace(&ephoto->config->directory, realpath); if (ed->ephoto->job.change_dir) ecore_job_del(ed->ephoto->job.change_dir); @@ -1028,6 +1040,7 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded, eina_list_append(ephoto->monitor_handlers, ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, _monitor_cb, ephoto)); + free(realpath); } static Eina_Bool @@ -1191,6 +1204,7 @@ ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label, Eina_File_Type type) { Ephoto_Entry *entry; + char *realpath; entry = calloc(1, sizeof(Ephoto_Entry)); entry->ephoto = ephoto; @@ -1198,10 +1212,10 @@ ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label, entry->basename = ecore_file_file_get(entry->path); entry->label = eina_stringshare_add(label); entry->sort_id = NULL; + realpath = ecore_file_realpath(entry->path); if (type == EINA_FILE_DIR) entry->is_dir = EINA_TRUE; - else if (type == EINA_FILE_LNK && ecore_file_is_dir( - ecore_file_realpath(entry->path))) + else if (type == EINA_FILE_LNK && ecore_file_is_dir((const char *)realpath)) entry->is_dir = EINA_TRUE; else entry->is_dir = EINA_FALSE; @@ -1210,6 +1224,7 @@ ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label, else entry->is_link = EINA_FALSE; + free(realpath); return entry; } diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index 56c81ee..2763703 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -1609,12 +1609,14 @@ _ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event) Ephoto_Thumb_Browser *tb = data; Ephoto_Event_Entry_Create *ev = event; Ephoto_Entry *e; + char *realpath; if (tb->dirs_only) return ECORE_CALLBACK_PASS_ON; e = ev->entry; - if (!e->is_dir && !ecore_file_is_dir(ecore_file_realpath(e->path))) + realpath = ecore_file_realpath(e->path); + if (!e->is_dir && !ecore_file_is_dir(realpath)) { Eina_File *f; @@ -1629,6 +1631,7 @@ _ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event) if (!tb->animator.todo_items) tb->animator.todo_items = ecore_animator_add(_todo_items_process, tb); + free(realpath); return ECORE_CALLBACK_PASS_ON; }