[gnome-commander] Propagate error when one occurs when changing the owner of a file
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Propagate error when one occurs when changing the owner of a file
- Date: Tue, 22 Jun 2021 21:02:07 +0000 (UTC)
commit 8ced20ff6a9cba9691b618840dafe0102b112dcd
Author: Uwe Scholz <u scholz83 gmx de>
Date: Tue Jun 22 23:01:05 2021 +0200
Propagate error when one occurs when changing the owner of a file
src/dialogs/gnome-cmd-chown-dialog.cc | 2 +-
src/dialogs/gnome-cmd-file-props-dialog.cc | 10 ++++++++--
src/gnome-cmd-file.cc | 30 +++++++++++++++++-------------
src/gnome-cmd-file.h | 2 +-
4 files changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-chown-dialog.cc b/src/dialogs/gnome-cmd-chown-dialog.cc
index 292b4ef6..23074832 100644
--- a/src/dialogs/gnome-cmd-chown-dialog.cc
+++ b/src/dialogs/gnome-cmd-chown-dialog.cc
@@ -49,7 +49,7 @@ static void do_chown (GnomeCmdFile *in, uid_t uid, gid_t gid, gboolean recurse)
g_return_if_fail (in != nullptr);
g_return_if_fail (in->gFileInfo != nullptr);
- if(!in->chown(uid, gid))
+ if(!in->chown(uid, gid, nullptr))
{
return;
}
diff --git a/src/dialogs/gnome-cmd-file-props-dialog.cc b/src/dialogs/gnome-cmd-file-props-dialog.cc
index 479bfcc2..e229b95e 100644
--- a/src/dialogs/gnome-cmd-file-props-dialog.cc
+++ b/src/dialogs/gnome-cmd-file-props-dialog.cc
@@ -187,6 +187,9 @@ static void do_calc_tree_size (GnomeCmdFilePropsDialogPrivate *data)
static void on_dialog_ok (GtkButton *btn, GnomeCmdFilePropsDialogPrivate *data)
{
+ GError *error;
+ error = nullptr;
+
GnomeVFSResult result = GNOME_VFS_OK;
gboolean retValue = true;
@@ -216,13 +219,16 @@ static void on_dialog_ok (GtkButton *btn, GnomeCmdFilePropsDialogPrivate *data)
if ( uid != GetGfileAttributeUInt32(data->f->gFile, G_FILE_ATTRIBUTE_UNIX_UID)
|| gid != GetGfileAttributeUInt32(data->f->gFile, G_FILE_ATTRIBUTE_UNIX_GID))
{
- retValue = data->f->chown(uid,gid);
+ retValue = data->f->chown(uid, gid, &error);
}
}
if (result != GNOME_VFS_OK || !retValue)
{
- gnome_cmd_show_message (nullptr, filename, gnome_vfs_result_to_string (result));
+ if (error != nullptr)
+ gnome_cmd_show_message (nullptr, filename, error->message);
+ else
+ gnome_cmd_show_message (nullptr, filename, gnome_vfs_result_to_string (result));
return;
}
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index 2726ccb5..8ba52618 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -408,30 +408,34 @@ gboolean GnomeCmdFile::chmod(guint32 permissions)
}
-gboolean GnomeCmdFile::chown(uid_t uid, gid_t gid)
+gboolean GnomeCmdFile::chown(uid_t uid, gid_t gid, GError **error)
{
- GError *error;
- error = nullptr;
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ GError *tmp_error;
+ tmp_error = nullptr;
auto gFileInfoMods = g_file_query_info(gFile,
G_FILE_ATTRIBUTE_UNIX_UID "," G_FILE_ATTRIBUTE_UNIX_GID,
G_FILE_QUERY_INFO_NONE,
nullptr,
- &error);
- if (error)
+ &tmp_error);
+ if (tmp_error)
{
- g_message ("chown: retrieving file info failed: %s", error->message);
+ g_message ("chown: retrieving file info failed: %s", tmp_error->message);
gchar *fname = GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
gchar *msg = g_strdup_printf (_("Could not chown %s"), fname);
- gnome_cmd_show_message (*main_win, msg, error->message);
+ gnome_cmd_show_message (*main_win, msg, tmp_error->message);
g_free (msg);
g_free (fname);
- g_error_free (error);
+ g_propagate_error (error, tmp_error);
return false;
}
+ tmp_error = nullptr;
+
if (uid != (uid_t) -1)
{
g_file_info_set_attribute_uint32(gFileInfoMods,
@@ -447,19 +451,19 @@ gboolean GnomeCmdFile::chown(uid_t uid, gid_t gid)
gFileInfoMods,
G_FILE_QUERY_INFO_NONE,
nullptr,
- &error);
- if (error)
+ &tmp_error);
+ if (tmp_error)
{
- g_message ("chmod: setting file mode failed: %s", error->message);
+ g_message ("chmod: setting file mode failed: %s", tmp_error->message);
gchar *fname = GetGfileAttributeString(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
gchar *msg = g_strdup_printf (_("Could not chown %s"), fname);
- gnome_cmd_show_message (*main_win, msg, error->message);
+ gnome_cmd_show_message (*main_win, msg, tmp_error->message);
g_free (msg);
g_free (fname);
g_object_unref(gFileInfoMods);
- g_error_free (error);
+ g_propagate_error (error, tmp_error);
return false;
}
diff --git a/src/gnome-cmd-file.h b/src/gnome-cmd-file.h
index 10aa6c5d..89f8a420 100644
--- a/src/gnome-cmd-file.h
+++ b/src/gnome-cmd-file.h
@@ -91,7 +91,7 @@ struct GnomeCmdFile
gboolean get_type_pixmap_and_mask(GdkPixmap **pixmap, GdkBitmap **mask);
gboolean chmod(guint32 permissions);
- gboolean chown(uid_t uid, gid_t gid);
+ gboolean chown(uid_t uid, gid_t gid, GError **error);
GnomeVFSResult rename(const gchar *new_name);
void update_info(GnomeVFSFileInfo *info);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]