(dir_list_load): show error message outside of this function.

(dir_list_reload): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2019-08-25 11:55:20 +03:00
parent fcc8639169
commit 8c5737f558
4 changed files with 53 additions and 37 deletions

View File

@ -42,7 +42,6 @@
#include "lib/fs.h"
#include "lib/strutil.h"
#include "lib/util.h"
#include "lib/widget.h" /* message() */
#include "src/setup.h" /* panels_options */
@ -620,7 +619,7 @@ handle_path (const char *path, struct stat * buf1, gboolean * link_to_dir, gbool
/* --------------------------------------------------------------------------------------------- */
void
gboolean
dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr)
{
@ -629,10 +628,11 @@ dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
struct stat st;
file_entry_t *fentry;
const char *vpath_str;
gboolean ret = TRUE;
/* ".." (if any) must be the first entry in the list */
if (!dir_list_init (list))
return;
return FALSE;
fentry = &list->list[0];
if (dir_get_dotdot_stat (vpath, &st))
@ -640,10 +640,7 @@ dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
dirp = mc_opendir (vpath);
if (dirp == NULL)
{
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
return;
}
return FALSE;
tree_store_start_check (vpath);
@ -660,7 +657,10 @@ dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
continue;
if (!dir_list_append (list, dp->d_name, &st, link_to_dir, stale_link))
{
ret = FALSE;
goto ret;
}
if ((list->len & 31) == 0)
rotate_dash (TRUE);
@ -672,6 +672,8 @@ dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
mc_closedir (dirp);
tree_store_end_check ();
rotate_dash (FALSE);
return ret;
}
/* --------------------------------------------------------------------------------------------- */
@ -689,7 +691,7 @@ if_link_is_exe (const vfs_path_t * full_name_vpath, const file_entry_t * file)
/* --------------------------------------------------------------------------------------------- */
/** If fltr is null, then it is a match */
void
gboolean
dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr)
{
@ -704,10 +706,9 @@ dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
dirp = mc_opendir (vpath);
if (dirp == NULL)
{
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
dir_list_clean (list);
dir_list_init (list);
return;
return FALSE;
}
tree_store_start_check (vpath);
@ -753,7 +754,7 @@ dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
if (!dir_list_init (list))
{
dir_list_free_list (&dir_copy);
return;
return FALSE;
}
if (dir_get_dotdot_stat (vpath, &st))
@ -788,7 +789,7 @@ dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
*/
tree_store_end_check ();
g_hash_table_destroy (marked_files);
return;
return FALSE;
}
fentry = &list->list[list->len - 1];
@ -816,6 +817,8 @@ dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
dir_list_free_list (&dir_copy);
rotate_dash (FALSE);
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -48,10 +48,10 @@ gboolean dir_list_grow (dir_list * list, int delta);
gboolean dir_list_append (dir_list * list, const char *fname, const struct stat *st,
gboolean link_to_dir, gboolean stale_link);
void dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr);
void dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr);
gboolean dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr);
gboolean dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const char *fltr);
void dir_list_sort (dir_list * list, GCompareFunc sort, const dir_sort_options_t * sort_op);
gboolean dir_list_init (dir_list * list);
void dir_list_clean (dir_list * list);

View File

@ -3277,8 +3277,10 @@ _do_panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_
/* Reload current panel */
panel_clean_dir (panel);
dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter);
if (!dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter))
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
try_to_select (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath));
load_hint (FALSE);
@ -4364,8 +4366,9 @@ panel_sized_with_dir_new (const char *panel_name, int y, int x, int lines, int c
}
/* Load the default format */
dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter);
if (!dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter))
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
/* Restore old right path */
if (curdir != NULL)
@ -4411,8 +4414,9 @@ panel_reload (WPanel * panel)
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
show_dir (panel);
dir_list_reload (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter);
if (!dir_list_reload (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
&panel->sort_info, panel->filter))
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
panel->dirty = 1;
if (panel->selected >= panel->dir.len)

View File

@ -300,30 +300,39 @@ mcview_load_next_prev_init (WView * view)
/* TODO: check mtime of directory to reload it */
const char *fname;
size_t fname_len;
int i;
dir_sort_options_t sort_op = { FALSE, TRUE, FALSE };
/* load directory where requested file is */
view->dir = g_new0 (dir_list, 1);
view->dir_idx = g_new (int, 1);
dir_list_load (view->dir, view->workdir_vpath, (GCompareFunc) sort_name, &sort_op, NULL);
fname = x_basename (vfs_path_as_str (view->filename_vpath));
fname_len = strlen (fname);
/* search current file in the list */
for (i = 0; i != view->dir->len; i++)
if (dir_list_load
(view->dir, view->workdir_vpath, (GCompareFunc) sort_name, &sort_op, NULL))
{
const file_entry_t *fe = &view->dir->list[i];
const char *fname;
size_t fname_len;
int i;
if (fname_len == fe->fnamelen && strncmp (fname, fe->fname, fname_len) == 0)
break;
fname = x_basename (vfs_path_as_str (view->filename_vpath));
fname_len = strlen (fname);
/* search current file in the list */
for (i = 0; i != view->dir->len; i++)
{
const file_entry_t *fe = &view->dir->list[i];
if (fname_len == fe->fnamelen && strncmp (fname, fe->fname, fname_len) == 0)
break;
}
*view->dir_idx = i;
}
else
{
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
MC_PTR_FREE (view->dir);
MC_PTR_FREE (view->dir_idx);
}
*view->dir_idx = i;
}
}