[gnome-initial-setup/wip/pwithnall/misc-fixes: 39/70] driver: detect whether live media is DVD




commit d35eace769be073785b780ae968d8f688762c813
Author: Will Thompson <wjt endlessm com>
Date:   Wed Aug 23 12:19:25 2017 +0100

    driver: detect whether live media is DVD
    
    This was originally implemented using UDisks and then changed to
    determine the DVD-ness from the image version.
    
    This is not as aesthetically pleasing as using UDisks and will produce
    incorrect results if a non-eosdvd ISO (i.e. base – no others fit) is
    written to DVD or an eosdvd ISO is written to USB.
    
    But the UDisks approach does not actually work: when booted from a DVD,
    for annoying reasons the udev properties indicating the media in the
    drive are missing for the DVD device, so UDisks doesn't believe it to be
    an optical device.
    
    This approach is simpler and easier to test.
    
    (Rebase 3.38: Fix minor rebase conflicts.)
    
    https://phabricator.endlessm.com/T18708

 gnome-initial-setup/gis-driver.c | 51 ++++++++++++++++++++++++++++------------
 1 file changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index f0afe549..c0e50c16 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -62,6 +62,7 @@ static guint signals[LAST_SIGNAL];
 typedef enum {
   PROP_MODE = 1,
   PROP_LIVE_SESSION,
+  PROP_LIVE_DVD,
   PROP_USERNAME,
   PROP_PASSWORDLESS,
   PROP_SMALL_SCREEN,
@@ -96,6 +97,7 @@ struct _GisDriverPrivate {
   GdkPixbuf *avatar;  /* (owned) (nullable) */
 
   gboolean is_live_session;
+  gboolean is_live_dvd;
 
   GisDriverMode mode;
   UmAccountMode account_mode;
@@ -123,12 +125,11 @@ check_for_live_boot (gchar **uuid)
   g_autoptr(GRegex) reg = NULL;
   g_autoptr(GMatchInfo) info = NULL;
 
-  g_return_val_if_fail (uuid != NULL, FALSE);
-
   force = g_getenv ("EI_FORCE_LIVE_BOOT_UUID");
   if (force != NULL && *force != '\0')
     {
-      *uuid = g_strdup (force);
+      if (uuid != NULL)
+        *uuid = g_strdup (force);
       return TRUE;
     }
 
@@ -140,23 +141,34 @@ check_for_live_boot (gchar **uuid)
 
   live_boot = g_regex_match_simple ("\\bendless\\.live_boot\\b", cmdline, 0, 0);
 
-  reg = g_regex_new ("\\bendless\\.image\\.device=UUID=([^\\s]*)", 0, 0, NULL);
-  g_regex_match (reg, cmdline, 0, &info);
-  if (g_match_info_matches (info))
-    *uuid = g_match_info_fetch (info, 1);
+  if (uuid != NULL)
+    {
+      reg = g_regex_new ("\\bendless\\.image\\.device=UUID=([^\\s]*)", 0, 0, NULL);
+      g_regex_match (reg, cmdline, 0, &info);
+      if (g_match_info_matches (info))
+        *uuid = g_match_info_fetch (info, 1);
+    }
 
   return live_boot;
 }
 
-static gboolean
-running_live_session (void)
+static void
+check_live_session (GisDriver   *driver,
+                    const gchar *image_version)
 {
-  g_autofree gchar *uuid = NULL;
-
-  if (!check_for_live_boot (&uuid))
-    return FALSE;
+  GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
 
-  return TRUE;
+  if (check_for_live_boot (NULL))
+    {
+      priv->is_live_session = TRUE;
+      priv->is_live_dvd = image_version != NULL &&
+        g_str_has_prefix (image_version, "eosdvd-");
+    }
+  else
+    {
+      priv->is_live_session = FALSE;
+      priv->is_live_dvd = FALSE;
+    }
 }
 
 #define EOS_IMAGE_VERSION_PATH "/sysroot"
@@ -794,6 +806,9 @@ gis_driver_get_property (GObject      *object,
     case PROP_LIVE_SESSION:
       g_value_set_boolean (value, priv->is_live_session);
       break;
+    case PROP_LIVE_DVD:
+      g_value_set_boolean (value, priv->is_live_dvd);
+      break;
     case PROP_MODE:
       g_value_set_enum (value, priv->mode);
       break;
@@ -1062,8 +1077,9 @@ gis_driver_startup (GApplication *app)
   image_version = get_image_version ();
   priv->product_name = get_product_from_image_version (image_version);
 
-  priv->is_live_session = running_live_session ();
+  check_live_session (driver, image_version);
   g_object_notify_by_pspec (G_OBJECT (driver), obj_props[PROP_LIVE_SESSION]);
+  g_object_notify_by_pspec (G_OBJECT (driver), obj_props[PROP_LIVE_DVD]);
 
   gis_driver_set_user_language (driver, setlocale (LC_MESSAGES, NULL), FALSE);
 
@@ -1122,6 +1138,11 @@ gis_driver_class_init (GisDriverClass *klass)
                           FALSE,
                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
+  obj_props[PROP_LIVE_DVD] =
+    g_param_spec_boolean ("live-dvd", "", "",
+                          FALSE,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
   obj_props[PROP_MODE] =
     g_param_spec_enum ("mode", "", "",
                        GIS_TYPE_DRIVER_MODE,


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