diff options
author | Colin Walters <walters@verbum.org> | 2013-09-15 15:16:56 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-09-15 15:16:56 -0400 |
commit | 6f929ca5af114da00030bd83d8b100706d0eebef (patch) | |
tree | b98b1ec6673841a478b2e25a6fb9d4e335fcfc33 /src/libostree | |
parent | 35bab87691fc0997e13f40680fbb9afd416ce1b9 (diff) | |
download | ostree-6f929ca5af114da00030bd83d8b100706d0eebef.tar.gz |
libostree: Move sysroot initialization API here
Diffstat (limited to 'src/libostree')
-rw-r--r-- | src/libostree/ostree-sysroot.c | 49 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot.h | 4 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index 4fa27af0..3f1fa376 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -174,3 +174,52 @@ ostree_sysroot_get_path (OstreeSysroot *self) { return self->path; } + +/** + * ostree_sysroot_ensure_initialized: + * @self: + * + * Ensure that @self is set up as a valid rootfs, by creating + * /ostree/repo, among other things. + */ +gboolean +ostree_sysroot_ensure_initialized (OstreeSysroot *self, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + gs_unref_object GFile *dir = NULL; + gs_unref_object GFile *ostree_dir = NULL; + + ostree_dir = g_file_get_child (self->path, "ostree"); + + g_clear_object (&dir); + dir = g_file_get_child (ostree_dir, "repo"); + if (!gs_file_ensure_directory (dir, TRUE, cancellable, error)) + goto out; + + g_clear_object (&dir); + dir = g_file_get_child (ostree_dir, "deploy"); + if (!gs_file_ensure_directory (dir, TRUE, cancellable, error)) + goto out; + + g_clear_object (&dir); + dir = ot_gfile_get_child_build_path (ostree_dir, "repo", "objects", NULL); + if (!g_file_query_exists (dir, NULL)) + { + gs_free char *opt_repo_arg = g_strdup_printf ("--repo=%s/repo", + gs_file_get_path_cached (ostree_dir)); + + if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL, + cancellable, error, + "ostree", opt_repo_arg, "init", NULL)) + { + g_prefix_error (error, "Failed to initialize repository: "); + goto out; + } + } + + ret = TRUE; + out: + return ret; +} diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h index b983383b..490d5d2c 100644 --- a/src/libostree/ostree-sysroot.h +++ b/src/libostree/ostree-sysroot.h @@ -38,5 +38,9 @@ OstreeSysroot* ostree_sysroot_new_default (void); GFile *ostree_sysroot_get_path (OstreeSysroot *self); +gboolean ostree_sysroot_ensure_initialized (OstreeSysroot *self, + GCancellable *cancellable, + GError **error); + G_END_DECLS |