(cd_error_msg): new function to show the change directory error message.

Use it where needed.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-05-09 09:04:44 +03:00
parent 8cc71a7f65
commit f4ac2bb01f
5 changed files with 23 additions and 15 deletions

View File

@ -38,6 +38,7 @@
#include "lib/vfs/vfs.h" #include "lib/vfs/vfs.h"
#include "lib/strescape.h" /* strutils_shell_unescape() */ #include "lib/strescape.h" /* strutils_shell_unescape() */
#include "lib/util.h" /* whitespace() */ #include "lib/util.h" /* whitespace() */
#include "lib/widget.h" /* message() */
#include "filemanager.h" /* current_panel, panel.h, layout.h */ #include "filemanager.h" /* current_panel, panel.h, layout.h */
#include "tree.h" /* sync_tree() */ #include "tree.h" /* sync_tree() */
@ -286,8 +287,7 @@ cd_to (const char *path)
char *d; char *d;
d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD); d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD);
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, cd_error_message (d);
unix_error_string (errno));
g_free (d); g_free (d);
} }
@ -299,3 +299,12 @@ cd_to (const char *path)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void
cd_error_message (const char *path)
{
message (D_ERROR, MSG_ERROR, _("Cannot change directory to\n%s\n%s"), path,
unix_error_string (errno));
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -16,6 +16,7 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void cd_to (const char *path); void cd_to (const char *path);
void cd_error_message (const char *path);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

View File

@ -90,7 +90,7 @@
#include "ext.h" /* regex_command() */ #include "ext.h" /* regex_command() */
#include "boxes.h" /* cd_box() */ #include "boxes.h" /* cd_box() */
#include "dir.h" #include "dir.h"
#include "cd.h" /* cd_to() */ #include "cd.h"
#include "cmd.h" /* Our definitions */ #include "cmd.h" /* Our definitions */
@ -147,7 +147,7 @@ do_view_cmd (WPanel * panel, gboolean plain_view)
fname_vpath = vfs_path_from_str (fe->fname->str); fname_vpath = vfs_path_from_str (fe->fname->str);
if (!panel_cd (panel, fname_vpath, cd_exact)) if (!panel_cd (panel, fname_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory")); cd_error_message (fe->fname->str);
vfs_path_free (fname_vpath, TRUE); vfs_path_free (fname_vpath, TRUE);
} }
else else
@ -446,7 +446,7 @@ nice_cd (const char *text, const char *xtext, const char *help,
cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON); cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
if (!panel_do_cd (MENU_PANEL, cd_vpath, cd_parse_command)) if (!panel_do_cd (MENU_PANEL, cd_vpath, cd_parse_command))
{ {
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); cd_error_message (cd_path);
if (save_type != view_listing) if (save_type != view_listing)
create_panel (MENU_PANEL_IDX, save_type); create_panel (MENU_PANEL_IDX, save_type);
@ -1009,7 +1009,7 @@ vfs_list (WPanel * panel)
target_vpath = vfs_path_from_str (target); target_vpath = vfs_path_from_str (target);
if (!panel_cd (current_panel, target_vpath, cd_exact)) if (!panel_cd (current_panel, target_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory")); cd_error_message (target);
vfs_path_free (target_vpath, TRUE); vfs_path_free (target_vpath, TRUE);
g_free (target); g_free (target);
} }

View File

@ -32,7 +32,6 @@
#include <config.h> #include <config.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -77,6 +76,7 @@
#include "command.h" /* cmdline */ #include "command.h" /* cmdline */
#include "filemanager.h" #include "filemanager.h"
#include "mountlist.h" /* my_statfs */ #include "mountlist.h" /* my_statfs */
#include "cd.h" /* cd_error_message() */
#include "panel.h" #include "panel.h"
@ -2936,7 +2936,7 @@ do_enter_on_file_entry (WPanel * panel, file_entry_t * fe)
fname_vpath = vfs_path_from_str (fname); fname_vpath = vfs_path_from_str (fname);
if (!panel_cd (panel, fname_vpath, cd_exact)) if (!panel_cd (panel, fname_vpath, cd_exact))
message (D_ERROR, MSG_ERROR, _("Cannot change directory")); cd_error_message (fname);
vfs_path_free (fname_vpath, TRUE); vfs_path_free (fname_vpath, TRUE);
return TRUE; return TRUE;
} }
@ -3519,7 +3519,7 @@ directory_history_list (WPanel * panel)
if (ok) if (ok)
directory_history_add (panel, panel->cwd_vpath); directory_history_add (panel, panel->cwd_vpath);
else else
message (D_ERROR, MSG_ERROR, _("Cannot change directory")); cd_error_message (hd.text);
vfs_path_free (s_vpath, TRUE); vfs_path_free (s_vpath, TRUE);
g_free (hd.text); g_free (hd.text);
} }
@ -3814,8 +3814,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
char *cwd; char *cwd;
cwd = vfs_path_to_str_flags (panel->cwd_vpath, 0, VPF_STRIP_PASSWORD); cwd = vfs_path_to_str_flags (panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), cd_error_message (cwd);
cwd, unix_error_string (errno));
g_free (cwd); g_free (cwd);
} }
else else
@ -4971,8 +4970,7 @@ panel_change_encoding (WPanel * panel)
vfs_path_change_encoding (panel->cwd_vpath, encoding); vfs_path_change_encoding (panel->cwd_vpath, encoding);
if (!panel_do_cd (panel, panel->cwd_vpath, cd_parse_command)) if (!panel_do_cd (panel, panel->cwd_vpath, cd_parse_command))
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_error_message (vfs_path_as_str (panel->cwd_vpath));
vfs_path_as_str (panel->cwd_vpath));
} }
} }

View File

@ -66,6 +66,7 @@
#include "treestore.h" #include "treestore.h"
#include "cmd.h" #include "cmd.h"
#include "filegui.h" #include "filegui.h"
#include "cd.h" /* cd_error_message() */
#include "tree.h" #include "tree.h"
@ -593,8 +594,7 @@ tree_chdir_sel (WTree * tree)
if (panel_cd (p, tree->selected_ptr->name, cd_exact)) if (panel_cd (p, tree->selected_ptr->name, cd_exact))
select_item (p); select_item (p);
else else
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), cd_error_message (vfs_path_as_str (tree->selected_ptr->name));
vfs_path_as_str (tree->selected_ptr->name), unix_error_string (errno));
widget_draw (WIDGET (p)); widget_draw (WIDGET (p));
(void) change_panel (); (void) change_panel ();