sysroot: Cache an OstreeRepo instance

Rather than returning a new OstreeRepo instance in each call to
ostree_sysroot_get_repo(), cache one internally so the same instance
is returned each time.
This commit is contained in:
Matthew Barnes 2015-04-17 09:00:17 -04:00
parent 6a7b9defb8
commit a6bbcf2ba7
2 changed files with 14 additions and 6 deletions

View File

@ -40,6 +40,9 @@ struct OstreeSysroot {
int bootversion;
int subbootversion;
OstreeDeployment *booted_deployment;
/* Only access through ostree_sysroot_get_repo() */
OstreeRepo *repo;
};
gboolean

View File

@ -64,6 +64,7 @@ ostree_sysroot_finalize (GObject *object)
g_clear_object (&self->path);
g_clear_object (&self->sepolicy);
g_clear_object (&self->repo);
G_OBJECT_CLASS (ostree_sysroot_parent_class)->finalize (object);
}
@ -111,9 +112,13 @@ static void
ostree_sysroot_constructed (GObject *object)
{
OstreeSysroot *self = OSTREE_SYSROOT (object);
gs_unref_object GFile *repo_path = NULL;
g_assert (self->path != NULL);
repo_path = g_file_resolve_relative_path (self->path, "ostree/repo");
self->repo = ostree_repo_new (repo_path);
G_OBJECT_CLASS (ostree_sysroot_parent_class)->constructed (object);
}
@ -875,15 +880,15 @@ ostree_sysroot_get_repo (OstreeSysroot *self,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object OstreeRepo *ret_repo = NULL;
gs_unref_object GFile *repo_path = g_file_resolve_relative_path (self->path, "ostree/repo");
ret_repo = ostree_repo_new (repo_path);
if (!ostree_repo_open (ret_repo, cancellable, error))
/* ostree_repo_open() is idempotent. */
if (!ostree_repo_open (self->repo, cancellable, error))
goto out;
if (out_repo != NULL)
*out_repo = g_object_ref (self->repo);
ret = TRUE;
ot_transfer_out_value (out_repo, &ret_repo);
out:
return ret;
}