Ephoto - Cleanup ecore_file_realpath usage.

This commit is contained in:
Stephen 'Okra' Houston 2017-02-10 14:12:43 -06:00
parent 5129f92d3a
commit 5cbf023d1d
4 changed files with 106 additions and 39 deletions

View File

@ -30,12 +30,13 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
if (strcmp(path, ephoto->config->directory) && strcmp(path, "Last") && if (strcmp(path, ephoto->config->directory) && strcmp(path, "Last") &&
ecore_file_exists(path)) ecore_file_exists(path))
{ {
char *realpath = ecore_file_realpath(path);
ephoto_directory_browser_clear(ephoto); ephoto_directory_browser_clear(ephoto);
ephoto_thumb_browser_clear(ephoto); ephoto_thumb_browser_clear(ephoto);
eina_stringshare_replace(&ephoto->config->directory, eina_stringshare_replace(&ephoto->config->directory, realpath);
ecore_file_realpath(path));
ephoto_directory_browser_top_dir_set(ephoto, ephoto->config->directory); ephoto_directory_browser_top_dir_set(ephoto, ephoto->config->directory);
ephoto_directory_browser_initialize_structure(ephoto); ephoto_directory_browser_initialize_structure(ephoto);
free(realpath);
} }
ephoto->config->prompts = elm_check_state_get(ephoto->config->show_prompts); ephoto->config->prompts = elm_check_state_get(ephoto->config->show_prompts);
ephoto->config->drop = elm_check_state_get(ephoto->config->move_drop); ephoto->config->drop = elm_check_state_get(ephoto->config->move_drop);

View File

@ -388,12 +388,19 @@ _check_for_subdirs(Ephoto_Entry *entry)
return EINA_FALSE; return EINA_FALSE;
EINA_ITERATOR_FOREACH(ls, info) EINA_ITERATOR_FOREACH(ls, info)
{ {
char *realpath = ecore_file_realpath(info->path);
if (info->type != EINA_FILE_DIR && info->type != EINA_FILE_LNK) if (info->type != EINA_FILE_DIR && info->type != EINA_FILE_LNK)
continue; {
if (info->type == EINA_FILE_LNK && !ecore_file_is_dir( free(realpath);
ecore_file_realpath(info->path))) continue;
continue; }
if (info->type == EINA_FILE_LNK && !ecore_file_is_dir((const char *)realpath))
{
free(realpath);
continue;
}
eina_iterator_free(ls); eina_iterator_free(ls);
free(realpath);
return EINA_TRUE; return EINA_TRUE;
} }
eina_iterator_free(ls); eina_iterator_free(ls);
@ -700,7 +707,9 @@ _todo_items_free(Ephoto_Directory_Browser *db)
static void static void
_monitor_add(Ephoto_Entry *e) _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 = e->monitor_handlers =
eina_list_append(e->monitor_handlers, eina_list_append(e->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, ecore_event_handler_add(EIO_MONITOR_FILE_CREATED,
@ -725,6 +734,8 @@ _monitor_add(Ephoto_Entry *e)
eina_list_append(e->monitor_handlers, eina_list_append(e->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED,
_monitor_cb, e)); _monitor_cb, e));
free(realpath);
} }
static Eina_Bool static Eina_Bool
@ -749,11 +760,17 @@ _monitor_cb(void *data, int type,
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED) if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED)
{ {
if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) char *realpath = ecore_file_realpath(ev->filename);
return ECORE_CALLBACK_PASS_ON; if (!ecore_file_is_dir((const char *)realpath))
{
free(realpath);
return ECORE_CALLBACK_PASS_ON;
}
if (ephoto_entry_exists(entry->ephoto, ev->filename)) 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 && if (elm_genlist_item_type_get(entry->item) == ELM_GENLIST_ITEM_TREE &&
elm_genlist_item_expanded_get(entry->item) == EINA_TRUE) elm_genlist_item_expanded_get(entry->item) == EINA_TRUE)
{ {
@ -787,6 +804,7 @@ _monitor_cb(void *data, int type,
entry->item = parent; entry->item = parent;
entry->no_delete = EINA_FALSE; entry->no_delete = EINA_FALSE;
} }
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }
else if (type == EIO_MONITOR_DIRECTORY_DELETED || type == EIO_MONITOR_FILE_DELETED) 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) else if (type == EIO_MONITOR_DIRECTORY_MODIFIED || type == EIO_MONITOR_FILE_MODIFIED)
{ {
if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) char *realpath = ecore_file_realpath(ev->filename);
return ECORE_CALLBACK_PASS_ON; 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)) if ((elm_genlist_item_expanded_get(entry->item) == EINA_TRUE))
{ {
item = elm_genlist_first_item_get(entry->genlist); 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); item = elm_genlist_item_next_get(item);
} }
} }
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }
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; return ECORE_CALLBACK_PASS_ON;
if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED) if (type == EIO_MONITOR_DIRECTORY_CREATED || type == EIO_MONITOR_FILE_CREATED)
{ {
if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) char *realpath = ecore_file_realpath(ev->filename);
return ECORE_CALLBACK_PASS_ON; if (!ecore_file_is_dir((const char *)realpath))
{
free(realpath);
return ECORE_CALLBACK_PASS_ON;
}
if (ephoto_entry_exists(db->ephoto, ev->filename)) 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); snprintf(buf, PATH_MAX, "%s", ev->filename);
e = ephoto_entry_new(db->ephoto, ev->filename, basename(buf), e = ephoto_entry_new(db->ephoto, ev->filename, basename(buf),
EINA_FILE_DIR); EINA_FILE_DIR);
@ -890,6 +920,7 @@ _top_monitor_cb(void *data, int type,
NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
if (e->item) if (e->item)
_monitor_add(e); _monitor_add(e);
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }
else if (type == EIO_MONITOR_DIRECTORY_DELETED || type == EIO_MONITOR_FILE_DELETED) 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) else if (type == EIO_MONITOR_DIRECTORY_MODIFIED || type == EIO_MONITOR_FILE_MODIFIED)
{ {
if (!ecore_file_is_dir(ecore_file_realpath(ev->filename))) char *realpath = ecore_file_realpath(ev->filename);
return ECORE_CALLBACK_PASS_ON; if (!ecore_file_is_dir((const char *)realpath))
{
free(realpath);
return ECORE_CALLBACK_PASS_ON;
}
item = elm_genlist_first_item_get(db->fsel); item = elm_genlist_first_item_get(db->fsel);
while (item) while (item)
{ {
@ -925,6 +960,7 @@ _top_monitor_cb(void *data, int type,
} }
item = elm_genlist_item_next_get(item); item = elm_genlist_item_next_get(item);
} }
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }
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_Directory_Browser *db = data;
Ephoto_Event_Entry_Create *ev = event; Ephoto_Event_Entry_Create *ev = event;
Ephoto_Entry *e; Ephoto_Entry *e;
char *realpath;
e = ev->entry; e = ev->entry;
realpath = ecore_file_realpath(e->path);
if (e->is_dir) if (e->is_dir)
{ {
db->todo_items = eina_list_append(db->todo_items, e); db->todo_items = eina_list_append(db->todo_items, e);
db->animator.count++; 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->todo_items = eina_list_append(db->todo_items, e);
db->animator.count++; db->animator.count++;
@ -1054,6 +1092,7 @@ _ephoto_dir_entry_create(void *data, int type EINA_UNUSED, void *event)
if (!db->animator.todo_items) if (!db->animator.todo_items)
db->animator.todo_items = ecore_animator_add(_todo_items_process, db); db->animator.todo_items = ecore_animator_add(_todo_items_process, db);
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }
@ -1102,6 +1141,7 @@ ephoto_directory_browser_top_dir_set(Ephoto *ephoto, const char *dir)
Ephoto_Directory_Browser *db = Ephoto_Directory_Browser *db =
evas_object_data_get(ephoto->dir_browser, "directory_browser"); evas_object_data_get(ephoto->dir_browser, "directory_browser");
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
char *realpath = ecore_file_realpath(dir);
if (db->monitor) 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); eina_stringshare_replace(&ephoto->top_directory, dir);
else else
ephoto->top_directory = eina_stringshare_add(dir); 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 = db->monitor_handlers =
eina_list_append(db->monitor_handlers, eina_list_append(db->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, 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, eina_list_append(db->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED,
_top_monitor_cb, db)); _top_monitor_cb, db));
free(realpath);
} }
void void
@ -1181,11 +1222,17 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto)
cur = next; cur = next;
EINA_ITERATOR_FOREACH(it, finfo) EINA_ITERATOR_FOREACH(it, finfo)
{ {
char *realpath = ecore_file_realpath(finfo->path);
if (finfo->type != EINA_FILE_DIR && finfo->type != EINA_FILE_LNK) if (finfo->type != EINA_FILE_DIR && finfo->type != EINA_FILE_LNK)
continue; {
if (finfo->type == EINA_FILE_LNK && !ecore_file_is_dir( free(realpath);
ecore_file_realpath(finfo->path))) continue;
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)) if (strncmp(finfo->path + finfo->name_start, ".", 1))
{ {
Ephoto_Entry *entry = ephoto_entry_new(ephoto, finfo->path, Ephoto_Entry *entry = ephoto_entry_new(ephoto, finfo->path,
@ -1229,6 +1276,7 @@ ephoto_directory_browser_initialize_structure(Ephoto *ephoto)
} }
} }
} }
free(realpath);
} }
count++; count++;
free(dir); free(dir);

View File

@ -671,16 +671,18 @@ ephoto_window_add(const char *path)
if (ecore_file_is_dir(path)) if (ecore_file_is_dir(path))
{ {
eina_stringshare_replace(&ephoto->config->directory, char *realpath = ecore_file_realpath(path);
ecore_file_realpath(path)); eina_stringshare_replace(&ephoto->config->directory, realpath);
free(realpath);
_ephoto_thumb_browser_show(ephoto, NULL); _ephoto_thumb_browser_show(ephoto, NULL);
} }
else else
{ {
char *dir = ecore_file_dir_get(path); char *dir = ecore_file_dir_get(path);
char *realpath = ecore_file_realpath(path);
eina_stringshare_replace(&ephoto->config->directory, eina_stringshare_replace(&ephoto->config->directory, realpath);
ecore_file_realpath(dir)); free(realpath);
free(dir); free(dir);
ephoto_single_browser_path_pending_set(ephoto->single_browser, path); ephoto_single_browser_path_pending_set(ephoto->single_browser, path);
elm_naviframe_item_simple_promote(ephoto->pager, 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; Ephoto_Dir_Data *ed = data;
const char *bname = info->path + info->name_start; const char *bname = info->path + info->name_start;
char *realpath;
if (bname[0] == '.') if (bname[0] == '.')
return EINA_FALSE; return EINA_FALSE;
realpath = ecore_file_realpath(info->path);
if (info->type == EINA_FILE_DIR && !ed->thumbs_only) if (info->type == EINA_FILE_DIR && !ed->thumbs_only)
{ {
free(realpath);
return EINA_TRUE; return EINA_TRUE;
} }
else if (info->type == EINA_FILE_LNK && ecore_file_is_dir( else if (info->type == EINA_FILE_LNK && ecore_file_is_dir((const char *)realpath))
ecore_file_realpath(info->path)))
{ {
if (ed->thumbs_only) if (ed->thumbs_only)
return EINA_FALSE; {
free(realpath);
return EINA_FALSE;
}
free(realpath);
return ecore_file_is_dir(ecore_file_realpath(info->path)); return ecore_file_is_dir(ecore_file_realpath(info->path));
} }
else if (!ed->dirs_only) else if (!ed->dirs_only)
return _ephoto_eina_file_direct_info_image_useful(info); {
else free(realpath);
return EINA_FALSE; return _ephoto_eina_file_direct_info_image_useful(info);
}
free(realpath);
return EINA_FALSE;
} }
static void static void
@ -986,6 +997,7 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded,
Ephoto_Dir_Data *ed; Ephoto_Dir_Data *ed;
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
Evas_Object *o; Evas_Object *o;
char *realpath;
ed = malloc(sizeof(Ephoto_Dir_Data)); ed = malloc(sizeof(Ephoto_Dir_Data));
ed->ephoto = ephoto; ed->ephoto = ephoto;
@ -1003,8 +1015,8 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded,
evas_object_del(o); evas_object_del(o);
ephoto_title_set(ephoto, NULL); ephoto_title_set(ephoto, NULL);
eina_stringshare_replace(&ephoto->config->directory, realpath = ecore_file_realpath(path);
ecore_file_realpath(path)); eina_stringshare_replace(&ephoto->config->directory, realpath);
if (ed->ephoto->job.change_dir) if (ed->ephoto->job.change_dir)
ecore_job_del(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, eina_list_append(ephoto->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, ecore_event_handler_add(EIO_MONITOR_FILE_DELETED,
_monitor_cb, ephoto)); _monitor_cb, ephoto));
free(realpath);
} }
static Eina_Bool static Eina_Bool
@ -1191,6 +1204,7 @@ ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label,
Eina_File_Type type) Eina_File_Type type)
{ {
Ephoto_Entry *entry; Ephoto_Entry *entry;
char *realpath;
entry = calloc(1, sizeof(Ephoto_Entry)); entry = calloc(1, sizeof(Ephoto_Entry));
entry->ephoto = ephoto; 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->basename = ecore_file_file_get(entry->path);
entry->label = eina_stringshare_add(label); entry->label = eina_stringshare_add(label);
entry->sort_id = NULL; entry->sort_id = NULL;
realpath = ecore_file_realpath(entry->path);
if (type == EINA_FILE_DIR) if (type == EINA_FILE_DIR)
entry->is_dir = EINA_TRUE; entry->is_dir = EINA_TRUE;
else if (type == EINA_FILE_LNK && ecore_file_is_dir( else if (type == EINA_FILE_LNK && ecore_file_is_dir((const char *)realpath))
ecore_file_realpath(entry->path)))
entry->is_dir = EINA_TRUE; entry->is_dir = EINA_TRUE;
else else
entry->is_dir = EINA_FALSE; entry->is_dir = EINA_FALSE;
@ -1210,6 +1224,7 @@ ephoto_entry_new(Ephoto *ephoto, const char *path, const char *label,
else else
entry->is_link = EINA_FALSE; entry->is_link = EINA_FALSE;
free(realpath);
return entry; return entry;
} }

View File

@ -1609,12 +1609,14 @@ _ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event)
Ephoto_Thumb_Browser *tb = data; Ephoto_Thumb_Browser *tb = data;
Ephoto_Event_Entry_Create *ev = event; Ephoto_Event_Entry_Create *ev = event;
Ephoto_Entry *e; Ephoto_Entry *e;
char *realpath;
if (tb->dirs_only) if (tb->dirs_only)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
e = ev->entry; 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; Eina_File *f;
@ -1629,6 +1631,7 @@ _ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event)
if (!tb->animator.todo_items) if (!tb->animator.todo_items)
tb->animator.todo_items = ecore_animator_add(_todo_items_process, tb); tb->animator.todo_items = ecore_animator_add(_todo_items_process, tb);
free(realpath);
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
} }