From 104b8bf6fb75b4327a28802df7b16c74a163f90f Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 13 Jul 2015 17:12:18 -0400 Subject: [PATCH] repo: Add a "sysroot-path" property Adds ostree_repo_new_for_sysroot_path() to specify a system root path. OstreeRepo otherwise uses _ostree_get_default_sysroot_path(). --- doc/ostree-sections.txt | 1 + src/libostree/ostree-repo-private.h | 1 + src/libostree/ostree-repo.c | 58 +++++++++++++++++++++++++---- src/libostree/ostree-repo.h | 3 ++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt index 1e488e00..7d412b46 100644 --- a/doc/ostree-sections.txt +++ b/doc/ostree-sections.txt @@ -216,6 +216,7 @@ OstreeRepo OstreeRepoMode ostree_repo_mode_from_string ostree_repo_new +ostree_repo_new_for_sysroot_path ostree_repo_new_default ostree_repo_open ostree_repo_set_disable_fsync diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index b124e227..cf6b8034 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -54,6 +54,7 @@ struct OstreeRepo { GFile *uncompressed_objects_dir; int uncompressed_objects_dir_fd; GFile *config_file; + GFile *sysroot_dir; GFile *transaction_lock_path; GHashTable *txn_refs; diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 2fe46634..34132279 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -83,7 +83,8 @@ typedef struct { enum { PROP_0, - PROP_PATH + PROP_PATH, + PROP_SYSROOT_PATH }; enum { @@ -520,6 +521,7 @@ ostree_repo_finalize (GObject *object) if (self->uncompressed_objects_dir_fd != -1) (void) close (self->uncompressed_objects_dir_fd); g_clear_object (&self->config_file); + g_clear_object (&self->sysroot_dir); g_clear_object (&self->transaction_lock_path); @@ -554,8 +556,10 @@ ostree_repo_set_property(GObject *object, switch (prop_id) { case PROP_PATH: - /* Canonicalize */ - self->repodir = g_file_new_for_path (gs_file_get_path_cached (g_value_get_object (value))); + self->repodir = g_value_dup_object (value); + break; + case PROP_SYSROOT_PATH: + self->sysroot_dir = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -576,6 +580,9 @@ ostree_repo_get_property(GObject *object, case PROP_PATH: g_value_set_object (value, self->repodir); break; + case PROP_SYSROOT_PATH: + g_value_set_object (value, self->sysroot_dir); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -599,6 +606,10 @@ ostree_repo_constructed (GObject *object) self->state_dir = g_file_get_child (self->repodir, "state"); self->config_file = g_file_get_child (self->repodir, "config"); + /* Ensure the "sysroot-path" property is set. */ + if (self->sysroot_dir == NULL) + self->sysroot_dir = g_object_ref (_ostree_get_default_sysroot_path ()); + G_OBJECT_CLASS (ostree_repo_parent_class)->constructed (object); } @@ -620,6 +631,14 @@ ostree_repo_class_init (OstreeRepoClass *klass) G_TYPE_FILE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, + PROP_SYSROOT_PATH, + g_param_spec_object ("sysroot-path", + "", + "", + G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + /** * OstreeRepo::gpg-verify-result: * @self: an #OstreeRepo @@ -683,9 +702,29 @@ ostree_repo_new (GFile *path) } static GFile * -get_default_repo_path (void) +get_default_repo_path (GFile *sysroot_path) { - return g_file_new_for_path ("/ostree/repo"); + if (sysroot_path == NULL) + sysroot_path = _ostree_get_default_sysroot_path (); + + return g_file_resolve_relative_path (sysroot_path, "ostree/repo"); +} + +/** + * ostree_repo_new_for_sysroot_path: + * @repo_path: Path to a repository + * @sysroot_path: Path to the system root + * + * Creates a new #OstreeRepo instance, taking the system root path explicitly + * instead of assuming "/". + * + * Returns: (transfer full): An accessor object for the OSTree repository located at @repo_path. + */ +OstreeRepo * +ostree_repo_new_for_sysroot_path (GFile *repo_path, + GFile *sysroot_path) +{ + return g_object_new (OSTREE_TYPE_REPO, "path", repo_path, "sysroot-path", sysroot_path, NULL); } /** @@ -714,7 +753,7 @@ ostree_repo_new_default (void) g_autoptr(GFile) repo_path = NULL; if (envvar == NULL || *envvar == '\0') - repo_path = get_default_repo_path (); + repo_path = get_default_repo_path (NULL); else repo_path = g_file_new_for_path (envvar); @@ -731,7 +770,12 @@ ostree_repo_new_default (void) gboolean ostree_repo_is_system (OstreeRepo *repo) { - g_autoptr(GFile) default_repo_path = get_default_repo_path (); + g_autoptr(GFile) default_repo_path = NULL; + + g_return_val_if_fail (OSTREE_IS_REPO (repo), FALSE); + + default_repo_path = get_default_repo_path (repo->sysroot_dir); + return g_file_equal (repo->repodir, default_repo_path); } diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index e6937b5f..84b0deb8 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -44,6 +44,9 @@ GType ostree_repo_get_type (void); OstreeRepo* ostree_repo_new (GFile *path); +OstreeRepo* ostree_repo_new_for_sysroot_path (GFile *repo_path, + GFile *sysroot_path); + OstreeRepo* ostree_repo_new_default (void); gboolean ostree_repo_open (OstreeRepo *self,