From: Matthew Barnes Date: Tue, 14 Jul 2015 15:58:00 +0000 (-0400) Subject: core: Add _ostree_get_default_sysroot_path() X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~657 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f2ddf10d4e166326ad5eb7cd1bcbe57e5be6b06e;p=ostree.git core: Add _ostree_get_default_sysroot_path() Returns a GFile for the default system root, which is usually the root directory unless overridden by the OSTREE_SYSROOT environment variable (which is mainly intended for testing). --- diff --git a/src/libostree/ostree-core-private.h b/src/libostree/ostree-core-private.h index c3c21b20..a92aa4c7 100644 --- a/src/libostree/ostree-core-private.h +++ b/src/libostree/ostree-core-private.h @@ -143,4 +143,7 @@ GVariant * _ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata, GBytes *signature_bytes); +GFile * +_ostree_get_default_sysroot_path (void); + G_END_DECLS diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index 88dcf645..a3d13e56 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -1967,3 +1967,30 @@ _ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata, return g_variant_dict_end (&metadata_dict); } + +/** + * _ostree_get_default_sysroot_path: + * + * Returns a #GFile for the default system root, which is usually the root + * directory ("/") unless overridden by the %OSTREE_SYSROOT environment + * variable. + * + * Returns: a #GFile for the default system root + */ +GFile * +_ostree_get_default_sysroot_path (void) +{ + static gsize default_sysroot_path_initialized; + static GFile *default_sysroot_path; + + if (g_once_init_enter (&default_sysroot_path_initialized)) + { + const char *path = g_getenv ("OSTREE_SYSROOT"); + if (path == NULL || *path == '\0') + path = "/"; + default_sysroot_path = g_file_new_for_path (path); + g_once_init_leave (&default_sysroot_path_initialized, 1); + } + + return default_sysroot_path; +}