deploy: Find kernel/initramfs consistently from filesystem
authorColin Walters <walters@verbum.org>
Tue, 21 Apr 2015 02:02:14 +0000 (22:02 -0400)
committerColin Walters <walters@verbum.org>
Sat, 19 Dec 2015 13:24:51 +0000 (08:24 -0500)
I'm porting the deployment code to be fd-relative, but part of the
logic was using `GFile` to talk to `OstreeRepoFile` to determine the
"bootcsum" (boot config checksum) before checking out the file tree.

We can avoid having both code paths by checking out the tree first,
then looking at it on the filesystem.

src/libostree/ostree-deployment-private.h [new file with mode: 0644]
src/libostree/ostree-deployment.c
src/libostree/ostree-sysroot-deploy.c

diff --git a/src/libostree/ostree-deployment-private.h b/src/libostree/ostree-deployment-private.h
new file mode 100644 (file)
index 0000000..b5ebb95
--- /dev/null
@@ -0,0 +1,29 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Colin Walters <walters@verbum.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#pragma once
+
+#include "ostree-deployment.h"
+
+G_BEGIN_DECLS
+
+void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum);
+
+G_END_DECLS
index 3d50df993b153bf6cb07818fd4b5bbf713856fbb..3a80474e56d5db08c4d07a12e5a99ab7715c38b3 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "config.h"
 
-#include "ostree-deployment.h"
+#include "ostree-deployment-private.h"
 #include "libglnx.h"
 
 struct _OstreeDeployment
@@ -129,6 +129,14 @@ ostree_deployment_set_origin (OstreeDeployment *self, GKeyFile *origin)
     self->origin = g_key_file_ref (origin);
 }
 
+void
+_ostree_deployment_set_bootcsum (OstreeDeployment *self,
+                                 const char *bootcsum)
+{
+  g_free (self->bootcsum);
+  self->bootcsum = g_strdup (bootcsum);
+}
+
 /**
  * ostree_deployment_clone:
  * @self: Deployment
index f7afe3d22230dc451871a4d1624cf3f55ae59852..82834f28d3e6760a24f85d38c1ea0576c7dfcb26 100644 (file)
@@ -24,6 +24,7 @@
 #include <gio/gunixoutputstream.h>
 
 #include "ostree-sysroot-private.h"
+#include "ostree-deployment-private.h"
 #include "ostree-core-private.h"
 #include "ostree-linuxfsutil.h"
 #include "otutil.h"
@@ -1934,7 +1935,6 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
   glnx_unref_object OstreeRepo *repo = NULL;
   g_autoptr(GFile) osdeploydir = NULL;
   g_autoptr(GFile) deployment_var = NULL;
-  g_autoptr(GFile) commit_root = NULL;
   g_autoptr(GFile) tree_kernel_path = NULL;
   g_autoptr(GFile) tree_initramfs_path = NULL;
   glnx_fd_close int deployment_dfd = -1;
@@ -1960,24 +1960,6 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
   if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
     goto out;
 
-  if (!ostree_repo_read_commit (repo, revision, &commit_root, NULL, cancellable, error))
-    goto out;
-
-  if (!get_kernel_from_tree (commit_root, &tree_kernel_path, &tree_initramfs_path,
-                             cancellable, error))
-    goto out;
-  
-  if (tree_initramfs_path != NULL)
-    {
-      if (!checksum_from_kernel_src (tree_initramfs_path, &new_bootcsum, error))
-        goto out;
-    }
-  else
-    {
-      if (!checksum_from_kernel_src (tree_kernel_path, &new_bootcsum, error))
-        goto out;
-    }
-
   if (provided_merge_deployment != NULL)
     merge_deployment = g_object_ref (provided_merge_deployment);
 
@@ -1997,6 +1979,25 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
       goto out;
     }
 
+  deployment_dir = ostree_sysroot_get_deployment_directory (self, new_deployment);
+
+  if (!get_kernel_from_tree (deployment_dir, &tree_kernel_path, &tree_initramfs_path,
+                             cancellable, error))
+    goto out;
+  
+  if (tree_initramfs_path != NULL)
+    {
+      if (!checksum_from_kernel_src (tree_initramfs_path, &new_bootcsum, error))
+        goto out;
+    }
+  else
+    {
+      if (!checksum_from_kernel_src (tree_kernel_path, &new_bootcsum, error))
+        goto out;
+    }
+  
+  _ostree_deployment_set_bootcsum (new_deployment, new_bootcsum);
+
   /* Create an empty boot configuration; we will merge things into
    * it as we go.
    */