forked from enlightenment/efl
efreet: opendir -> eina_file_direct_ls
SVN revision: 67308
This commit is contained in:
parent
46a8cf1c4c
commit
820722a779
|
@ -5,7 +5,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include <Eina.h>
|
#include <Eina.h>
|
||||||
#include <Eet.h>
|
#include <Eet.h>
|
||||||
|
@ -130,29 +129,30 @@ cache_scan(const char *path, const char *base_id, int priority, int recurse, int
|
||||||
char *file_id = NULL;
|
char *file_id = NULL;
|
||||||
char id[PATH_MAX];
|
char id[PATH_MAX];
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
DIR *files;
|
Eina_Iterator *it;
|
||||||
struct dirent *ent;
|
Eina_File_Direct_Info *info;
|
||||||
|
|
||||||
if (!ecore_file_is_dir(path)) return 1;
|
if (!ecore_file_is_dir(path)) return 1;
|
||||||
|
|
||||||
files = opendir(path);
|
it = eina_file_direct_ls(path);
|
||||||
if (!files) return 1;
|
if (!it) return 1;
|
||||||
id[0] = '\0';
|
|
||||||
while ((ent = readdir(files)))
|
|
||||||
{
|
|
||||||
if (!ent) break;
|
|
||||||
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue;
|
|
||||||
|
|
||||||
|
id[0] = '\0';
|
||||||
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
|
{
|
||||||
|
const char *fname;
|
||||||
|
|
||||||
|
fname = info->path + info->name_start;
|
||||||
if (base_id)
|
if (base_id)
|
||||||
{
|
{
|
||||||
if (*base_id)
|
if (*base_id)
|
||||||
snprintf(id, sizeof(id), "%s-%s", base_id, ent->d_name);
|
snprintf(id, sizeof(id), "%s-%s", base_id, fname);
|
||||||
else
|
else
|
||||||
strcpy(id, ent->d_name);
|
strcpy(id, fname);
|
||||||
file_id = id;
|
file_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", path, ent->d_name);
|
snprintf(buf, sizeof(buf), "%s/%s", path, fname);
|
||||||
if (ecore_file_is_dir(buf))
|
if (ecore_file_is_dir(buf))
|
||||||
{
|
{
|
||||||
if (recurse)
|
if (recurse)
|
||||||
|
@ -162,12 +162,12 @@ cache_scan(const char *path, const char *base_id, int priority, int recurse, int
|
||||||
{
|
{
|
||||||
if (!cache_add(buf, file_id, priority, changed))
|
if (!cache_add(buf, file_id, priority, changed))
|
||||||
{
|
{
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,6 @@ extern "C"
|
||||||
void *alloca (size_t);
|
void *alloca (size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_EVIL
|
#ifdef HAVE_EVIL
|
||||||
# include <Evil.h>
|
# include <Evil.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1005,23 +1003,18 @@ efreet_desktop_changes_listen(void)
|
||||||
static void
|
static void
|
||||||
efreet_desktop_changes_listen_recursive(const char *path)
|
efreet_desktop_changes_listen_recursive(const char *path)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX];
|
Eina_Iterator *it;
|
||||||
DIR *files;
|
Eina_File_Direct_Info *info;
|
||||||
struct dirent *file;
|
|
||||||
|
|
||||||
efreet_desktop_changes_monitor_add(path);
|
efreet_desktop_changes_monitor_add(path);
|
||||||
|
|
||||||
files = opendir(path);
|
it = eina_file_direct_ls(path);
|
||||||
if (!files) return;
|
if (!it) return;
|
||||||
while ((file = readdir(files)))
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
{
|
{
|
||||||
if (!file) break;
|
if (ecore_file_is_dir(info->path)) efreet_desktop_changes_listen_recursive(info->path);
|
||||||
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", path, file->d_name);
|
|
||||||
if (ecore_file_is_dir(buf)) efreet_desktop_changes_listen_recursive(buf);
|
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -20,8 +20,6 @@ extern "C"
|
||||||
void *alloca (size_t);
|
void *alloca (size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include <Ecore_File.h>
|
#include <Ecore_File.h>
|
||||||
|
|
||||||
/* define macros and variable for using the eina logging system */
|
/* define macros and variable for using the eina logging system */
|
||||||
|
@ -1611,9 +1609,8 @@ efreet_menu_handle_merge_dir(Efreet_Menu_Internal *parent, Efreet_Xml *xml)
|
||||||
static int
|
static int
|
||||||
efreet_menu_merge_dir(Efreet_Menu_Internal *parent, Efreet_Xml *xml, const char *path)
|
efreet_menu_merge_dir(Efreet_Menu_Internal *parent, Efreet_Xml *xml, const char *path)
|
||||||
{
|
{
|
||||||
char dir_path[PATH_MAX];
|
Eina_Iterator *it;
|
||||||
DIR *files;
|
Eina_File_Direct_Info *info;
|
||||||
struct dirent *file;
|
|
||||||
|
|
||||||
if (!parent || !xml || !path) return 0;
|
if (!parent || !xml || !path) return 0;
|
||||||
|
|
||||||
|
@ -1621,26 +1618,24 @@ efreet_menu_merge_dir(Efreet_Menu_Internal *parent, Efreet_Xml *xml, const char
|
||||||
if (eina_hash_find(efreet_merged_dirs, path)) return 1;
|
if (eina_hash_find(efreet_merged_dirs, path)) return 1;
|
||||||
eina_hash_add(efreet_merged_dirs, path, (void *)1);
|
eina_hash_add(efreet_merged_dirs, path, (void *)1);
|
||||||
|
|
||||||
files = opendir(path);
|
it = eina_file_direct_ls(path);
|
||||||
if (!files) return 1;
|
if (!it) return 1;
|
||||||
|
|
||||||
while ((file = readdir(files)))
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
|
p = strrchr(info->path + info->name_length, '.');
|
||||||
p = strrchr(file->d_name, '.');
|
|
||||||
if (!p) continue;
|
if (!p) continue;
|
||||||
if (strcmp(p, ".menu")) continue;
|
if (strcmp(p, ".menu")) continue;
|
||||||
|
|
||||||
snprintf(dir_path, sizeof(dir_path), "%s/%s", path, file->d_name);
|
if (!efreet_menu_merge(parent, xml, info->path))
|
||||||
if (!efreet_menu_merge(parent, xml, dir_path))
|
|
||||||
{
|
{
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1748,13 +1743,11 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root,
|
||||||
const char *prefix)
|
const char *prefix)
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
char file_path[PATH_MAX];
|
|
||||||
Efreet_Menu_Internal *legacy_internal;
|
Efreet_Menu_Internal *legacy_internal;
|
||||||
Efreet_Menu_Filter *filter;
|
Efreet_Menu_Filter *filter;
|
||||||
Efreet_Menu_App_Dir *app_dir;
|
Efreet_Menu_App_Dir *app_dir;
|
||||||
int path_len, count = 0;
|
int count = 0;
|
||||||
DIR *files;
|
Eina_Iterator *it;
|
||||||
struct dirent *file;
|
|
||||||
|
|
||||||
if (!parent || !legacy_dir) return 0;
|
if (!parent || !legacy_dir) return 0;
|
||||||
|
|
||||||
|
@ -1811,34 +1804,31 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root,
|
||||||
efreet_menu_create_filter_list(legacy_internal);
|
efreet_menu_create_filter_list(legacy_internal);
|
||||||
legacy_internal->filters = eina_list_append(legacy_internal->filters, filter);
|
legacy_internal->filters = eina_list_append(legacy_internal->filters, filter);
|
||||||
|
|
||||||
path_len = strlen(path);
|
it = eina_file_direct_ls(path);
|
||||||
files = opendir(path);
|
if (it)
|
||||||
if (files)
|
|
||||||
{
|
{
|
||||||
while ((file = readdir(files)))
|
Eina_File_Direct_Info *info;
|
||||||
|
|
||||||
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
{
|
{
|
||||||
Efreet_Desktop *desktop = NULL;
|
Efreet_Desktop *desktop = NULL;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
char *exten;
|
char *exten;
|
||||||
|
const char *fname;
|
||||||
|
|
||||||
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
|
fname = info->path + info->name_length;
|
||||||
file_path[0] = '\0';
|
|
||||||
eina_strlcpy(file_path, path, PATH_MAX);
|
|
||||||
eina_strlcpy(file_path + path_len, "/", PATH_MAX - path_len);
|
|
||||||
eina_strlcpy(file_path + path_len + 1, file->d_name, PATH_MAX - path_len - 1);
|
|
||||||
|
|
||||||
/* recurse into sub directories */
|
/* recurse into sub directories */
|
||||||
if (ecore_file_is_dir(file_path))
|
if (ecore_file_is_dir(info->path))
|
||||||
{
|
{
|
||||||
Efreet_Menu_Internal *ret;
|
Efreet_Menu_Internal *ret;
|
||||||
|
|
||||||
ret = efreet_menu_handle_legacy_dir_helper(root ? root : legacy_internal,
|
ret = efreet_menu_handle_legacy_dir_helper(root ? root : legacy_internal,
|
||||||
legacy_internal, file_path, prefix);
|
legacy_internal, info->path, prefix);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
efreet_menu_internal_free(legacy_internal);
|
efreet_menu_internal_free(legacy_internal);
|
||||||
eina_stringshare_del(path);
|
eina_stringshare_del(path);
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1848,9 +1838,9 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(file->d_name, ".directory"))
|
if (!strcmp(fname, ".directory"))
|
||||||
{
|
{
|
||||||
legacy_internal->directory = efreet_desktop_get(file_path);
|
legacy_internal->directory = efreet_desktop_get(info->path);
|
||||||
if (legacy_internal->directory
|
if (legacy_internal->directory
|
||||||
&& legacy_internal->directory->type != EFREET_DESKTOP_TYPE_DIRECTORY)
|
&& legacy_internal->directory->type != EFREET_DESKTOP_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
|
@ -1860,10 +1850,10 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
exten = strrchr(file->d_name, '.');
|
exten = strrchr(fname, '.');
|
||||||
|
|
||||||
if (exten && !strcmp(exten, ".desktop"))
|
if (exten && !strcmp(exten, ".desktop"))
|
||||||
desktop = efreet_desktop_get(file_path);
|
desktop = efreet_desktop_get(info->path);
|
||||||
|
|
||||||
if (!desktop) continue;
|
if (!desktop) continue;
|
||||||
|
|
||||||
|
@ -1879,16 +1869,16 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root,
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "%s%s", prefix, file->d_name);
|
snprintf(buf, sizeof(buf), "%s%s", prefix, fname);
|
||||||
filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(buf));
|
filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(buf));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(file->d_name));
|
filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(fname));
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
efreet_desktop_free(desktop);
|
efreet_desktop_free(desktop);
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_stringshare_del(path);
|
eina_stringshare_del(path);
|
||||||
|
@ -3295,34 +3285,36 @@ efreet_menu_app_dir_scan(Efreet_Menu_Internal *internal, const char *path, const
|
||||||
{
|
{
|
||||||
Efreet_Desktop *desktop;
|
Efreet_Desktop *desktop;
|
||||||
Efreet_Menu_Desktop *menu_desktop;
|
Efreet_Menu_Desktop *menu_desktop;
|
||||||
DIR *files;
|
char buf2[PATH_MAX];
|
||||||
char buf[PATH_MAX], buf2[PATH_MAX];
|
Eina_Iterator *it;
|
||||||
struct dirent *file;
|
Eina_File_Direct_Info *info;
|
||||||
char *ext;
|
|
||||||
|
|
||||||
files = opendir(path);
|
it = eina_file_direct_ls(path);
|
||||||
if (!files) return 1;
|
if (!it) return 1;
|
||||||
|
|
||||||
while ((file = readdir(files)))
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
{
|
{
|
||||||
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
|
const char *fname;
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", path, file->d_name);
|
|
||||||
if (id)
|
|
||||||
snprintf(buf2, sizeof(buf2), "%s-%s", id, file->d_name);
|
|
||||||
else
|
|
||||||
strcpy(buf2, file->d_name);
|
|
||||||
|
|
||||||
if (ecore_file_is_dir(buf))
|
fname = info->path + info->name_length;
|
||||||
|
if (id)
|
||||||
|
snprintf(buf2, sizeof(buf2), "%s-%s", id, fname);
|
||||||
|
else
|
||||||
|
strcpy(buf2, fname);
|
||||||
|
|
||||||
|
if (ecore_file_is_dir(info->path))
|
||||||
{
|
{
|
||||||
if (!legacy)
|
if (!legacy)
|
||||||
efreet_menu_app_dir_scan(internal, buf, buf2, legacy);
|
efreet_menu_app_dir_scan(internal, info->path, buf2, legacy);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ext = strrchr(buf, '.');
|
const char *ext;
|
||||||
|
|
||||||
|
ext = strrchr(fname, '.');
|
||||||
|
|
||||||
if (!ext || strcmp(ext, ".desktop")) continue;
|
if (!ext || strcmp(ext, ".desktop")) continue;
|
||||||
desktop = efreet_desktop_get(buf);
|
desktop = efreet_desktop_get(info->path);
|
||||||
|
|
||||||
if (!desktop || desktop->type != EFREET_DESKTOP_TYPE_APPLICATION)
|
if (!desktop || desktop->type != EFREET_DESKTOP_TYPE_APPLICATION)
|
||||||
{
|
{
|
||||||
|
@ -3344,7 +3336,7 @@ efreet_menu_app_dir_scan(Efreet_Menu_Internal *internal, const char *path, const
|
||||||
internal->app_pool = eina_list_prepend(internal->app_pool, menu_desktop);
|
internal->app_pool = eina_list_prepend(internal->app_pool, menu_desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -3400,32 +3392,33 @@ efreet_menu_directory_dir_scan(const char *path, const char *relative_path,
|
||||||
Eina_Hash *cache)
|
Eina_Hash *cache)
|
||||||
{
|
{
|
||||||
Efreet_Desktop *desktop;
|
Efreet_Desktop *desktop;
|
||||||
DIR *files;
|
char buf2[PATH_MAX];
|
||||||
char buf[PATH_MAX], buf2[PATH_MAX];
|
Eina_Iterator *it;
|
||||||
struct dirent *file;
|
Eina_File_Direct_Info *info;
|
||||||
char *ext;
|
char *ext;
|
||||||
|
|
||||||
files = opendir(path);
|
it = eina_file_direct_ls(path);
|
||||||
if (!files) return 1;
|
if (!it) return 1;
|
||||||
|
|
||||||
while ((file = readdir(files)))
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
{
|
{
|
||||||
if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue;
|
const char *fname;
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", path, file->d_name);
|
|
||||||
if (relative_path)
|
|
||||||
snprintf(buf2, sizeof(buf2), "%s/%s", relative_path, file->d_name);
|
|
||||||
else
|
|
||||||
strcpy(buf2, file->d_name);
|
|
||||||
|
|
||||||
if (ecore_file_is_dir(buf))
|
fname = info->path + info->name_length;
|
||||||
efreet_menu_directory_dir_scan(buf, buf2, cache);
|
if (relative_path)
|
||||||
|
snprintf(buf2, sizeof(buf2), "%s/%s", relative_path, fname);
|
||||||
|
else
|
||||||
|
strcpy(buf2, fname);
|
||||||
|
|
||||||
|
if (ecore_file_is_dir(info->path))
|
||||||
|
efreet_menu_directory_dir_scan(info->path, buf2, cache);
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ext = strrchr(buf, '.');
|
ext = strrchr(fname, '.');
|
||||||
if (!ext || strcmp(ext, ".directory")) continue;
|
if (!ext || strcmp(ext, ".directory")) continue;
|
||||||
|
|
||||||
desktop = efreet_desktop_get(buf);
|
desktop = efreet_desktop_get(info->path);
|
||||||
if (!desktop || desktop->type != EFREET_DESKTOP_TYPE_DIRECTORY)
|
if (!desktop || desktop->type != EFREET_DESKTOP_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
efreet_desktop_free(desktop);
|
efreet_desktop_free(desktop);
|
||||||
|
@ -3436,7 +3429,7 @@ efreet_menu_directory_dir_scan(const char *path, const char *relative_path,
|
||||||
eina_hash_add(cache, buf2, desktop);
|
eina_hash_add(cache, buf2, desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ void *alloca (size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include <Ecore_File.h>
|
#include <Ecore_File.h>
|
||||||
|
|
||||||
|
@ -344,25 +343,25 @@ efreet_util_menus_find(void)
|
||||||
static Eina_List *
|
static Eina_List *
|
||||||
efreet_util_menus_find_helper(Eina_List *menus, const char *config_dir)
|
efreet_util_menus_find_helper(Eina_List *menus, const char *config_dir)
|
||||||
{
|
{
|
||||||
DIR *files = NULL;
|
Eina_Iterator *it;
|
||||||
struct dirent *file = NULL;
|
Eina_File_Direct_Info *info;
|
||||||
char dbuf[PATH_MAX], fbuf[PATH_MAX];
|
char dbuf[PATH_MAX];
|
||||||
|
|
||||||
snprintf(dbuf, sizeof(dbuf), "%s/menus", config_dir);
|
snprintf(dbuf, sizeof(dbuf), "%s/menus", config_dir);
|
||||||
files = opendir(dbuf);
|
it = eina_file_direct_ls(dbuf);
|
||||||
if (!files) return menus;
|
if (!it) return menus;
|
||||||
while ((file = readdir(files))) {
|
EINA_ITERATOR_FOREACH(it, info)
|
||||||
|
{
|
||||||
const char *exten;
|
const char *exten;
|
||||||
exten = strrchr(file->d_name, '.');
|
exten = strrchr(info->path + info->name_length, '.');
|
||||||
if (!exten) continue;
|
if (!exten) continue;
|
||||||
if (strcmp(".menu", exten)) continue;
|
if (strcmp(".menu", exten)) continue;
|
||||||
|
|
||||||
snprintf(fbuf, sizeof(fbuf), "%s/%s", dbuf, file->d_name);
|
if (ecore_file_is_dir(info->path)) continue;
|
||||||
if (ecore_file_is_dir(fbuf)) continue;
|
|
||||||
|
|
||||||
menus = eina_list_append(menus, strdup(fbuf));
|
menus = eina_list_append(menus, strdup(info->path));
|
||||||
}
|
}
|
||||||
closedir(files);
|
eina_iterator_free(it);
|
||||||
return menus;
|
return menus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue