main/pin: Fix usage of GError

This regressed in 2db79fb398
I noticed this while finally getting the installed tests to run
in FCOS via kola and `ostree admin pin 0` is now aborting because
we were returning TRUE, but no error set.

I don't see a reason to try to continue on if we hit an error;
the original reporter was requesting support for multiple arguments,
but not "ignore invalid requests".
This commit is contained in:
Colin Walters 2020-03-18 02:13:15 +00:00
parent 35c8fd3722
commit 0b6ac72b7f
1 changed files with 6 additions and 17 deletions

View File

@ -52,39 +52,28 @@ ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation
return FALSE; return FALSE;
} }
unsigned int nsuccess = 0;
for (unsigned int i = 1; i < argc; i++) for (unsigned int i = 1; i < argc; i++)
{ {
const char *deploy_index_str = argv[i]; const char *deploy_index_str = argv[i];
const int deploy_index = atoi (deploy_index_str); const int deploy_index = atoi (deploy_index_str);
g_autoptr(GError) e = NULL; g_autoptr(OstreeDeployment) target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error);
g_autoptr(OstreeDeployment) target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, &e);
if (!target_deployment) if (!target_deployment)
{ return FALSE;
g_print ("Invalid deployment %s: %s\n", deploy_index_str, e->message);
continue;
}
gboolean current_pin = ostree_deployment_is_pinned (target_deployment); gboolean current_pin = ostree_deployment_is_pinned (target_deployment);
const gboolean desired_pin = !opt_unpin; const gboolean desired_pin = !opt_unpin;
if (current_pin == desired_pin) if (current_pin == desired_pin)
{ {
g_print ("Deployment %s is already %s\n", deploy_index_str, current_pin ? "pinned" : "unpinned"); g_print ("Deployment %s is already %s\n", deploy_index_str, current_pin ? "pinned" : "unpinned");
nsuccess++;
} }
else else
{ {
g_autoptr(GError) e = NULL; if (!ostree_sysroot_deployment_set_pinned (sysroot, target_deployment, desired_pin, error))
if (ostree_sysroot_deployment_set_pinned (sysroot, target_deployment, desired_pin, &e)) return FALSE;
{ g_print ("Deployment %s is now %s\n", deploy_index_str, desired_pin ? "pinned" : "unpinned");
g_print ("Deployment %s is now %s\n", deploy_index_str, desired_pin ? "pinned" : "unpinned");
nsuccess++;
}
else
g_print ("Failed to %s deployment %s: %s\n", desired_pin ? "pin" : "unpin", deploy_index_str, e->message);
} }
} }
return nsuccess > 0; return TRUE;
} }