Minor optimization of chown/chmod/chattr operations.

(try_chmod): create filename when required.
(try_chown): likewise.
(try_advanced_chown): likewise.
(try_chattr): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-03-17 19:50:19 +03:00
parent 6329771fc0
commit 50f4717f45
4 changed files with 21 additions and 13 deletions

View File

@ -847,9 +847,7 @@ static gboolean
try_advanced_chown (const vfs_path_t * p, mode_t m, uid_t u, gid_t g)
{
int chmod_result;
const char *fname;
fname = x_basename (vfs_path_as_str (p));
const char *fname = NULL;
while ((chmod_result = mc_chmod (p, m)) == -1 && !ignore_all)
{
@ -857,6 +855,8 @@ try_advanced_chown (const vfs_path_t * p, mode_t m, uid_t u, gid_t g)
int result;
char *msg;
if (fname == NULL)
fname = x_basename (vfs_path_as_str (p));
msg = g_strdup_printf (_("Cannot chmod \"%s\"\n%s"), fname, unix_error_string (my_errno));
result =
query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),
@ -892,6 +892,8 @@ try_advanced_chown (const vfs_path_t * p, mode_t m, uid_t u, gid_t g)
int result;
char *msg;
if (fname == NULL)
fname = x_basename (vfs_path_as_str (p));
msg = g_strdup_printf (_("Cannot chown \"%s\"\n%s"), fname, unix_error_string (my_errno));
result =
query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),

View File

@ -5,7 +5,7 @@
Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2020-2022
Andrew Borodin <aborodin@vmail.ru>, 2020-2023
This file is part of the Midnight Commander.
@ -1109,15 +1109,17 @@ next_file (const WPanel * panel)
static gboolean
try_chattr (const char *p, unsigned long m)
{
const char *fname = NULL;
while (fsetflags (p, m) == -1 && !ignore_all)
{
int my_errno = errno;
int result;
char *msg;
msg =
g_strdup_printf (_("Cannot chattr \"%s\"\n%s"), x_basename (p),
unix_error_string (my_errno));
if (fname == NULL)
fname = x_basename (vfs_path_as_str (p));
msg = g_strdup_printf (_("Cannot chattr \"%s\"\n%s"), fname, unix_error_string (my_errno));
result =
query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),
_("&Cancel"));

View File

@ -426,15 +426,17 @@ next_file (const WPanel * panel)
static gboolean
try_chmod (const vfs_path_t * p, mode_t m)
{
const char *fname = NULL;
while (mc_chmod (p, m) == -1 && !ignore_all)
{
int my_errno = errno;
int result;
char *msg;
msg =
g_strdup_printf (_("Cannot chmod \"%s\"\n%s"), x_basename (vfs_path_as_str (p)),
unix_error_string (my_errno));
if (fname == NULL)
fname = x_basename (vfs_path_as_str (p));
msg = g_strdup_printf (_("Cannot chmod \"%s\"\n%s"), fname, unix_error_string (my_errno));
result =
query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),
_("&Cancel"));

View File

@ -298,15 +298,17 @@ next_file (const WPanel * panel)
static gboolean
try_chown (const vfs_path_t * p, uid_t u, gid_t g)
{
const char *fname = NULL;
while (mc_chown (p, u, g) == -1 && !ignore_all)
{
int my_errno = errno;
int result;
char *msg;
msg =
g_strdup_printf (_("Cannot chown \"%s\"\n%s"), x_basename (vfs_path_as_str (p)),
unix_error_string (my_errno));
if (fname == NULL)
fname = x_basename (vfs_path_as_str (p));
msg = g_strdup_printf (_("Cannot chown \"%s\"\n%s"), fname, unix_error_string (my_errno));
result =
query_dialog (MSG_ERROR, msg, D_ERROR, 4, _("&Ignore"), _("Ignore &all"), _("&Retry"),
_("&Cancel"));