[gnome-control-center/wip/info-udisks2] info: use UDisks to retrieve disk size



commit 31fb1019fa5a55690871157f0b283dd93bff401e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 23 10:15:29 2017 -0200

    info: use UDisks to retrieve disk size
    
    The current code relies on GLib API and uses the
    available mounts to calculate the available partition
    size. This is because this code assumes that more
    than one OS can be installed in the same drive, and
    wouldn't make sense to show the whole disk size in
    this situation.
    
    That, however, clashes with the general purpose of
    the panel, for it is meant to show general information
    about the user's computer, and it is not reporting
    the full disk size.
    
    Fix that by using the UDisks API to get the real size
    of the full disks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=639376
    
    Slighly modified by Iain Lane <iainl gnome org> to
    port to meson and add udisks2 to CI deps.
    
    Fixes #285.
    Fixes #302.

 .gitlab-ci.yml                                 |   5 +-
 build-aux/ci/Dockerfile.arm64v8.fedora.rawhide |   2 +-
 panels/info/cc-info-overview-panel.c           | 135 +++++++------------------
 panels/info/meson.build                        |   1 +
 4 files changed, 44 insertions(+), 99 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index be9c9b555..09af64afc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -46,7 +46,7 @@ build:
   stage: build
 
   script:
-    - dnf -y install gsound-devel # FIXME: Remove when new images built
+    - dnf -y install libudisks2-devel # FIXME: Remove when new images built
 
     - *environment_information
     - *build_procedure
@@ -78,6 +78,7 @@ test:
 
   script:
     - *environment_information
+    - dnf -y install libudisks2-devel # FIXME: Remove when new images built
 
     - |
       if [[ -n "${CI_COMMIT_TAG}" ]]; then
@@ -263,7 +264,7 @@ stop_review:
   stage: manual
   when: manual
   script:
-    - dnf -y install gsound-devel # FIXME: Remove when new images built
+    - dnf -y install libudisks2-devel # FIXME: Remove when new images built
     - *environment_information
     - *build_procedure
     - *run_tests
diff --git a/build-aux/ci/Dockerfile.arm64v8.fedora.rawhide b/build-aux/ci/Dockerfile.arm64v8.fedora.rawhide
index 5295314be..fdd10848b 100644
--- a/build-aux/ci/Dockerfile.arm64v8.fedora.rawhide
+++ b/build-aux/ci/Dockerfile.arm64v8.fedora.rawhide
@@ -16,7 +16,7 @@ RUN dnf -y --nogpgcheck upgrade && \
                    gnome-online-accounts-devel gnome-settings-daemon-devel grilo-devel \
                    gsettings-desktop-schemas-devel gsound-devel gtk3-devel ibus-devel intltool 
libcanberra-devel \
                    libgtop2-devel libgudev-devel libnma-devel libpwquality-devel libsmbclient-devel \
-                   libsoup-devel libwacom-devel libX11-devel libXi-devel libxml2-devel libxslt \
+                   libsoup-devel libudisks2-devel libwacom-devel libX11-devel libXi-devel libxml2-devel 
libxslt \
                    libXxf86misc-devel meson ModemManager-glib-devel NetworkManager-libnm-devel \
                    polkit-devel pulseaudio-libs-devel upower-devel \
                    python3-dbusmock xorg-x11-server-Xvfb mesa-dri-drivers libsecret-devel && \
diff --git a/panels/info/cc-info-overview-panel.c b/panels/info/cc-info-overview-panel.c
index e2276a295..ff47c1fef 100644
--- a/panels/info/cc-info-overview-panel.c
+++ b/panels/info/cc-info-overview-panel.c
@@ -36,6 +36,7 @@
 #include <glibtop/mountlist.h>
 #include <glibtop/mem.h>
 #include <glibtop/sysinfo.h>
+#include <udisks/udisks.h>
 
 #include <gdk/gdk.h>
 
@@ -81,9 +82,7 @@ typedef struct
 
   GCancellable   *cancellable;
 
-  /* Free space */
-  GList          *primary_mounts;
-  guint64         total_bytes;
+  UDisksClient   *client;
 
   GraphicsData   *graphics_data;
 } CcInfoOverviewPanelPrivate;
@@ -96,8 +95,6 @@ struct _CcInfoOverviewPanel
  CcInfoOverviewPanelPrivate *priv;
 };
 
-static void get_primary_disc_info_start (CcInfoOverviewPanel *self);
-
 typedef struct
 {
   char *major;
@@ -486,111 +483,51 @@ get_os_type (void)
 }
 
 static void
-query_done (GFile               *file,
-            GAsyncResult        *res,
-            CcInfoOverviewPanel *self)
+get_primary_disc_info (CcInfoOverviewPanel *self)
 {
   CcInfoOverviewPanelPrivate *priv;
-  g_autoptr(GFileInfo) info = NULL;
-  g_autoptr(GError) error = NULL;
-
-  info = g_file_query_filesystem_info_finish (file, res, &error);
-  if (info != NULL)
-    {
-      priv = cc_info_overview_panel_get_instance_private (self);
-      priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
-    }
-  else
-    {
-      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-          return;
-      else
-        {
-          g_autofree char *path = NULL;
-          path = g_file_get_path (file);
-          g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message);
-        }
-    }
+  GDBusObjectManager *manager;
+  g_autolist(GDBusObject) objects = NULL;
+  GList *l;
+  guint64 total_size;
 
-  /* And onto the next element */
-  get_primary_disc_info_start (self);
-}
-
-static void
-get_primary_disc_info_start (CcInfoOverviewPanel *self)
-{
-  GUnixMountEntry *mount;
-  g_autoptr(GFile) file = NULL;
-  CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
+  priv = cc_info_overview_panel_get_instance_private (self);
+  total_size = 0;
 
-  if (priv->primary_mounts == NULL)
+  if (!priv->client)
     {
-      g_autofree char *size = NULL;
-
-      size = g_format_size (priv->total_bytes);
-      gtk_label_set_text (GTK_LABEL (priv->disk_label), size);
-
+      gtk_label_set_text (GTK_LABEL (priv->disk_label), _("Unknown"));
       return;
     }
 
-  mount = priv->primary_mounts->data;
-  priv->primary_mounts = g_list_remove (priv->primary_mounts, mount);
-  file = g_file_new_for_path (g_unix_mount_get_mount_path (mount));
-  g_unix_mount_free (mount);
-
-  g_file_query_filesystem_info_async (file,
-                                      G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,
-                                      0,
-                                      priv->cancellable,
-                                      (GAsyncReadyCallback) query_done,
-                                      self);
-}
-
-static void
-get_primary_disc_info (CcInfoOverviewPanel *self)
-{
-  GList *points;
-  GList *p;
-  GHashTable *hash;
-  CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
-
-  hash = g_hash_table_new (g_str_hash, g_str_equal);
-  points = g_unix_mount_points_get (NULL);
-
-  /* If we do not have /etc/fstab around, try /etc/mtab */
-  if (points == NULL)
-    points = g_unix_mounts_get (NULL);
+  manager = udisks_client_get_object_manager (priv->client);
+  objects = g_dbus_object_manager_get_objects (manager);
 
-  for (p = points; p != NULL; p = p->next)
+  for (l = objects; l != NULL; l = l->next)
     {
-      GUnixMountEntry *mount = p->data;
-      const char *mount_path;
-      const char *device_path;
-
-      mount_path = g_unix_mount_get_mount_path (mount);
-      device_path = g_unix_mount_get_device_path (mount);
-
-      /* Do not count multiple mounts with same device_path, because it is
-       * probably something like btrfs subvolume. Use only the first one in
-       * order to count the real size. */
-      if (gsd_should_ignore_unix_mount (mount) ||
-          gsd_is_removable_mount (mount) ||
-          g_str_has_prefix (mount_path, "/media/") ||
-          g_str_has_prefix (mount_path, g_get_home_dir ()) ||
-          g_hash_table_lookup (hash, device_path) != NULL)
+      UDisksDrive *drive;
+      drive = udisks_object_peek_drive (UDISKS_OBJECT (l->data));
+
+      /* Skip removable devices */
+      if (drive == NULL ||
+          udisks_drive_get_removable (drive) ||
+          udisks_drive_get_ejectable (drive))
         {
-          g_unix_mount_free (mount);
           continue;
         }
 
-      priv->primary_mounts = g_list_prepend (priv->primary_mounts, mount);
-      g_hash_table_insert (hash, (gpointer) device_path, (gpointer) device_path);
+      total_size += udisks_drive_get_size (drive);
     }
-  g_list_free (points);
-  g_hash_table_destroy (hash);
 
-  priv->cancellable = g_cancellable_new ();
-  get_primary_disc_info_start (self);
+  if (total_size > 0)
+    {
+      g_autofree gchar *size = g_format_size (total_size);
+      gtk_label_set_text (GTK_LABEL (priv->disk_label), size);
+    }
+  else
+    {
+      gtk_label_set_text (GTK_LABEL (priv->disk_label), _("Unknown"));
+    }
 }
 
 static char *
@@ -852,8 +789,7 @@ cc_info_overview_panel_finalize (GObject *object)
       g_clear_object (&priv->cancellable);
     }
 
-  if (priv->primary_mounts)
-    g_list_free_full (priv->primary_mounts, (GDestroyNotify) g_unix_mount_free);
+  g_clear_object (&priv->client);
 
   g_free (priv->gnome_version);
   g_free (priv->gnome_date);
@@ -895,6 +831,7 @@ static void
 cc_info_overview_panel_init (CcInfoOverviewPanel *self)
 {
   CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
+  g_autoptr(GError) error = NULL;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -907,6 +844,12 @@ cc_info_overview_panel_init (CcInfoOverviewPanel *self)
   else
     gtk_widget_destroy (priv->updates_button);
 
+  priv->client = udisks_client_new_sync (NULL, &error);
+
+  if (error != NULL)
+      g_warning ("Unable to get UDisks client: %s. Disk information will not be available.",
+                 error->message);
+
   info_overview_panel_setup_overview (self);
   info_overview_panel_setup_virt (self);
 }
diff --git a/panels/info/meson.build b/panels/info/meson.build
index 037425513..c54e5fdaf 100644
--- a/panels/info/meson.build
+++ b/panels/info/meson.build
@@ -61,6 +61,7 @@ sources += gnome.compile_resources(
 
 deps = common_deps + [
   polkit_gobject_dep,
+  dependency('udisks2', version: '>= 2.1.8'),
   dependency('libgtop-2.0')
 ]
 


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