(do_load_dir): use vfs_path_t as a path handle.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-04-19 13:19:47 +04:00 committed by Slava Zanko
parent bf65b9b691
commit 1c05ebf8b9
4 changed files with 16 additions and 26 deletions

View File

@ -533,7 +533,7 @@ handle_path (dir_list * list, const char *path,
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
int 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) gboolean lc_case_sensitive, gboolean exec_ff, const char *fltr)
{ {
DIR *dirp; 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 status, link_to_dir, stale_link;
int next_free = 0; int next_free = 0;
struct stat st; struct stat st;
vfs_path_t *vpath;
/* ".." (if any) must be the first entry in the list */ /* ".." (if any) must be the first entry in the list */
if (!set_zero_dir (list)) if (!set_zero_dir (list))
return next_free; return next_free;
vpath = vfs_path_from_str (path);
if (get_dotdot_dir_stat (vpath, &st)) if (get_dotdot_dir_stat (vpath, &st))
list->list[next_free].st = st; list->list[next_free].st = st;
next_free++; next_free++;
@ -556,7 +554,7 @@ do_load_dir (const char *path, dir_list * list, sortfn * sort, gboolean lc_rever
if (dirp == NULL) if (dirp == NULL)
{ {
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents")); message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
goto ret; return next_free;
} }
tree_store_start_check (vpath); 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')) if ((path[0] == PATH_SEP) && (path[1] == '\0'))
next_free--; 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); status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link);
if (status == 0) if (status == 0)
continue; continue;
if (status == -1) if (status == -1)
{
tree_store_end_check ();
mc_closedir (dirp);
goto ret; goto ret;
}
list->list[next_free].fnamelen = NLENGTH (dp); 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].fname = g_strndup (dp->d_name, list->list[next_free].fnamelen);
list->list[next_free].f.marked = 0; 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) if (next_free != 0)
do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff); do_sort (list, sort, next_free - 1, lc_reverse, lc_case_sensitive, exec_ff);
ret:
mc_closedir (dirp); mc_closedir (dirp);
tree_store_end_check (); tree_store_end_check ();
ret:
vfs_path_free (vpath);
return next_free; return next_free;
} }

View File

@ -32,7 +32,7 @@ typedef struct
/*** declarations of public functions ************************************************************/ /*** 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); gboolean case_sensitive, gboolean exec_ff, const char *fltr);
void do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse, void do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff); gboolean case_sensitive, gboolean exec_ff);

View File

@ -3047,17 +3047,19 @@ _do_panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_
/* Reload current panel */ /* Reload current panel */
panel_clean_dir (panel); panel_clean_dir (panel);
{ {
char *tmp_path; char *tmp_path;
tmp_path = vfs_path_to_str (panel->cwd_vpath);
panel->count = 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.reverse, panel->sort_info.case_sensitive,
panel->sort_info.exec_first, panel->filter); 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)); try_to_select (panel, get_parent_dir_name (tmp_path, olddir));
g_free (tmp_path); g_free (tmp_path);
} }
load_hint (0); load_hint (0);
panel->dirty = 1; panel->dirty = 1;
update_xterm_title_path (); update_xterm_title_path ();
@ -4133,16 +4135,10 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
} }
/* Load the default format */ /* Load the default format */
{ panel->count =
char *tmp_path; do_load_dir (panel->cwd_vpath, &panel->dir, panel->sort_info.sort_field->sort_routine,
panel->sort_info.reverse, panel->sort_info.case_sensitive,
tmp_path = vfs_path_to_str (panel->cwd_vpath); panel->sort_info.exec_first, panel->filter);
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);
}
/* Restore old right path */ /* Restore old right path */
if (curdir != NULL) if (curdir != NULL)

View File

@ -136,10 +136,10 @@ get_panel_widget (int idx)
int 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) gboolean case_sensitive, gboolean exec_ff, const char *fltr)
{ {
(void) path; (void) vpath;
(void) list; (void) list;
(void) sort; (void) sort;
(void) reverse; (void) reverse;