Skip to content

Commit

Permalink
Refactor logic to separate findDeploymentIndex function
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Sturla <[email protected]>
  • Loading branch information
p5 committed Jan 23, 2024
1 parent 1fe36d3 commit 114cd15
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/ostree/ot-admin-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,42 +229,33 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
}
else if (opt_booted_index)
{
for (guint i = 0; i < deployments->len; ++i)
index = findDeploymentIndex (booted_deployment, deployments);
if (index != G_MAXUINT)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == booted_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
g_print ("%d\n", index);
return TRUE;
}

return FALSE;
}
else if (opt_pending_index)
{
for (guint i = 0; i < deployments->len; ++i)
index = findDeploymentIndex (pending_deployment, deployments);
if (index != G_MAXUINT)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == pending_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
g_print ("%d\n", index);
return TRUE;
}

return FALSE;
}
else if (opt_rollback_index)
{
for (guint i = 0; i < deployments->len; ++i)
index = findDeploymentIndex (rollback_deployment, deployments);
if (index != G_MAXUINT)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == rollback_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
g_print ("%d\n", index);
return TRUE;
}

return FALSE;
Expand All @@ -283,3 +274,16 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat

return TRUE;
}

static guint
findDeploymentIndex (OstreeDeployment *targetDeployment, GPtrArray *deployments)
{
for (guint i = 0; i < deployments->len; ++i)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == targetDeployment)
return i;
}

return G_MAXUINT;
}

0 comments on commit 114cd15

Please sign in to comment.