[ostree] sysroot: Cache an OstreeRepo instance



commit a6bbcf2ba7b8c6e8c478bd776e1042bc7990b942
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Apr 17 09:00:17 2015 -0400

    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.

 src/libostree/ostree-sysroot-private.h |    3 +++
 src/libostree/ostree-sysroot.c         |   17 +++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h
index 03224de..69310c3 100644
--- a/src/libostree/ostree-sysroot-private.h
+++ b/src/libostree/ostree-sysroot-private.h
@@ -40,6 +40,9 @@ struct OstreeSysroot {
   int bootversion;
   int subbootversion;
   OstreeDeployment *booted_deployment;
+
+  /* Only access through ostree_sysroot_get_repo() */
+  OstreeRepo *repo;
 };
 
 gboolean
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
index 2afc59c..6d62240 100644
--- a/src/libostree/ostree-sysroot.c
+++ b/src/libostree/ostree-sysroot.c
@@ -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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]