bstinson / rpms / rpm-ostree

Forked from rpms/rpm-ostree 5 years ago
Clone

Blame SOURCES/0001-postprocess-Handle-Fedora-rawhide-kernel-installatio.patch

88798c
From 1c3a549ef9ebaecf9a0eab7515adddc594c78779 Mon Sep 17 00:00:00 2001
88798c
From: Colin Walters <walters@verbum.org>
88798c
Date: Tue, 12 May 2015 12:26:38 -0400
88798c
Subject: [PATCH] postprocess: Handle Fedora rawhide kernel installation
88798c
88798c
The vmlinuz binary has moved to /usr/lib/modules, which is a change
88798c
mostly for the better, but we need to adapt.
88798c
88798c
Closes: https://github.com/projectatomic/rpm-ostree/pull/143
88798c
---
88798c
 src/libpriv/rpmostree-postprocess.c | 98 +++++++++++++++++++++++++++++++------
88798c
 1 file changed, 84 insertions(+), 14 deletions(-)
88798c
88798c
diff --git a/src/libpriv/rpmostree-postprocess.c b/src/libpriv/rpmostree-postprocess.c
88798c
index c690fe2..7b390f9 100644
88798c
--- a/src/libpriv/rpmostree-postprocess.c
88798c
+++ b/src/libpriv/rpmostree-postprocess.c
88798c
@@ -168,7 +168,8 @@ find_kernel_and_initramfs_in_bootdir (GFile       *bootdir,
88798c
 
88798c
       name = g_file_info_get_name (file_info);
88798c
 
88798c
-      if (g_str_has_prefix (name, "vmlinuz-"))
88798c
+      /* Current Fedora 23 kernel.spec installs as just vmlinuz */
88798c
+      if (strcmp (name, "vmlinuz") == 0 || g_str_has_prefix (name, "vmlinuz-"))
88798c
         {
88798c
           if (ret_kernel)
88798c
             {
88798c
@@ -192,17 +193,57 @@ find_kernel_and_initramfs_in_bootdir (GFile       *bootdir,
88798c
         }
88798c
     }
88798c
 
88798c
-  if (!ret_kernel)
88798c
+  ret = TRUE;
88798c
+  gs_transfer_out_value (out_kernel, &ret_kernel);
88798c
+  gs_transfer_out_value (out_initramfs, &ret_initramfs);
88798c
+ out:
88798c
+  return ret;
88798c
+}
88798c
+
88798c
+/* Given a directory @d, find the first child that is a directory,
88798c
+ * returning it in @out_subdir.  If there are multiple directories,
88798c
+ * return an error.
88798c
+ */
88798c
+static gboolean
88798c
+find_ensure_one_subdirectory (GFile         *d,
88798c
+                              GFile        **out_subdir,
88798c
+                              GCancellable  *cancellable,
88798c
+                              GError       **error)
88798c
+{
88798c
+  gboolean ret = FALSE;
88798c
+  gs_unref_object GFileEnumerator *direnum = NULL;
88798c
+  gs_unref_object GFile *ret_subdir = NULL;
88798c
+
88798c
+  direnum = g_file_enumerate_children (d, "standard::name,standard::type", 0, 
88798c
+                                       cancellable, error);
88798c
+  if (!direnum)
88798c
+    goto out;
88798c
+
88798c
+  while (TRUE)
88798c
     {
88798c
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
88798c
-                   "Unable to find vmlinuz- in %s",
88798c
-                   gs_file_get_path_cached (bootdir));
88798c
-      goto out;
88798c
+      GFileInfo *file_info;
88798c
+      GFile *child;
88798c
+
88798c
+      if (!gs_file_enumerator_iterate (direnum, &file_info, &child,
88798c
+                                       cancellable, error))
88798c
+        goto out;
88798c
+      if (!file_info)
88798c
+        break;
88798c
+
88798c
+      if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
88798c
+        {
88798c
+          if (ret_subdir)
88798c
+            {
88798c
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
88798c
+                           "Multiple subdirectories found in: %s", gs_file_get_path_cached (d));
88798c
+              goto out;
88798c
+            }
88798c
+          ret_subdir = g_object_ref (child);
88798c
+        }
88798c
     }
88798c
 
88798c
   ret = TRUE;
88798c
-  gs_transfer_out_value (out_kernel, &ret_kernel);
88798c
-  gs_transfer_out_value (out_initramfs, &ret_initramfs);
88798c
+  gs_transfer_out_value (out_subdir, &ret_subdir);
88798c
  out:
88798c
   return ret;
88798c
 }
88798c
@@ -220,14 +261,38 @@ do_kernel_prep (GFile         *yumroot,
88798c
   gs_unref_object GFile *initramfs_path = NULL;
88798c
   const char *boot_checksum_str = NULL;
88798c
   GChecksum *boot_checksum = NULL;
88798c
-  const char *kname;
88798c
-  const char *kver;
88798c
+  g_autofree char *kver = NULL;
88798c
 
88798c
   if (!find_kernel_and_initramfs_in_bootdir (bootdir, &kernel_path,
88798c
                                              &initramfs_path,
88798c
                                              cancellable, error))
88798c
     goto out;
88798c
 
88798c
+  if (kernel_path == NULL)
88798c
+    {
88798c
+      gs_unref_object GFile *mod_dir = g_file_resolve_relative_path (yumroot, "usr/lib/modules");
88798c
+      gs_unref_object GFile *modversion_dir = NULL;
88798c
+
88798c
+      if (!find_ensure_one_subdirectory (mod_dir, &modversion_dir, cancellable, error))
88798c
+        goto out;
88798c
+
88798c
+      if (modversion_dir)
88798c
+        {
88798c
+          kver = g_file_get_basename (modversion_dir);
88798c
+          if (!find_kernel_and_initramfs_in_bootdir (modversion_dir, &kernel_path,
88798c
+                                                     &initramfs_path,
88798c
+                                                     cancellable, error))
88798c
+            goto out;
88798c
+        }
88798c
+    }
88798c
+
88798c
+  if (kernel_path == NULL)
88798c
+    {
88798c
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
88798c
+                   "Unable to find kernel (vmlinuz) in /boot or /usr/lib/modules");
88798c
+      goto out;
88798c
+    }
88798c
+      
88798c
   if (initramfs_path)
88798c
     {
88798c
       g_print ("Removing RPM-generated '%s'\n",
88798c
@@ -236,10 +301,15 @@ do_kernel_prep (GFile         *yumroot,
88798c
         goto out;
88798c
     }
88798c
 
88798c
-  kname = gs_file_get_basename_cached (kernel_path);
88798c
-  kver = strchr (kname, '-');
88798c
-  g_assert (kver);
88798c
-  kver += 1;
88798c
+  if (!kver)
88798c
+    {
88798c
+      const char *kname = gs_file_get_basename_cached (kernel_path);
88798c
+      const char *kver_p;
88798c
+
88798c
+      kver_p = strchr (kname, '-');
88798c
+      g_assert (kver_p);
88798c
+      kver = g_strdup (kver_p + 1);
88798c
+    }
88798c
 
88798c
   /* OSTree needs to own this */
88798c
   {
88798c
-- 
88798c
1.8.3.1
88798c