[nautilus/wip/corey/properties: 32/36] properties: Fix opening gnome-disks for root filesystem




commit d761df22f62c25a01e99823aad568b1ef75395c1
Author: Corey Berla <corey berla me>
Date:   Tue Aug 23 09:52:52 2022 -0700

    properties: Fix opening gnome-disks for root filesystem
    
    With the introduction of nautilus-dbus-launcher, we made it so that
    the current disk is selected in gnome-disks (when opening from the
    properties window) by passing the disk identifier to --block-device.
    This works fine for most mounted volumes, but breaks the ability to
    open gnome-disks for the root filesystem because
    g_file_find_enclosing_mount() doesn't return a mount for the root file
    system (it only returns "user interesting locations").
    
    So, use unix-specific API to handle that case (antoniof's ammendment).
    
    As a 2nd fallback, just open Disks without selecting anything (but if
    this ever happens, it's a bug: we probably shouldn't show the Disks
    section in Properties in that directory).
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2447

 src/nautilus-properties-window.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 67f88ea08..3343fa4eb 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -28,6 +28,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
+#include <gio/gunixmounts.h>
 #include <nautilus-extension.h>
 #include <string.h>
 #include <sys/stat.h>
@@ -2613,12 +2614,37 @@ open_in_disks (NautilusPropertiesWindow *self)
 
     mount = nautilus_file_get_mount (get_original_file (self));
     volume = (mount != NULL) ? g_mount_get_volume (mount) : NULL;
-    device_identifier = g_volume_get_identifier (volume,
-                                                 G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
-    parameters = g_variant_new_parsed ("(objectpath '/org/gnome/DiskUtility', "
-                                       "@aay [], {'options': <{'block-device': <%s>}> })",
-                                       device_identifier);
+    if (volume != NULL)
+    {
+        device_identifier = g_volume_get_identifier (volume,
+                                                     G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+    }
+    else
+    {
+        g_autoptr (GFile) location = NULL;
+        g_autofree gchar *path = NULL;
+        g_autoptr (GUnixMountEntry) mount_entry = NULL;
+
+        location = nautilus_file_get_location (get_original_file (self));
+        path = g_file_get_path (location);
+        mount_entry = (path != NULL) ? g_unix_mount_at (path, NULL) : NULL;
+        if (mount_entry != NULL)
+        {
+            device_identifier = g_strdup (g_unix_mount_get_device_path (mount_entry));
+        }
+    }
+
+    if (device_identifier != NULL)
+    {
+        parameters = g_variant_new_parsed ("(objectpath '/org/gnome/DiskUtility', "
+                                           "@aay [], {'options': <{'block-device': <%s>}> })",
+                                           device_identifier);
+    }
+    else
+    {
+        parameters = g_variant_new_parsed ("(objectpath '/org/gnome/DiskUtility', @aay [], @a{sv} {})");
+    }
 
     nautilus_dbus_launcher_call (launcher,
                                  NAUTILUS_DBUS_LAUNCHER_DISKS,


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