[ostree/wip/upgrader-api] WIP on a new OstreeSysrootUpgrader class



commit 8adcb3f56efe9f27bcbe9199958e2b3b9473b084
Author: Colin Walters <walters verbum org>
Date:   Sun Mar 23 08:54:28 2014 -0400

    WIP on a new OstreeSysrootUpgrader class

 Makefile-libostree-defines.am           |    1 +
 Makefile-libostree.am                   |    1 +
 src/libostree/ostree-sysroot-upgrader.c |  375 +++++++++++++++++++++++++++++++
 src/libostree/ostree-sysroot-upgrader.h |   73 ++++++
 src/libostree/ostree.h                  |    1 +
 src/ostree/ot-admin-builtin-upgrade.c   |   91 ++++-----
 src/ostree/ot-admin-functions.c         |   28 ---
 7 files changed, 490 insertions(+), 80 deletions(-)
---
diff --git a/Makefile-libostree-defines.am b/Makefile-libostree-defines.am
index 02037ed..7f776e0 100644
--- a/Makefile-libostree-defines.am
+++ b/Makefile-libostree-defines.am
@@ -29,6 +29,7 @@ libostree_public_headers = \
        src/libostree/ostree-diff.h \
        src/libostree/ostree-sepolicy.h \
        src/libostree/ostree-sysroot.h \
+       src/libostree/ostree-sysroot-upgrader.h \
        src/libostree/ostree-deployment.h \
        src/libostree/ostree-bootconfig-parser.h \
        $(NULL)
diff --git a/Makefile-libostree.am b/Makefile-libostree.am
index 04d03be..988f1cb 100644
--- a/Makefile-libostree.am
+++ b/Makefile-libostree.am
@@ -61,6 +61,7 @@ libostree_1_la_SOURCES = \
        src/libostree/ostree-sysroot.c \
        src/libostree/ostree-sysroot-cleanup.c \
        src/libostree/ostree-sysroot-deploy.c \
+       src/libostree/ostree-sysroot-upgrader.c \
        src/libostree/ostree-bootconfig-parser.c \
        src/libostree/ostree-deployment.c \
        src/libostree/ostree-bootloader.h \
diff --git a/src/libostree/ostree-sysroot-upgrader.c b/src/libostree/ostree-sysroot-upgrader.c
new file mode 100644
index 0000000..54f1aef
--- /dev/null
+++ b/src/libostree/ostree-sysroot-upgrader.c
@@ -0,0 +1,375 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2014 Colin Walters <walters verbum org>
+ *
+ * This library 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 License, 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.
+ */
+
+#include "config.h"
+
+#include "otutil.h"
+#include "libgsystem.h"
+
+#include "ostree-sysroot-upgrader.h"
+
+/**
+ * SECTION:libostree-sysroot-upgrader
+ * @title: Simple upgrade class
+ * @short_description: Upgrade OSTree systems
+ *
+ * The #OstreeSysrootUpgrader class allows performing simple upgrade
+ * operations.
+ */
+typedef struct {
+  GObjectClass parent_class;
+} OstreeSysrootUpgraderClass;
+
+typedef struct {
+  GObject parent;
+
+  OstreeSysroot *sysroot;
+  char *osname;
+
+  OstreeDeployment *merge_deployment;
+  GKeyFile *origin;
+  char *origin_remote;
+  char *origin_ref;
+} OstreeSysrootUpgrader; 
+
+enum {
+  PROP_0,
+
+  PROP_SYSROOT,
+  PROP_OSNAME
+};
+
+static void ostree_sysroot_upgrader_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (OstreeSysrootUpgrader, ostree_sysroot_upgrader, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, 
ostree_sysroot_upgrader_initable_iface_init))
+
+static gboolean
+ostree_sysroot_upgrader_initable_init (GInitable        *initable,
+                                       GCancellable     *cancellable,
+                                       GError          **error)
+{
+  gboolean ret = FALSE;
+  OstreeSysrootUpgrader *self = (OstreeSysrootUpgrader*)initable;
+  OstreeDeployment *booted_deployment =
+    ostree_sysroot_get_booted_deployment (self->sysroot);
+  gs_unref_object GFile *deployment_path = NULL;
+  gs_unref_object GFile *deployment_origin_path = NULL;
+
+  if (booted_deployment == NULL && self->osname == NULL)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "Not currently booted into an OSTree system and no --os= argument given");
+      goto out;
+    }
+
+  self->merge_deployment = ostree_sysroot_get_merge_deployment (self->sysroot, osname); 
+  if (self->merge_deployment == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No previous deployment for OS '%s'", osname);
+      goto out;
+    }
+
+  deployment_path = ostree_sysroot_get_deployment_directory (self->sysroot, merge_deployment);
+  deployment_origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
+
+  origin = ostree_deployment_get_origin (merge_deployment);
+  if (!origin)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No origin known for deployment %s.%d",
+                   ostree_deployment_get_csum (self->merge_deployment),
+                   ostree_deployment_get_deployserial (self->merge_deployment));
+      goto out;
+    }
+  origin_refspec = g_key_file_get_string (origin, "origin", "refspec", NULL);
+  if (!origin_refspec)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No origin/refspec in current deployment origin; cannot upgrade via ostree");
+      goto out;
+    }
+  if (!ostree_parse_refspec (origin_refspec,
+                             &self->origin_remote, 
+                             &self->origin_ref,
+                             error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
+}
+
+static void
+ostree_sysroot_upgrader_initable_iface_init (GInitableIface *iface)
+{
+  iface->init = ostree_sysroot_upgrader_initable_init;
+}
+
+static void
+ostree_sysroot_upgrader_finalize (GObject *object)
+{
+  OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER_UPGRADER (object);
+
+  g_clear_object (&self->sysroot);
+  g_free (&self->osname);
+
+  g_clear_object (&self->merge_deployment);
+  if (self->origin)
+    g_key_file_unref (self->origin);
+  g_free (&self->origin_remote);
+  g_free (&self->origin_ref);
+
+  G_OBJECT_CLASS (ostree_sysroot_upgrader_parent_class)->finalize (object);
+}
+
+static void
+ostree_sysroot_upgrader_set_property (GObject         *object,
+                                      guint            prop_id,
+                                      const GValue    *value,
+                                      GParamSpec      *pspec)
+{
+  OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER_UPGRADER (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYSROOT:
+      self->sysroot = g_value_dup_object (value);
+      break;
+    case PROP_OSNAME:
+      self->oname = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+ostree_sysroot_upgrader_get_property (GObject         *object,
+                                      guint            prop_id,
+                                      GValue          *value,
+                                      GParamSpec      *pspec)
+{
+  OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER_UPGRADER (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYSROOT:
+      g_value_set_object (value, self->sysroot);
+      break;
+    case PROP_OSNAME:
+      g_value_set_string (value, self->osname);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+ostree_sysroot_upgrader_constructed (GObject *object)
+{
+  OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER_UPGRADER (object);
+
+  g_assert (self->sysroot != NULL);
+
+  G_OBJECT_CLASS (ostree_sysroot_upgrader_parent_class)->constructed (object);
+}
+
+static void
+ostree_sysroot_upgrader_class_init (OstreeSysrootUpgraderClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = ostree_sysroot_upgrader_constructed;
+  object_class->get_property = ostree_sysroot_upgrader_get_property;
+  object_class->set_property = ostree_sysroot_upgrader_set_property;
+  object_class->finalize = ostree_sysroot_upgrader_finalize;
+
+  g_object_class_install_property (object_class,
+                                   PROP_SYSROOT,
+                                   g_param_spec_object ("sysroot", "", "",
+                                                        OSTREE_TYPE_SYSROOT,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+  g_object_class_install_property (object_class,
+                                   PROP_OSNAME,
+                                   g_param_spec_string ("osname", "", "", "",
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+ostree_sysroot_upgrader_init (OstreeSysrootUpgrader *self)
+{
+}
+
+/**
+ * ostree_sysroot_upgrader_new:
+ * @sysroot: An #OstreeSysroot
+ *
+ * Returns: (transfer full): An upgrader
+ */
+OstreeSysrootUpgrader*
+ostree_sysroot_upgrader_new (OstreeSysroot *sysroot,
+                             GCancellable  *cancellable,
+                             GError       **error)
+{
+  return g_object_new (OSTREE_TYPE_SYSROOT_UPGRADER,
+                       "sysroot", sysroot, NULL);
+}
+
+/**
+ * ostree_sysroot_upgrader_new_for_os:
+ * @sysroot: An #OstreeSysroot
+ * @osname: (allow-none): Operating system name
+ *
+ * Returns: (transfer full): An upgrader
+ */
+OstreeSysrootUpgrader*
+ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot,
+                                    const char    *osname,
+                                    GCancellable  *cancellable,
+                                    GError       **error)
+{
+  return g_object_new (OSTREE_TYPE_SYSROOT_UPGRADER,
+                       "sysroot", sysroot,
+                       "osname", osname, NULL);
+}
+
+/**
+ * ostree_sysroot_upgrader_check_timestamps:
+ * @repo: Repo
+ * @from_rev: From revision
+ * @to_rev: To revision
+ * @error: Error
+ *
+ * Check that the timestamp on @to_rev is equal to or newer than
+ * @from_rev.  This protects systems against man-in-the-middle
+ * attackers which provide a client with an older commit.
+ */
+gboolean
+ostree_sysroot_upgrader_check_timestamps (OstreeRepo     *repo,
+                                          const char     *from_rev,
+                                          const char     *to_rev,
+                                          GError        **error)
+{
+  gboolean ret = FALSE;
+  const char *old_revision = ostree_deployment_get_csum (merge_deployment);
+  gs_unref_variant GVariant *old_commit = NULL;
+  gs_unref_variant GVariant *new_commit = NULL;
+
+  if (!ostree_repo_load_variant (repo,
+                                 OSTREE_OBJECT_TYPE_COMMIT,
+                                 from_rev,
+                                 &old_commit,
+                                 error))
+    goto out;
+  
+  if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
+                                 to_rev, &new_commit,
+                                 error))
+    goto out;
+
+  if (ostree_commit_get_timestamp (old_commit) > ostree_commit_get_timestamp (new_commit))
+    {
+      GDateTime *old_ts = g_date_time_new_from_unix_utc (ostree_commit_get_timestamp (old_commit));
+      GDateTime *new_ts = g_date_time_new_from_unix_utc (ostree_commit_get_timestamp (new_commit));
+      gs_free char *old_ts_str = NULL;
+      gs_free char *new_ts_str = NULL;
+
+      g_assert (old_ts);
+      g_assert (new_ts);
+      old_ts_str = g_date_time_format (old_ts, "%c");
+      new_ts_str = g_date_time_format (new_ts, "%c");
+      g_date_time_unref (old_ts);
+      g_date_time_unref (new_ts);
+
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Upgrade target revision '%s' with timestamp '%s' is chronologically older than current 
revision '%s' with timestamp '%s'; use --allow-downgrade to permit",
+                   to_rev, new_ts_str, from_rev, old_ts_str);
+      goto out;
+    }
+
+  ret = TRUE;
+ out:
+  return ret;
+}
+
+
+/**
+ * ostree_sysroot_upgrader_pull:
+ * @self: Upgrader
+ * @flags: Flags controlling pull behavior
+ * @upgrader_flags: Flags controlling upgrader behavior
+ * @progress: (allow-none): Progress
+ * @out_changed: (out): Whether or not the origin changed
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Perform a pull from the origin.  First check if the ref has
+ * changed, if so download the linked objects, and store the updated
+ * ref locally.  Then @out_changed will be %TRUE.
+ *
+ * If the origin remote is unchanged, @out_changed will be set to
+ * %FALSE.
+ */
+gboolean
+ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader  *self,
+                              OstreeRepoPullFlags     flags,
+                              OstreeSysrootUpgraderPullFlags     upgrader_flags,
+                              OstreeAsyncProgress    *progress,
+                              gboolean               *out_changed,
+                              GCancellable           *cancellable,
+                              GError                **error)
+{
+  gboolean ret = FALSE;
+  gs_unref_object OstreeRepo *repo =
+    ostree_sysroot_get_repo (self->sysroot);
+  char *refs_to_fetch[] = { self->origin_ref, NULL };
+  gs_free char *from_revision = NULL;
+  gs_free char *new_revision = NULL;
+  gs_free char *origin_refspec = NULL;
+
+  origin_refspec = g_strconcat (self->origin_remote, ":", self->origin_ref, NULL);
+
+  if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &from_revision,
+                                error))
+    goto out;
+
+  if (!ostree_repo_pull (repo, self->origin_remote, refs_to_fetch,
+                         flags, progress,
+                         cancellable, error))
+    goto out;
+
+  if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &new_revision,
+                                error))
+    goto out;
+
+  if (!ostree_sysroot_upgrader_check_timestamps (repo, from_revision,
+                                                 new_revision,
+                                                 error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
+}
diff --git a/src/libostree/ostree-sysroot-upgrader.h b/src/libostree/ostree-sysroot-upgrader.h
new file mode 100644
index 0000000..488fba9
--- /dev/null
+++ b/src/libostree/ostree-sysroot-upgrader.h
@@ -0,0 +1,73 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2014 Colin Walters <walters verbum org>
+ *
+ * This library 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 License, 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-sysroot.h"
+
+G_BEGIN_DECLS
+
+#define OSTREE_TYPE_SYSROOT_UPGRADER ostree_sysroot_upgrader_get_type()
+#define OSTREE_SYSROOT_UPGRADER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SYSROOT_UPGRADER, OstreeSysrootUpgrader))
+#define OSTREE_IS_SYSROOT_UPGRADER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SYSROOT_UPGRADER))
+
+GType ostree_sysroot_upgrader_get_type (void);
+
+OstreeSysrootUpgrader *ostree_sysroot_upgrader_new (OstreeSysroot *sysroot,
+                                                    GCancellable  *cancellable,
+                                                    GError       **error);
+
+OstreeSysrootUpgrader *ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot,
+                                                           const char    *osname,
+                                                           GCancellable  *cancellable,
+                                                           GError       **error);
+
+/*
+GKeyFile *ostree_sysroot_upgrader_get_origin (OstreeSysrootUpgrader *self);
+const char *ostree_sysroot_upgrader_get_origin_refspec (OstreeSysrootUpgrader *self);
+void  ostree_sysroot_upgrader_set_origin (OstreeSysrootUpgrader *self);
+*/
+
+gboolean ostree_sysroot_upgrader_check_timestamps (OstreeRepo     *repo,
+                                                   const char     *from_rev,
+                                                   const char     *to_rev,
+                                                   GError        **error);
+
+typedef enum {
+  OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_NONE = 0,
+  OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER = (1 << 0)
+} OstreeSysrootUpgraderPullFlags;
+
+gboolean ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader  *self,
+                                       OstreeRepoPullFlags     flags,
+                                       OstreeSysrootUpgraderPullFlags     upgrader_flags,
+                                       OstreeAsyncProgress    *progress,
+                                       gboolean               *out_changed,
+                                       GCancellable           *cancellable,
+                                       GError                **error);
+
+gboolean ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader  *self,
+                                         GCancellable           *cancellable,
+                                         GError                **error);
+
+G_END_DECLS
+
diff --git a/src/libostree/ostree.h b/src/libostree/ostree.h
index f1e7450..57b2ffd 100644
--- a/src/libostree/ostree.h
+++ b/src/libostree/ostree.h
@@ -26,6 +26,7 @@
 #include <ostree-mutable-tree.h>
 #include <ostree-repo-file.h>
 #include <ostree-sysroot.h>
+#include <ostree-sysroot-upgrader.h>
 #include <ostree-deployment.h>
 #include <ostree-bootconfig-parser.h>
 #include <ostree-diff.h>
diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c
index badaf2e..fcd6699 100644
--- a/src/ostree/ot-admin-builtin-upgrade.c
+++ b/src/ostree/ot-admin-builtin-upgrade.c
@@ -49,7 +49,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
 {
   gboolean ret = FALSE;
   GOptionContext *context;
-  gs_unref_object OstreeRepo *repo = NULL;
+  gs_unref_object OstreeSysrootUpgrader *upgrader = NULL;
   gs_free char *origin_remote = NULL;
   gs_free char *origin_ref = NULL;
   gs_free char *origin_refspec = NULL;
@@ -58,6 +58,8 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
   gs_unref_object GFile *deployment_origin_path = NULL;
   gs_unref_object OstreeDeployment *merge_deployment = NULL;
   gs_unref_object OstreeDeployment *new_deployment = NULL;
+  GSConsole *console;
+  gs_unref_object OstreeAsyncProgress *progress = NULL;
   GKeyFile *origin;
 
   context = g_option_context_new ("Construct new tree from current origin and deploy it, if it changed");
@@ -69,6 +71,42 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
   if (!ostree_sysroot_load (sysroot, cancellable, error))
     goto out;
 
+  upgrader = ostree_sysroot_upgrader_new (sysroot, opt_osname,
+                                          cancellable, error);
+  if (!upgrader)
+    goto out;
+
+  console = gs_console_get ();
+  if (console)
+    {
+      gs_console_begin_status_line (console, "", NULL, NULL);
+      progress = ostree_async_progress_new_and_connect (ot_common_pull_progress, console);
+    }
+
+  if (!ostree_sysroot_upgrader_pull (upgrader, 0, progress, &changed,
+                                     cancellable, error))
+    goto out;
+
+  if (!changed)
+    {
+      const char *origin_refspec = ostree_sysroot_upgrader_get_origin_refspec (upgrader);
+      g_assert (origin_refspec);
+      g_print ("%s is unchanged\n", origin_refspec);
+    }
+  else
+    {
+      gs_unref_object GFile *real_sysroot = g_file_new_for_path ("/");
+
+      if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
+        goto out;
+
+      if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
+        {
+          gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
+                                         cancellable, error,
+                                         "systemctl", "reboot", NULL);
+        }
+    }
 
   if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
     goto out;
@@ -82,19 +120,9 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
   if (origin_remote)
     {
       OstreeRepoPullFlags pullflags = 0;
-      char *refs_to_fetch[] = { origin_ref, NULL };
-      GSConsole *console;
-      gs_unref_object OstreeAsyncProgress *progress = NULL;
 
       g_print ("Fetching remote %s ref %s\n", origin_remote, origin_ref);
 
-      console = gs_console_get ();
-      if (console)
-        {
-          gs_console_begin_status_line (console, "", NULL, NULL);
-          progress = ostree_async_progress_new_and_connect (ot_common_pull_progress, console);
-        }
-
       if (!ostree_repo_pull (repo, origin_remote, refs_to_fetch, pullflags, progress,
                              cancellable, error))
         goto out;
@@ -115,44 +143,9 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
     }
   else
     {
-      gs_unref_object GFile *real_sysroot = g_file_new_for_path ("/");
 
       if (!opt_allow_downgrade)
         {
-          const char *old_revision = ostree_deployment_get_csum (merge_deployment);
-          gs_unref_variant GVariant *old_commit = NULL;
-          gs_unref_variant GVariant *new_commit = NULL;
-
-          if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
-                                         old_revision,
-                                         &old_commit,
-                                         error))
-            goto out;
-          
-          if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
-                                         new_revision, &new_commit,
-                                         error))
-            goto out;
-
-          if (ostree_commit_get_timestamp (old_commit) > ostree_commit_get_timestamp (new_commit))
-            {
-              GDateTime *old_ts = g_date_time_new_from_unix_utc (ostree_commit_get_timestamp (old_commit));
-              GDateTime *new_ts = g_date_time_new_from_unix_utc (ostree_commit_get_timestamp (new_commit));
-              gs_free char *old_ts_str = NULL;
-              gs_free char *new_ts_str = NULL;
-
-              g_assert (old_ts);
-              g_assert (new_ts);
-              old_ts_str = g_date_time_format (old_ts, "%c");
-              new_ts_str = g_date_time_format (new_ts, "%c");
-              g_date_time_unref (old_ts);
-              g_date_time_unref (new_ts);
-
-              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                           "Upgrade target revision '%s' with timestamp '%s' is chronologically older than 
current revision '%s' with timestamp '%s'; use --allow-downgrade to permit",
-                           new_revision, new_ts_str, old_revision, old_ts_str);
-              goto out;
-            }
         }
       
       /* Here we perform cleanup of any leftover data from previous
@@ -183,12 +176,6 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
                                                    cancellable, error))
         goto out;
 
-      if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
-        {
-          gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
-                                         cancellable, error,
-                                         "systemctl", "reboot", NULL);
-        }
     }
 
   ret = TRUE;
diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c
index 198f3e4..0faebae 100644
--- a/src/ostree/ot-admin-functions.c
+++ b/src/ostree/ot-admin-functions.c
@@ -63,41 +63,13 @@ ot_admin_deploy_prepare (OstreeSysroot      *sysroot,
   gs_free char *origin_refspec = NULL;
   gs_free char *origin_remote = NULL;
   gs_free char *origin_ref = NULL;
-  gs_unref_object GFile *deployment_path = NULL;
-  gs_unref_object GFile *deployment_origin_path = NULL;
   gs_unref_object OstreeDeployment *merge_deployment = NULL;
   GKeyFile *origin;
 
   if (!ot_admin_require_booted_deployment_or_osname (sysroot, osname,
                                                      cancellable, error))
     goto out;
-  merge_deployment = ostree_sysroot_get_merge_deployment (sysroot, osname); 
-  if (merge_deployment == NULL)
-    {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   "No previous deployment for OS '%s'", osname);
-      goto out;
-    }
 
-  deployment_path = ostree_sysroot_get_deployment_directory (sysroot, merge_deployment);
-  deployment_origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
-
-  origin = ostree_deployment_get_origin (merge_deployment);
-  if (!origin)
-    {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   "No origin known for current deployment");
-      goto out;
-    }
-  origin_refspec = g_key_file_get_string (origin, "origin", "refspec", NULL);
-  if (!origin_refspec)
-    {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                   "No origin/refspec in current deployment origin; cannot upgrade via ostree");
-      goto out;
-    }
-  if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error))
-    goto out;
 
   ret = TRUE;
   gs_transfer_out_value (out_merge_deployment, &merge_deployment);


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