lib/upgrader: Port to new code style

No surprises here.  Prep for future work.

Closes: #864
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-05-16 11:30:35 -04:00 committed by Atomic Bot
parent 9380dbb14d
commit 3ef2870700
1 changed files with 41 additions and 91 deletions

View File

@ -22,6 +22,7 @@
#include "otutil.h" #include "otutil.h"
#include "ostree.h"
#include "ostree-sysroot-upgrader.h" #include "ostree-sysroot-upgrader.h"
/** /**
@ -70,7 +71,6 @@ parse_refspec (OstreeSysrootUpgrader *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autofree char *origin_refspec = NULL; g_autofree char *origin_refspec = NULL;
g_autofree char *unconfigured_state = NULL; g_autofree char *unconfigured_state = NULL;
g_autofree char *csum = NULL; g_autofree char *csum = NULL;
@ -82,37 +82,28 @@ parse_refspec (OstreeSysrootUpgrader *self,
*/ */
unconfigured_state = g_key_file_get_string (self->origin, "origin", "unconfigured-state", NULL); unconfigured_state = g_key_file_get_string (self->origin, "origin", "unconfigured-state", NULL);
if (unconfigured_state) if (unconfigured_state)
{ return glnx_throw (error, "origin unconfigured-state: %s", unconfigured_state);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"origin unconfigured-state: %s", unconfigured_state);
goto out;
}
} }
origin_refspec = g_key_file_get_string (self->origin, "origin", "refspec", NULL); origin_refspec = g_key_file_get_string (self->origin, "origin", "refspec", NULL);
if (!origin_refspec) if (!origin_refspec)
{ return glnx_throw (error, "No origin/refspec in current deployment origin; cannot upgrade via ostree");
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No origin/refspec in current deployment origin; cannot upgrade via ostree");
goto out;
}
g_clear_pointer (&self->origin_remote, g_free); g_clear_pointer (&self->origin_remote, g_free);
g_clear_pointer (&self->origin_ref, g_free); g_clear_pointer (&self->origin_ref, g_free);
if (!ostree_parse_refspec (origin_refspec, if (!ostree_parse_refspec (origin_refspec,
&self->origin_remote, &self->origin_remote,
&self->origin_ref, &self->origin_ref,
error)) error))
goto out; return FALSE;
csum = g_key_file_get_string (self->origin, "origin", "override-commit", NULL); csum = g_key_file_get_string (self->origin, "origin", "override-commit", NULL);
if (csum != NULL && !ostree_validate_checksum_string (csum, error)) if (csum != NULL && !ostree_validate_checksum_string (csum, error))
goto out; return FALSE;
g_clear_pointer (&self->override_csum, g_free); g_clear_pointer (&self->override_csum, g_free);
self->override_csum = g_steal_pointer (&csum); self->override_csum = g_steal_pointer (&csum);
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -120,17 +111,12 @@ ostree_sysroot_upgrader_initable_init (GInitable *initable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
OstreeSysrootUpgrader *self = (OstreeSysrootUpgrader*)initable; OstreeSysrootUpgrader *self = (OstreeSysrootUpgrader*)initable;
OstreeDeployment *booted_deployment = OstreeDeployment *booted_deployment =
ostree_sysroot_get_booted_deployment (self->sysroot); ostree_sysroot_get_booted_deployment (self->sysroot);
if (booted_deployment == NULL && self->osname == NULL) if (booted_deployment == NULL && self->osname == NULL)
{ return glnx_throw (error, "Not currently booted into an OSTree system and no OS specified");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Not currently booted into an OSTree system and no OS specified");
goto out;
}
if (self->osname == NULL) if (self->osname == NULL)
{ {
@ -138,37 +124,23 @@ ostree_sysroot_upgrader_initable_init (GInitable *initable,
self->osname = g_strdup (ostree_deployment_get_osname (booted_deployment)); self->osname = g_strdup (ostree_deployment_get_osname (booted_deployment));
} }
else if (self->osname[0] == '\0') else if (self->osname[0] == '\0')
{ return glnx_throw (error, "Invalid empty osname");
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid empty osname");
goto out;
}
self->merge_deployment = ostree_sysroot_get_merge_deployment (self->sysroot, self->osname); self->merge_deployment = ostree_sysroot_get_merge_deployment (self->sysroot, self->osname);
if (self->merge_deployment == NULL) if (self->merge_deployment == NULL)
{ return glnx_throw (error, "No previous deployment for OS '%s'", self->osname);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No previous deployment for OS '%s'", self->osname);
goto out;
}
self->origin = ostree_deployment_get_origin (self->merge_deployment); self->origin = ostree_deployment_get_origin (self->merge_deployment);
if (!self->origin) if (!self->origin)
{ return glnx_throw (error, "No origin known for deployment %s.%d",
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, ostree_deployment_get_csum (self->merge_deployment),
"No origin known for deployment %s.%d", ostree_deployment_get_deployserial (self->merge_deployment));
ostree_deployment_get_csum (self->merge_deployment),
ostree_deployment_get_deployserial (self->merge_deployment));
goto out;
}
g_key_file_ref (self->origin); g_key_file_ref (self->origin);
if (!parse_refspec (self, cancellable, error)) if (!parse_refspec (self, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
static void static void
@ -401,19 +373,15 @@ ostree_sysroot_upgrader_set_origin (OstreeSysrootUpgrader *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_clear_pointer (&self->origin, g_key_file_unref); g_clear_pointer (&self->origin, g_key_file_unref);
if (origin) if (origin)
{ {
self->origin = g_key_file_ref (origin); self->origin = g_key_file_ref (origin);
if (!parse_refspec (self, cancellable, error)) if (!parse_refspec (self, cancellable, error))
goto out; return FALSE;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -447,21 +415,19 @@ ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo,
const char *to_rev, const char *to_rev,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GVariant) old_commit = NULL; g_autoptr(GVariant) old_commit = NULL;
g_autoptr(GVariant) new_commit = NULL;
if (!ostree_repo_load_variant (repo, if (!ostree_repo_load_variant (repo,
OSTREE_OBJECT_TYPE_COMMIT, OSTREE_OBJECT_TYPE_COMMIT,
from_rev, from_rev,
&old_commit, &old_commit,
error)) error))
goto out; return FALSE;
g_autoptr(GVariant) new_commit = NULL;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
to_rev, &new_commit, to_rev, &new_commit,
error)) error))
goto out; return FALSE;
if (ostree_commit_get_timestamp (old_commit) > ostree_commit_get_timestamp (new_commit)) if (ostree_commit_get_timestamp (old_commit) > ostree_commit_get_timestamp (new_commit))
{ {
@ -471,31 +437,22 @@ ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo,
g_autofree char *new_ts_str = NULL; g_autofree char *new_ts_str = NULL;
if (old_ts == NULL || new_ts == NULL) if (old_ts == NULL || new_ts == NULL)
{ return glnx_throw (error, "Upgrade target revision '%s' timestamp (%" G_GINT64_FORMAT ") or current revision '%s' timestamp (%" G_GINT64_FORMAT ") is invalid",
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, to_rev, ostree_commit_get_timestamp (new_commit),
"Upgrade target revision '%s' timestamp (%" G_GINT64_FORMAT ") or current revision '%s' timestamp (%" G_GINT64_FORMAT ") is invalid", from_rev, ostree_commit_get_timestamp (old_commit));
to_rev, ostree_commit_get_timestamp (new_commit),
from_rev, ostree_commit_get_timestamp (old_commit));
goto out;
}
old_ts_str = g_date_time_format (old_ts, "%c"); old_ts_str = g_date_time_format (old_ts, "%c");
new_ts_str = g_date_time_format (new_ts, "%c"); new_ts_str = g_date_time_format (new_ts, "%c");
g_date_time_unref (old_ts); g_date_time_unref (old_ts);
g_date_time_unref (new_ts); g_date_time_unref (new_ts);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, return glnx_throw (error, "Upgrade target revision '%s' with timestamp '%s' is chronologically older than current revision '%s' with timestamp '%s'; use --allow-downgrade to permit",
"Upgrade target revision '%s' with timestamp '%s' is chronologically older than current revision '%s' with timestamp '%s'; use --allow-downgrade to permit", to_rev, new_ts_str, from_rev, old_ts_str);
to_rev, new_ts_str, from_rev, old_ts_str);
goto out;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
* ostree_sysroot_upgrader_pull: * ostree_sysroot_upgrader_pull:
* @self: Upgrader * @self: Upgrader
@ -551,8 +508,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(OstreeRepo) repo = NULL;
glnx_unref_object OstreeRepo *repo = NULL;
char *refs_to_fetch[] = { NULL, NULL }; char *refs_to_fetch[] = { NULL, NULL };
const char *from_revision = NULL; const char *from_revision = NULL;
g_autofree char *origin_refspec = NULL; g_autofree char *origin_refspec = NULL;
@ -563,7 +519,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
refs_to_fetch[0] = self->origin_ref; refs_to_fetch[0] = self->origin_ref;
if (!ostree_sysroot_get_repo (self->sysroot, &repo, cancellable, error)) if (!ostree_sysroot_get_repo (self->sysroot, &repo, cancellable, error))
goto out; return FALSE;
if (self->origin_remote) if (self->origin_remote)
origin_refspec = g_strconcat (self->origin_remote, ":", self->origin_ref, NULL); origin_refspec = g_strconcat (self->origin_remote, ":", self->origin_ref, NULL);
@ -579,7 +535,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
if (!ostree_repo_pull_one_dir (repo, self->origin_remote, dir_to_pull, refs_to_fetch, if (!ostree_repo_pull_one_dir (repo, self->origin_remote, dir_to_pull, refs_to_fetch,
flags, progress, flags, progress,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (progress) if (progress)
ostree_async_progress_finish (progress); ostree_async_progress_finish (progress);
@ -593,7 +549,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
self->override_csum, self->override_csum,
cancellable, cancellable,
error)) error))
goto out; return FALSE;
self->new_revision = g_strdup (self->override_csum); self->new_revision = g_strdup (self->override_csum);
} }
@ -601,7 +557,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
{ {
if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE,
&self->new_revision, error)) &self->new_revision, error))
goto out; return FALSE;
} }
@ -620,13 +576,11 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
if (!ostree_sysroot_upgrader_check_timestamps (repo, from_revision, if (!ostree_sysroot_upgrader_check_timestamps (repo, from_revision,
self->new_revision, self->new_revision,
error)) error))
goto out; return FALSE;
} }
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -643,9 +597,7 @@ ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(OstreeDeployment) new_deployment = NULL;
glnx_unref_object OstreeDeployment *new_deployment = NULL;
if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname, if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname,
self->new_revision, self->new_revision,
self->origin, self->origin,
@ -653,18 +605,16 @@ ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self,
NULL, NULL,
&new_deployment, &new_deployment,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname, if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname,
new_deployment, new_deployment,
self->merge_deployment, self->merge_deployment,
0, 0,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
GType GType