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:
Colin Walters authored and Atomic Bot committed 2017-05-26 19:17:59 +00:00
1 parent ed430b45de
commit 9bf8a8503a
7 files changed
+47 -15

No files matched your search

+38 -2
View File
@@ -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