From 1c05ebf8b956f36182606e6d8ad9b96fe6add02c Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 19 Apr 2012 13:19:47 +0400 Subject: [PATCH] (do_load_dir): use vfs_path_t as a path handle. Signed-off-by: Andrew Borodin --- src/filemanager/dir.c | 16 +++++----------- src/filemanager/dir.h | 2 +- src/filemanager/panel.c | 20 ++++++++------------ tests/src/filemanager/do_panel_cd_stub_env.c | 4 ++-- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 34ac15755..9e0b511d4 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -533,7 +533,7 @@ handle_path (dir_list * list, const char *path, /* --------------------------------------------------------------------------------------------- */ int -do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_reverse, +do_load_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, gboolean lc_reverse, gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr) { DIR *dirp; @@ -541,13 +541,11 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever int status, link_to_dir, stale_link; int next_free = 0; struct stat st; - vfs_path_t *vpath; /* ".." (if any) must be the first entry in the list */ if (!set_zero_dir (list)) return next_free; - vpath = vfs_path_from_str (path); if (get_dotdot_dir_stat (vpath, &st)) list->list[next_free].st = st; next_free++; @@ -556,7 +554,7 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever if (dirp == NULL) { message (D_ERROR, MSG_ERROR, _("Cannot read directory contents")); - goto ret; + return next_free; } tree_store_start_check (vpath); @@ -565,17 +563,14 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever if ((path[0] == PATH_SEP) && (path[1] == '\0')) next_free--; - while ((dp = mc_readdir (dirp))) + while ((dp = mc_readdir (dirp)) != NULL) { status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link); if (status == 0) continue; if (status == -1) - { - tree_store_end_check (); - mc_closedir (dirp); goto ret; - } + list->list[next_free].fnamelen = NLENGTH (dp); list->list[next_free].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen); list->list[next_free].f.marked = 0; @@ -594,10 +589,9 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever if (next_free != 0) do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff); + ret: mc_closedir (dirp); tree_store_end_check (); - ret: - vfs_path_free (vpath); return next_free; } diff --git a/src/filemanager/dir.h b/src/filemanager/dir.h index bddce85c5..bbfac7327 100644 --- a/src/filemanager/dir.h +++ b/src/filemanager/dir.h @@ -32,7 +32,7 @@ typedef struct /*** declarations of public functions ************************************************************/ -int do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean reverse, +int do_load_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr); void do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse, gboolean case_sensitive, gboolean exec_ff); diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index ec779c3b3..fd3f82bcf 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -3047,17 +3047,19 @@ _do_panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_ /* Reload current panel */ panel_clean_dir (panel); + { char *tmp_path; - tmp_path = vfs_path_to_str (panel->cwd_vpath); panel->count = - do_load_dir (tmp_path, &panel->dir, panel->sort_info.sort_field->sort_routine, + do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_info.sort_field->sort_routine, panel->sort_info.reverse, panel->sort_info.case_sensitive, panel->sort_info.exec_first, panel->filter); + tmp_path = vfs_path_to_str (panel->cwd_vpath); try_to_select (panel, get_parent_dir_name (tmp_path, olddir)); g_free (tmp_path); } + load_hint (0); panel->dirty = 1; update_xterm_title_path (); @@ -4133,16 +4135,10 @@ panel_new_with_dir (const char *panel_name, const char *wpath) } /* Load the default format */ - { - char *tmp_path; - - tmp_path = vfs_path_to_str (panel->cwd_vpath); - panel->count = - do_load_dir (tmp_path, &panel->dir, panel->sort_info.sort_field->sort_routine, - panel->sort_info.reverse, panel->sort_info.case_sensitive, - panel->sort_info.exec_first, panel->filter); - g_free (tmp_path); - } + panel->count = + do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_info.sort_field->sort_routine, + panel->sort_info.reverse, panel->sort_info.case_sensitive, + panel->sort_info.exec_first, panel->filter); /* Restore old right path */ if (curdir != NULL) diff --git a/tests/src/filemanager/do_panel_cd_stub_env.c b/tests/src/filemanager/do_panel_cd_stub_env.c index 22fba1543..5591880f9 100644 --- a/tests/src/filemanager/do_panel_cd_stub_env.c +++ b/tests/src/filemanager/do_panel_cd_stub_env.c @@ -136,10 +136,10 @@ get_panel_widget (int idx) int -do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean reverse, +do_load_dir (const vfs_path_t *vpath, dir_list * list, sortfn * sort, gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr) { - (void) path; + (void) vpath; (void) list; (void) sort; (void) reverse;