diff --git a/src/libostree/ostree-repo-static-delta-compilation.c b/src/libostree/ostree-repo-static-delta-compilation.c index eecaa8bc..4e4e7f9c 100644 --- a/src/libostree/ostree-repo-static-delta-compilation.c +++ b/src/libostree/ostree-repo-static-delta-compilation.c @@ -1483,7 +1483,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, descriptor_dir = g_file_get_parent (descriptor_path); - if (!gs_file_ensure_directory (descriptor_dir, TRUE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (AT_FDCWD, gs_file_get_path_cached (descriptor_dir), 0755, + cancellable, error)) goto out; for (i = 0; i < part_tempfiles->len; i++) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 1d0b2f93..84907c45 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -2228,8 +2228,14 @@ ostree_repo_create (OstreeRepo *self, if (!ostree_repo_mode_to_string (mode, &mode_str, error)) goto out; - if (!gs_file_ensure_directory (self->repodir, FALSE, cancellable, error)) - goto out; + if (mkdir (gs_file_get_path_cached (self->repodir), 0755) != 0) + { + if (errno != EEXIST) + { + glnx_set_error_from_errno (error); + goto out; + } + } config_data = g_string_new (DEFAULT_CONFIG_CONTENTS); g_string_append_printf (config_data, "mode=%s\n", mode_str); @@ -2632,7 +2638,8 @@ ostree_repo_open (OstreeRepo *self, if (self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2 && self->enable_uncompressed_cache) { - if (!gs_file_ensure_directory (self->uncompressed_objects_dir, TRUE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755, + cancellable, error)) goto out; if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE, &self->uncompressed_objects_dir_fd, diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index e05f5c29..bc8dde66 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -278,28 +278,29 @@ ostree_sysroot_ensure_initialized (OstreeSysroot *self, GError **error) { gboolean ret = FALSE; - g_autoptr(GFile) dir = NULL; - g_autoptr(GFile) ostree_dir = NULL; - g_autoptr(GFile) repo_dir = NULL; + struct stat stbuf; - ostree_dir = g_file_get_child (self->path, "ostree"); - repo_dir = g_file_get_child (ostree_dir, "repo"); - if (!gs_file_ensure_directory (repo_dir, TRUE, cancellable, error)) + if (!ensure_sysroot_fd (self, 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)) - { - glnx_unref_object OstreeRepo *repo = ostree_repo_new (repo_dir); - if (!ostree_repo_create (repo, OSTREE_REPO_MODE_BARE, + if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/repo", 0755, cancellable, error)) - goto out; + goto out; + + if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/deploy", 0755, + cancellable, error)) + goto out; + + if (fstatat (self->sysroot_fd, "ostree/repo/objects", &stbuf, 0) != 0) + { + if (errno == ENOENT) + { + g_autoptr(GFile) repo_dir = g_file_resolve_relative_path (self->path, "ostree/repo"); + glnx_unref_object OstreeRepo *repo = ostree_repo_new (repo_dir); + if (!ostree_repo_create (repo, OSTREE_REPO_MODE_BARE, + cancellable, error)) + goto out; + } } ret = TRUE; diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c index 0172f01c..1f122553 100644 --- a/src/ostree/ot-admin-builtin-init-fs.c +++ b/src/ostree/ot-admin-builtin-init-fs.c @@ -39,8 +39,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GErr GOptionContext *context; glnx_unref_object OstreeSysroot *sysroot = NULL; gboolean ret = FALSE; - g_autoptr(GFile) dir = NULL; - g_autoptr(GFile) child = NULL; + glnx_fd_close int root_dfd = -1; glnx_unref_object OstreeSysroot *target_sysroot = NULL; guint i; const char *normal_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"}; @@ -58,36 +57,31 @@ ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GErr goto out; } - dir = g_file_new_for_path (argv[1]); - target_sysroot = ostree_sysroot_new (dir); + if (!glnx_opendirat (AT_FDCWD, argv[1], TRUE, &root_dfd, error)) + goto out; + { g_autoptr(GFile) dir = g_file_new_for_path (argv[1]); + target_sysroot = ostree_sysroot_new (dir); + } for (i = 0; i < G_N_ELEMENTS(normal_toplevels); i++) { - child = g_file_get_child (dir, normal_toplevels[i]); - if (!gs_file_ensure_directory_mode (child, 0755, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (root_dfd, normal_toplevels[i], 0755, + cancellable, error)) goto out; - g_clear_object (&child); } - - child = g_file_get_child (dir, "root"); - if (!gs_file_ensure_directory_mode (child, 0700, cancellable, error)) + + if (!glnx_shutil_mkdir_p_at (root_dfd, "root", 0700, + cancellable, error)) goto out; - g_clear_object (&child); - child = g_file_get_child (dir, "tmp"); - if (!gs_file_ensure_directory_mode (child, 01777, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (root_dfd, "tmp", 01777, + cancellable, error)) goto out; - /* FIXME - we should be using an API that explicitly ignores umask; - */ - { - const char *path = gs_file_get_path_cached (child); - if (chmod (path, 01777) == -1) - { - gs_set_prefix_error_from_errno (error, errno, "chmod"); - goto out; - } - } - g_clear_object (&child); + if (fchmodat (root_dfd, "tmp", 01777, 0) == -1) + { + glnx_set_prefix_error_from_errno (error, "chmod: %s", "tmp"); + goto out; + } if (!ostree_sysroot_ensure_initialized (target_sysroot, cancellable, error)) goto out;