lib/sysroot: Add non-failable ostree_sysroot_repo()
Having a failable accessor is annoying, since it's really common to reference both. Instead, open the repo once when we load the sysroot, and provide a non-failable accessor. This is also prep for `ostree_repo_open_at()`, which collapses the separation between `ostree_repo_new()` and `ostree_repo_open()`. Closes: #886 Approved by: jlebon
This commit is contained in:
parent
ed430b45de
commit
9bf8a8503a
|
|
@ -486,6 +486,7 @@ ostree_sysroot_get_deployment_dirpath
|
|||
ostree_sysroot_get_deployment_origin_path
|
||||
ostree_sysroot_cleanup
|
||||
ostree_sysroot_prepare_cleanup
|
||||
ostree_sysroot_repo
|
||||
ostree_sysroot_get_repo
|
||||
ostree_sysroot_init_osname
|
||||
ostree_sysroot_deployment_set_kargs
|
||||
|
|
|
|||
|
|
@ -402,12 +402,10 @@ global:
|
|||
* NOTE NOTE NOTE
|
||||
*/
|
||||
|
||||
/*
|
||||
LIBOSTREE_2017.$NEWVERSION {
|
||||
LIBOSTREE_2017.7 {
|
||||
global:
|
||||
someostree_symbol_deleteme;
|
||||
ostree_sysroot_repo;
|
||||
} LIBOSTREE_2017.6;
|
||||
*/
|
||||
|
||||
/* Stub section for the stable release *after* this development one; don't
|
||||
* edit this other than to update the last number. This is just a copy/paste
|
||||
|
|
|
|||
|
|
@ -501,8 +501,6 @@ _ostree_sysroot_cleanup_internal (OstreeSysroot *self,
|
|||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
glnx_unref_object OstreeRepo *repo = NULL;
|
||||
|
||||
g_return_val_if_fail (OSTREE_IS_SYSROOT (self), FALSE);
|
||||
g_return_val_if_fail (self->loaded, FALSE);
|
||||
|
||||
|
|
@ -512,9 +510,7 @@ _ostree_sysroot_cleanup_internal (OstreeSysroot *self,
|
|||
if (!cleanup_old_deployments (self, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
OstreeRepo *repo = ostree_sysroot_repo (self);
|
||||
if (!generate_deployment_refs (self, repo,
|
||||
self->bootversion,
|
||||
self->subbootversion,
|
||||
|
|
|
|||
|
|
@ -1956,10 +1956,7 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self,
|
|||
if (!glnx_opendirat (self->sysroot_fd, osdeploypath, TRUE, &os_deploy_dfd, error))
|
||||
return FALSE;
|
||||
|
||||
glnx_unref_object OstreeRepo *repo = NULL;
|
||||
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
OstreeRepo *repo = ostree_sysroot_repo (self);
|
||||
glnx_unref_object OstreeDeployment *merge_deployment = NULL;
|
||||
if (provided_merge_deployment != NULL)
|
||||
merge_deployment = g_object_ref (provided_merge_deployment);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ struct OstreeSysroot {
|
|||
|
||||
/* Only access through ostree_sysroot_get_repo() */
|
||||
OstreeRepo *repo;
|
||||
gboolean repo_opened;
|
||||
|
||||
OstreeSysrootDebugFlags debug_flags;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -729,6 +729,18 @@ ostree_sysroot_load (OstreeSysroot *self,
|
|||
return ostree_sysroot_load_if_changed (self, NULL, cancellable, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ensure_repo_opened (OstreeSysroot *self,
|
||||
GError **error)
|
||||
{
|
||||
if (self->repo_opened)
|
||||
return TRUE;
|
||||
if (!ostree_repo_open (self->repo, NULL, error))
|
||||
return FALSE;
|
||||
self->repo_opened = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_sysroot_load_if_changed (OstreeSysroot *self,
|
||||
gboolean *out_changed,
|
||||
|
|
@ -738,6 +750,13 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self,
|
|||
if (!ensure_sysroot_fd (self, error))
|
||||
return FALSE;
|
||||
|
||||
/* Here we also lazily initialize the repository. We didn't do this
|
||||
* previous to v2017.6, but we do now to support the error-free
|
||||
* ostree_sysroot_repo() API.
|
||||
*/
|
||||
if (!ensure_repo_opened (self, error))
|
||||
return FALSE;
|
||||
|
||||
int bootversion = 0;
|
||||
if (!read_current_bootversion (self, &bootversion, cancellable, error))
|
||||
return FALSE;
|
||||
|
|
@ -918,8 +937,7 @@ ostree_sysroot_get_repo (OstreeSysroot *self,
|
|||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
/* ostree_repo_open() is idempotent. */
|
||||
if (!ostree_repo_open (self->repo, cancellable, error))
|
||||
if (!ensure_repo_opened (self, error))
|
||||
return FALSE;
|
||||
|
||||
if (out_repo != NULL)
|
||||
|
|
@ -927,6 +945,24 @@ ostree_sysroot_get_repo (OstreeSysroot *self,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_sysroot_repo:
|
||||
* @self: Sysroot
|
||||
*
|
||||
* This function is a variant of ostree_sysroot_get_repo() that cannot fail, and
|
||||
* returns a cached repository. Can only be called after ostree_sysroot_load()
|
||||
* has been invoked successfully.
|
||||
*
|
||||
* Returns: (transfer none): The OSTree repository in sysroot @self.
|
||||
*/
|
||||
OstreeRepo *
|
||||
ostree_sysroot_repo (OstreeSysroot *self)
|
||||
{
|
||||
g_return_val_if_fail (self->loaded, NULL);
|
||||
g_assert (self->repo);
|
||||
return self->repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_sysroot_query_bootloader:
|
||||
* @sysroot: Sysroot
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
|
|||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepo * ostree_sysroot_repo (OstreeSysroot *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_sysroot_get_repo (OstreeSysroot *self,
|
||||
OstreeRepo **out_repo,
|
||||
|
|
|
|||
Loading…
Reference in New Issue