Skip to content

Commit

Permalink
fixup! deploy: Keep last deployment version during stage
Browse files Browse the repository at this point in the history
Properly find last version
  • Loading branch information
r4f4 committed Nov 26, 2019
1 parent 68dfb0f commit 3860ca4
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/libostree/ostree-sysroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,11 +1631,16 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
if (!booted_deployment && !merge_deployment && (retain_pending || retain_rollback))
retain = TRUE;

/* tracks current versioned deployment */
OstreeRepo *repo = ostree_sysroot_repo (sysroot);
OstreeDeployment *versioned = booted_deployment ? booted_deployment : merge_deployment;
const gchar *last_version = NULL;
if (versioned)
last_version = _ostree_deployment_get_version (versioned, repo, error);

/* tracks when we come across the booted deployment */
gboolean before_booted = TRUE;
gboolean before_merge = TRUE;
/* tracks last version */
const gchar *last_version = NULL;
gboolean retained_previous_version = FALSE;
for (guint i = 0; i < deployments->len; i++)
{
Expand All @@ -1655,20 +1660,10 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
const gboolean passed_crossover = booted_deployment ? !before_booted : !before_merge;

gboolean is_previous_version = FALSE;
if (!retained_previous_version)
if (passed_crossover && osname_matches && !retained_previous_version)
{
OstreeRepo *repo = ostree_sysroot_repo (sysroot);
const gchar *deployment_version =
_ostree_deployment_get_version (deployment, repo, error);

if (deployment_version && *deployment_version)
{
if (!last_version)
last_version = deployment_version;

is_previous_version = (osname_matches && passed_crossover && last_version &&
(g_strcmp0 (deployment_version, last_version) != 0));
}
const gchar *version = _ostree_deployment_get_version (deployment, repo, error);
is_previous_version = version && (!last_version || (g_strcmp0 (version, last_version) < 0));
}

/* Retain deployment if:
Expand All @@ -1689,7 +1684,7 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
/*
* - we're keeping the previous version deployment
*/
else if (retain_previous && is_previous_version && !retained_previous_version)
else if (retain_previous && !retained_previous_version && is_previous_version)
{
g_ptr_array_add (new_deployments, g_object_ref (deployment));
/* Just keep one previous version */
Expand Down

0 comments on commit 3860ca4

Please sign in to comment.