Ephoto: Fix use of stat/lstat, use eina_environment to get HOME and tmp dirs.

This commit is contained in:
Stephen 'Okra' Houston 2017-03-29 16:12:50 -05:00
parent 751e08acc7
commit ef805cefa9
8 changed files with 23 additions and 46 deletions

View File

@ -19,7 +19,7 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
if (!strcmp(text, _("Root Directory"))) if (!strcmp(text, _("Root Directory")))
path = "/"; path = "/";
else if (!strcmp(text, _("Home Directory"))) else if (!strcmp(text, _("Home Directory")))
path = getenv("HOME"); path = eina_environment_home_get();
else if (!strcmp(text, _("Last Open Directory"))) else if (!strcmp(text, _("Last Open Directory")))
path = "Last"; path = "Last";
else else
@ -778,7 +778,7 @@ ephoto_config_init(Ephoto *ephoto)
ephoto->config->window_height = 500*elm_config_scale_get(); ephoto->config->window_height = 500*elm_config_scale_get();
ephoto->config->fsel_hide = 0; ephoto->config->fsel_hide = 0;
ephoto->config->lpane_size = .15; ephoto->config->lpane_size = .15;
ephoto->config->open = eina_stringshare_add(getenv("HOME")); ephoto->config->open = eina_stringshare_add(eina_environment_home_get());
ephoto->config->prompts = 1; ephoto->config->prompts = 1;
ephoto->config->drop = 0; ephoto->config->drop = 0;
ephoto->config->movess = 1; ephoto->config->movess = 1;

View File

@ -473,7 +473,7 @@ _dir_go_trash(void *data, Evas_Object *obj EINA_UNUSED,
eina_stringshare_replace(&db->back_directory, eina_stringshare_replace(&db->back_directory,
db->ephoto->config->directory); db->ephoto->config->directory);
snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(path)) if (!ecore_file_exists(path))
ecore_file_mkpath(path); ecore_file_mkpath(path);
db->thumbs_only = 0; db->thumbs_only = 0;
@ -607,7 +607,7 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
if (info->button != 3) if (info->button != 3)
return; return;
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (item) if (item)
elm_genlist_item_selected_set(item, EINA_TRUE); elm_genlist_item_selected_set(item, EINA_TRUE);

View File

@ -728,7 +728,7 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
const char *file; const char *file;
char destination[PATH_MAX]; char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(destination)) if (!ecore_file_exists(destination))
ecore_file_mkpath(destination); ecore_file_mkpath(destination);
@ -743,11 +743,10 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX]; char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret; int ret;
struct stat s; struct stat s;
#ifdef _WIN32 #ifdef _WIN32
if (stat(file, &s)) if (stat(file, &s) == 0)
#else #else
if (lstat(file, &s)) if (lstat(file, &s) == 0)
#endif #endif
{ {
if (S_ISLNK(s.st_mode)) if (S_ISLNK(s.st_mode))
@ -808,7 +807,7 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
const char *dir = eina_list_data_get(ephoto->file_pos); const char *dir = eina_list_data_get(ephoto->file_pos);
char destination[PATH_MAX]; char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(destination)) if (!ecore_file_exists(destination))
ecore_file_mkpath(destination); ecore_file_mkpath(destination);
@ -868,7 +867,7 @@ _empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED)
const char *file; const char *file;
char trash[PATH_MAX]; char trash[PATH_MAX];
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ephoto->file_pos) if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0); ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);

View File

@ -18,42 +18,20 @@ int
e_ipc_init(void) e_ipc_init(void)
{ {
char buf[4096], buf3[4096]; char buf[4096], buf3[4096];
const char *tmp, *user, *base; const char *tmp, *user, *base = NULL;
int pid, trynum = 0, id1 = 0; int pid, trynum = 0, id1 = 0;
tmp = eina_environment_tmp_get(); tmp = eina_environment_tmp_get();
if (!tmp) tmp = "/tmp";
base = tmp;
tmp = getenv("XDG_RUNTIME_DIR");
if (tmp)
{
if (ecore_file_exists(tmp))
{
if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp)) if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
base = tmp; base = tmp;
else else
ERR("XDG_RUNTIME_DIR of '%s' failed permissions check", tmp); ERR("Temp dir could not be accessed");
}
else
ERR("XDG_RUNTIME_DIR of '%s' cannot be accessed", tmp);
}
tmp = getenv("SD_USER_SOCKETS_DIR");
if (tmp)
{
if (ecore_file_exists(tmp))
{
if (ecore_file_is_dir(tmp) && ecore_file_can_write(tmp))
base = tmp;
else
ERR("SD_USER_SOCKETS_DIR of '%s' failed permissions check", tmp);
}
else
ERR("SD_USER_SOCKETS_DIR of '%s' cannot be accessed", tmp);
}
#ifdef _WIN32
user = getenv("USERNAME");
#else
user = getenv("USER"); user = getenv("USER");
#endif
setenv("EPHOTO_IPC_SOCKET", "", 1); setenv("EPHOTO_IPC_SOCKET", "", 1);

View File

@ -561,7 +561,7 @@ ephoto_window_add(const char *path)
if (getcwd(buf, sizeof(buf))) if (getcwd(buf, sizeof(buf)))
path = buf; path = buf;
else else
path = getenv("HOME"); path = eina_environment_home_get();
} }
} }

View File

@ -195,7 +195,7 @@ ephoto_scale_add(Ephoto *ephoto, Evas_Object *main, Evas_Object *parent,
es->parent = parent; es->parent = parent;
es->image = image; es->image = image;
snprintf(buf, PATH_MAX, "%s/.config/ephoto/temp.%s", getenv("HOME"), snprintf(buf, PATH_MAX, "%s/.config/ephoto/temp.%s", eina_environment_home_get(),
strrchr(file, '.')+1); strrchr(file, '.')+1);
es->tmp_file = eina_stringshare_add(buf); es->tmp_file = eina_stringshare_add(buf);
if (ecore_file_exists(es->tmp_file)) if (ecore_file_exists(es->tmp_file))

View File

@ -2084,7 +2084,7 @@ _ephoto_main_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
if (sb->edit_main) if (sb->edit_main)
evas_object_del(sb->edit_main); evas_object_del(sb->edit_main);
sb->edit_main = NULL; sb->edit_main = NULL;
snprintf(tmp_path, PATH_MAX, "%s/.config/ephoto/", getenv("HOME")); snprintf(tmp_path, PATH_MAX, "%s/.config/ephoto/", eina_environment_home_get());
tmps = eina_file_stat_ls(tmp_path); tmps = eina_file_stat_ls(tmp_path);
EINA_ITERATOR_FOREACH(tmps, info) EINA_ITERATOR_FOREACH(tmps, info)
{ {

View File

@ -945,7 +945,7 @@ _grid_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
return; return;
} }
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (item) if (item)
{ {
@ -1724,7 +1724,7 @@ _ephoto_main_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
char *trash; char *trash;
snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", snprintf(path, PATH_MAX, "%s/.config/ephoto/trash",
getenv("HOME")); eina_environment_home_get());
trash = strdup(path); trash = strdup(path);
if ((strlen(trash)) == (strlen(tb->ephoto->config->directory))) if ((strlen(trash)) == (strlen(tb->ephoto->config->directory)))
{ {