[ostree] admin: Don't overwrite previous ref unless it's different



commit 64934202e43ac6b067829078a79afb69c098dc45
Author: Colin Walters <walters verbum org>
Date:   Thu Jan 24 17:32:59 2013 -0500

    admin: Don't overwrite previous ref unless it's different
    
    We shouldn't overwrite deploy/<osname>/previous unless we actually
    have something new.
    
    This fixes the bug where two consecutive:
    
    $ ostree admin upgrade foo
    $ ostree admin upgrade foo
    
    would end up pruning the data for foo/previous from the repo.

 src/ostree/ot-admin-builtin-deploy.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c
index 088cfbf..24bc0da 100644
--- a/src/ostree/ot-admin-builtin-deploy.c
+++ b/src/ostree/ot-admin-builtin-deploy.c
@@ -404,6 +404,7 @@ deploy_tree (OtAdminDeploy     *self,
   ot_lfree char *checkout_target_name = NULL;
   ot_lfree char *checkout_target_tmp_name = NULL;
   ot_lfree char *resolved_commit = NULL;
+  gs_free char *resolved_previous_commit = NULL;
   GError *temp_error = NULL;
   gboolean skip_checkout;
 
@@ -423,6 +424,8 @@ deploy_tree (OtAdminDeploy     *self,
 
   if (!ostree_repo_resolve_rev (self->repo, revision, FALSE, &resolved_commit, error))
     goto out;
+  if (!ostree_repo_resolve_rev (self->repo, revision, TRUE, &resolved_previous_commit, error))
+    goto out;
 
   root = (OstreeRepoFile*)ostree_repo_file_new_root (self->repo, resolved_commit);
   if (!ostree_repo_file_ensure_resolved (root, error))
@@ -561,7 +564,10 @@ deploy_tree (OtAdminDeploy     *self,
   if (!ostree_repo_write_ref (self->repo, NULL, current_deployment_ref,
                               resolved_commit, error))
     goto out;
-  if (previous_deployment_revision != NULL)
+  /* Only overwrite previous if it's different from what we're deploying now.
+   */
+  if (resolved_previous_commit != NULL
+      && strcmp (resolved_previous_commit, resolved_commit) != 0)
     {
       if (!ostree_repo_write_ref (self->repo, NULL, previous_deployment_ref,
                                   previous_deployment_revision, error))



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