From 64934202e43ac6b067829078a79afb69c098dc45 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 24 Jan 2013 17:32:59 -0500 Subject: [PATCH] admin: Don't overwrite previous ref unless it's different We shouldn't overwrite deploy//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 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index 088cfbfa..24bc0da0 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))