[Libosinfo] [libosinfo v2] Add 'eject-after-install' parameter to OsinfoMedia

Fabiano Fidêncio fidencio at redhat.com
Tue Apr 18 21:47:39 UTC 2017


From: Fabiano Fidêncio <fabiano at fidencio.org>

If the media is an installer, thus specifies whether the media should be
ejected after the installation process. Default value is true.

This is mainly needed for applications like GNOME Boxes (and maybe
virt-install) to be able to decide whether the media should be ejected
or not when the final reboot happens during its installation process.

The latter case may happen when the installer leaves some packages to be
installed after rebooting the OS for the last time.

The issue solved by this patch is a corner-case faced when adding the
install scripts for SLES, as during its installation only one reboot is
performed (so, installer-reboots attribute doesn't help us) and the media
must not be ejected after the reboot in order to finish the installation.

Signed-off-by: Fabiano Fidêncio <fabiano at fidencio.org>
---
 osinfo/libosinfo.syms  |  5 +++++
 osinfo/osinfo_db.c     |  9 ++++++++-
 osinfo/osinfo_loader.c |  9 +++++++++
 osinfo/osinfo_media.c  | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 osinfo/osinfo_media.h  |  2 ++
 5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 68d54ff..64c6f79 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -520,6 +520,11 @@ LIBOSINFO_0.2.12 {
 	osinfo_media_get_volume_size;
 } LIBOSINFO_0.2.11;
 
+LIBOSINFO_0.2.13 {
+    global:
+    osinfo_media_get_eject_after_install;
+} LIBOSINFO_0.2.12;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index cf86ccc..fa14c6d 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -628,6 +628,7 @@ static void fill_media(OsinfoDb *db, OsinfoMedia *media,
 {
     gboolean is_installer;
     gboolean is_live;
+    gboolean eject_after_install;
     gint reboots;
     const gchar *id;
     const gchar *kernel_path;
@@ -669,7 +670,13 @@ static void fill_media(OsinfoDb *db, OsinfoMedia *media,
                  NULL);
     if (is_installer) {
         reboots = osinfo_media_get_installer_reboots(matched_media);
-        g_object_set(G_OBJECT(media), "installer-reboots", reboots, NULL);
+        eject_after_install =
+            osinfo_media_get_eject_after_install(matched_media);
+
+        g_object_set(G_OBJECT(media),
+                     "installer-reboots", reboots,
+                     "eject-after-install", eject_after_install,
+                     NULL);
     }
     if (os != NULL)
         osinfo_media_set_os(media, os);
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index dba567f..6c7c009 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1050,6 +1050,8 @@ static OsinfoMedia *osinfo_loader_media(OsinfoLoader *loader,
     xmlChar *installer = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER);
     xmlChar *installer_reboots =
             xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER_REBOOTS);
+    xmlChar *eject_after_install =
+            xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL);
     const OsinfoEntityKey keys[] = {
         { OSINFO_MEDIA_PROP_URL, G_TYPE_STRING },
         { OSINFO_MEDIA_PROP_KERNEL, G_TYPE_STRING },
@@ -1082,6 +1084,13 @@ static OsinfoMedia *osinfo_loader_media(OsinfoLoader *loader,
         xmlFree(installer_reboots);
     }
 
+    if (eject_after_install) {
+        osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL,
+                                (gchar *)eject_after_install);
+        xmlFree(eject_after_install);
+    }
+
     gint nnodes = osinfo_loader_nodeset("./variant", loader, ctxt, &nodes, err);
     if (error_is_set(err)) {
         g_object_unref(media);
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index af4bb14..63967de 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -156,7 +156,8 @@ enum {
     PROP_INSTALLER_REBOOTS,
     PROP_OS,
     PROP_LANGUAGES,
-    PROP_VOLUME_SIZE
+    PROP_VOLUME_SIZE,
+    PROP_EJECT_AFTER_INSTALL
 };
 
 static void
@@ -236,6 +237,11 @@ osinfo_media_get_property(GObject    *object,
                           osinfo_media_get_volume_size(media));
         break;
 
+    case PROP_EJECT_AFTER_INSTALL:
+        g_value_set_boolean(value,
+                            osinfo_media_get_eject_after_install(media));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -332,6 +338,12 @@ osinfo_media_set_property(GObject      *object,
                                       g_value_get_int64(value));
         break;
 
+    case PROP_EJECT_AFTER_INSTALL:
+        osinfo_entity_set_param_boolean(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL,
+                                        g_value_get_boolean(value));
+
+        break;
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -574,6 +586,24 @@ osinfo_media_class_init(OsinfoMediaClass *klass)
                                G_PARAM_READWRITE |
                                G_PARAM_STATIC_STRINGS);
     g_object_class_install_property(g_klass, PROP_VOLUME_SIZE, pspec);
+
+    /**
+     * OsinfoMedia:eject-after-install:
+     *
+     * Whether the media should be ejected after the installation process.
+     *
+     * Some distros need their media to not be ejected after the final reboot
+     * during its installation process as some packages are installed after the
+     * reboot (which may cause the media to be ejected, depending on the
+     * application).
+     */
+    pspec = g_param_spec_boolean("eject-after-install",
+                                 "EjectAfterInstall",
+                                 _("Whether the media should be ejected after the installtion process"),
+                                 TRUE /* default value */,
+                                 G_PARAM_READWRITE |
+                                 G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_EJECT_AFTER_INSTALL, pspec);
 }
 
 static void
@@ -1269,6 +1299,20 @@ gint64 osinfo_media_get_volume_size(OsinfoMedia *media)
         (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_VOLUME_SIZE, -1);
 }
 
+/**
+ * osinfo_media_get_eject_after_install:
+ * @media: an #OsinfoMedia instance
+ *
+ * Whether @media should ejected after the installation procces.
+ *
+ * Returns: #TRUE if media should be ejected, #FALSE otherwise
+ */
+gboolean osinfo_media_get_eject_after_install(OsinfoMedia *media)
+{
+    return osinfo_entity_get_param_value_boolean_with_default
+        (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL, TRUE);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
@@ -1276,3 +1320,5 @@ gint64 osinfo_media_get_volume_size(OsinfoMedia *media)
  *  c-basic-offset: 4
  * End:
  */
+
+
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 09fbacd..6df7b60 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -90,6 +90,7 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_LANG_MAP       "l10n-language-map"
 #define OSINFO_MEDIA_PROP_VARIANT        "variant"
 #define OSINFO_MEDIA_PROP_VOLUME_SIZE    "volume-size"
+#define OSINFO_MEDIA_PROP_EJECT_AFTER_INSTALL "eject-after-install"
 
 /* object */
 struct _OsinfoMedia
@@ -140,6 +141,7 @@ gboolean osinfo_media_get_installer(OsinfoMedia *media);
 gboolean osinfo_media_get_live(OsinfoMedia *media);
 gint osinfo_media_get_installer_reboots(OsinfoMedia *media);
 gint64 osinfo_media_get_volume_size(OsinfoMedia *media);
+gboolean osinfo_media_get_eject_after_install(OsinfoMedia *media);
 
 #endif /* __OSINFO_MEDIA_H__ */
 /*
-- 
2.9.3




More information about the Libosinfo mailing list