(panel_operate): refactoring: move check of single entry to separate function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2017-03-25 10:38:42 +03:00
parent edd67ef445
commit ead9063880

View File

@ -1238,6 +1238,7 @@ erase_dir_iff_empty (file_op_context_t * ctx, const vfs_path_t * vpath, size_t c
/* }}} */ /* }}} */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/* {{{ Panel operate routines */ /* {{{ Panel operate routines */
/** /**
@ -1246,7 +1247,7 @@ erase_dir_iff_empty (file_op_context_t * ctx, const vfs_path_t * vpath, size_t c
*/ */
static const char * static const char *
panel_get_file (WPanel * panel) panel_get_file (const WPanel * panel)
{ {
if (get_current_type () == view_tree) if (get_current_type () == view_tree)
{ {
@ -1270,6 +1271,55 @@ panel_get_file (WPanel * panel)
return panel->dir.list[panel->selected].fname; return panel->dir.list[panel->selected].fname;
} }
/* --------------------------------------------------------------------------------------------- */
static const char *
check_single_entry (const WPanel * panel, gboolean force_single, struct stat *src_stat)
{
const char *source;
gboolean ok;
if (force_single)
source = selection (panel)->fname;
else
source = panel_get_file (panel);
ok = !DIR_IS_DOTDOT (source);
if (!ok)
message (D_ERROR, MSG_ERROR, _("Cannot operate on \"..\"!"));
else
{
vfs_path_t *source_vpath;
source_vpath = vfs_path_from_str (source);
/* Update stat to get actual info */
ok = mc_lstat (source_vpath, src_stat) == 0;
if (!ok)
{
message (D_ERROR, MSG_ERROR, _("Cannot stat \"%s\"\n%s"),
path_trunc (source, 30), unix_error_string (errno));
/* Directory was changed outside MC. Reload it forced */
if (!panel->is_panelized)
{
panel_update_flags_t flags = UP_RELOAD;
/* don't update panelized panel */
if (get_other_type () == view_listing && other_panel->is_panelized)
flags |= UP_ONLY_CURRENT;
update_panels (flags, UP_KEEPSEL);
}
}
vfs_path_free (source_vpath);
}
return ok ? source : NULL;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* panel_compute_totals: * panel_compute_totals:
@ -2647,47 +2697,9 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl
if (single_entry) if (single_entry)
{ {
gboolean ok; source = check_single_entry (panel, force_single, &src_stat);
if (force_single) if (source == NULL)
source = selection (panel)->fname;
else
source = panel_get_file (panel);
ok = !DIR_IS_DOTDOT (source);
if (!ok)
message (D_ERROR, MSG_ERROR, _("Cannot operate on \"..\"!"));
else
{
vfs_path_t *source_vpath;
source_vpath = vfs_path_from_str (source);
/* Update stat to get actual info */
ok = mc_lstat (source_vpath, &src_stat) == 0;
if (!ok)
{
message (D_ERROR, MSG_ERROR, _("Cannot stat \"%s\"\n%s"),
path_trunc (source, 30), unix_error_string (errno));
/* Directory was changed outside MC. Reload it forced */
if (!panel->is_panelized)
{
panel_update_flags_t flags = UP_RELOAD;
/* don't update panelized panel */
if (get_other_type () == view_listing && other_panel->is_panelized)
flags |= UP_ONLY_CURRENT;
update_panels (flags, UP_KEEPSEL);
}
}
vfs_path_free (source_vpath);
}
if (!ok)
return FALSE; return FALSE;
} }