[gnome-commander/57-remote-connections-gnome-commander-misreads-file-ownership] If a file does not have a G_FILE_ATTRIBUTE_OWNER attribute, display the UID or GID



commit e87ee33da65d156647ceeb418da6a96a40f1ecb5
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Sun Nov 21 21:32:50 2021 +0100

    If a file does not have a G_FILE_ATTRIBUTE_OWNER attribute, display the UID or GID

 NEWS                             |  1 +
 doc/C/releases.xml               |  3 +++
 src/gnome-cmd-chown-component.cc | 17 +++++++++++++++++
 src/gnome-cmd-file.cc            | 28 ++++++++++++++++++++++++++--
 4 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index 15eb5fee..cbbae189 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Bug fixes:
  * Fixed issue #47 (Duplicate directory when copying over an existing directory)
  * Fixed issue #51 (Move and not copy by default on same filesystem)
  * Fixed issue #52 (Auto refresh when changing permissions etc)
+ * Fixed issue #57 (Remote connections: Gnome Commander misreads file ownership)
  * Fixed issue #74 (Does not show mounted external drives)
  * Fixed issue #75 (Newly inserted DVD does not show up)
 
diff --git a/doc/C/releases.xml b/doc/C/releases.xml
index 4a20045e..61d1a5cc 100644
--- a/doc/C/releases.xml
+++ b/doc/C/releases.xml
@@ -62,6 +62,9 @@
                         <listitem>
                             <para>Fixed issue #52 (Auto refresh when changing permissions etc)</para>
                         </listitem>
+                        <listitem>
+                            <para>Fixed issue #57 (Remote connections: Gnome Commander misreads file 
ownership)</para>
+                        </listitem>
                         <listitem>
                             <para>Fixed issue #74 (Does not show mounted external drives)</para>
                         </listitem>
diff --git a/src/gnome-cmd-chown-component.cc b/src/gnome-cmd-chown-component.cc
index 16cebcfc..41e26f33 100644
--- a/src/gnome-cmd-chown-component.cc
+++ b/src/gnome-cmd-chown-component.cc
@@ -157,9 +157,26 @@ void gnome_cmd_chown_component_set (GnomeCmdChownComponent *comp, uid_t uid, gid
     const gchar *gid_name = gcmd_owner.groups[gid];
 
     if (uid_name)
+    {
         gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->user_combo)->entry), uid_name);
+    }
+    else
+    {
+        auto uidString = g_strdup_printf("%u", uid);
+        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->user_combo)->entry), uidString);
+        g_free(uidString);
+    }
+
     if (gid_name)
+    {
         gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->group_combo)->entry), gid_name);
+    }
+    else
+    {
+        auto gidString = g_strdup_printf("%u", gid);
+        gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (comp->priv->group_combo)->entry), gidString);
+        g_free(gidString);
+    }
 }
 
 
diff --git a/src/gnome-cmd-file.cc b/src/gnome-cmd-file.cc
index d7237285..a9ec582b 100644
--- a/src/gnome-cmd-file.cc
+++ b/src/gnome-cmd-file.cc
@@ -650,7 +650,19 @@ const gchar *GnomeCmdFile::get_owner()
 {
     g_return_val_if_fail (gFileInfo != nullptr, nullptr);
 
-    return g_file_info_get_attribute_string(gFileInfo, G_FILE_ATTRIBUTE_OWNER_USER);
+    const gchar *ownerString = nullptr;
+
+    ownerString = g_file_info_get_attribute_string(gFileInfo, G_FILE_ATTRIBUTE_OWNER_USER);
+
+    if (!ownerString)
+    {
+        static gchar owner_str[MAX_OWNER_LENGTH];
+        g_snprintf (owner_str, MAX_OWNER_LENGTH, "%d",
+            g_file_info_get_attribute_uint32(gFileInfo, G_FILE_ATTRIBUTE_UNIX_UID));
+        return owner_str;
+    }
+
+    return ownerString;
 }
 
 
@@ -658,7 +670,19 @@ const gchar *GnomeCmdFile::get_group()
 {
     g_return_val_if_fail (gFileInfo != nullptr, nullptr);
 
-    return g_file_info_get_attribute_string(gFileInfo, G_FILE_ATTRIBUTE_OWNER_GROUP);
+    const gchar *groupString = nullptr;
+
+    groupString = g_file_info_get_attribute_string(gFileInfo, G_FILE_ATTRIBUTE_OWNER_GROUP);
+
+    if (!groupString)
+    {
+        static gchar owner_str[MAX_OWNER_LENGTH];
+        g_snprintf (owner_str, MAX_OWNER_LENGTH, "%d",
+            g_file_info_get_attribute_uint32(gFileInfo, G_FILE_ATTRIBUTE_UNIX_GID));
+        return owner_str;
+    }
+
+    return groupString;
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]