From 30963766c7b22779210464c47cc4d0c0c171debf Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 27 Jul 2016 10:38:36 +0200 Subject: [PATCH] libostree: new function ostree_repo_checkout_at Provide a gobject introspection safe version for `ostree_repo_checkout_tree_at'. Signed-off-by: Giuseppe Scrivano Closes: #417 Approved by: cgwalters --- apidoc/ostree-sections.txt | 1 + src/libostree/libostree.sym | 1 + src/libostree/ostree-repo-checkout.c | 70 ++++++++++++++++++++++------ src/libostree/ostree-repo.h | 50 +++++++++++++++++--- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index 8b6337f7..37c7e11e 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -344,6 +344,7 @@ OstreeRepoCheckoutMode OstreeRepoCheckoutOverwriteMode ostree_repo_checkout_tree ostree_repo_checkout_tree_at +ostree_repo_checkout_at ostree_repo_checkout_gc ostree_repo_read_commit OstreeRepoListObjectsFlags diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym index 04e36453..3d05ac0e 100644 --- a/src/libostree/libostree.sym +++ b/src/libostree/libostree.sym @@ -355,4 +355,5 @@ LIBOSTREE_2016.8 { global: ostree_checksum_b64_to_bytes; ostree_checksum_b64_from_bytes; + ostree_repo_checkout_at; } LIBOSTREE_2016.7; diff --git a/src/libostree/ostree-repo-checkout.c b/src/libostree/ostree-repo-checkout.c index 265270b1..1010d239 100644 --- a/src/libostree/ostree-repo-checkout.c +++ b/src/libostree/ostree-repo-checkout.c @@ -104,14 +104,14 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self, static gboolean fsync_is_enabled (OstreeRepo *self, - OstreeRepoCheckoutOptions *options) + OstreeRepoCheckoutAtOptions *options) { return !(self->disable_fsync || options->disable_fsync); } static gboolean write_regular_file_content (OstreeRepo *self, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, GOutputStream *output, GFileInfo *file_info, GVariant *xattrs, @@ -181,7 +181,7 @@ write_regular_file_content (OstreeRepo *self, static gboolean checkout_file_from_input_at (OstreeRepo *self, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, GFileInfo *file_info, GVariant *xattrs, GInputStream *input, @@ -264,7 +264,7 @@ checkout_file_from_input_at (OstreeRepo *self, */ static gboolean checkout_file_unioning_from_input_at (OstreeRepo *repo, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, GFileInfo *file_info, GVariant *xattrs, GInputStream *input, @@ -334,7 +334,7 @@ checkout_file_unioning_from_input_at (OstreeRepo *repo, static gboolean checkout_file_hardlink (OstreeRepo *self, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, const char *loose_path, int destination_dfd, const char *destination_name, @@ -391,7 +391,7 @@ checkout_file_hardlink (OstreeRepo *self, static gboolean checkout_one_file_at (OstreeRepo *repo, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, GFile *source, GFileInfo *source_info, int destination_dfd, @@ -627,7 +627,7 @@ checkout_one_file_at (OstreeRepo *repo, */ static gboolean checkout_tree_at (OstreeRepo *self, - OstreeRepoCheckoutOptions *options, + OstreeRepoCheckoutAtOptions *options, int destination_parent_fd, const char *destination_name, OstreeRepoFile *source, @@ -813,7 +813,7 @@ ostree_repo_checkout_tree (OstreeRepo *self, GCancellable *cancellable, GError **error) { - OstreeRepoCheckoutOptions options = { 0, }; + OstreeRepoCheckoutAtOptions options = { 0, }; options.mode = mode; options.overwrite_mode = overwrite_mode; @@ -827,7 +827,7 @@ ostree_repo_checkout_tree (OstreeRepo *self, } /** - * ostree_repo_checkout_tree_at: + * ostree_repo_checkout_tree_at: (skip) * @self: Repo * @options: (allow-none): Options * @destination_dfd: Directory FD for destination @@ -837,7 +837,7 @@ ostree_repo_checkout_tree (OstreeRepo *self, * @error: Error * * Similar to ostree_repo_checkout_tree(), but uses directory-relative - * paths for the destination, uses a new `OstreeRepoCheckoutOptions`, + * paths for the destination, uses a new `OstreeRepoCheckoutAtOptions`, * and takes a commit checksum and optional subpath pair, rather than * requiring use of `GFile` APIs for the caller. * @@ -846,19 +846,63 @@ ostree_repo_checkout_tree (OstreeRepo *self, * cache. */ gboolean -ostree_repo_checkout_tree_at (OstreeRepo *self, +ostree_repo_checkout_tree_at (OstreeRepo *self, OstreeRepoCheckoutOptions *options, int destination_dfd, const char *destination_path, const char *commit, GCancellable *cancellable, GError **error) +{ + OstreeRepoCheckoutAtOptions new_opts = {0, }; + new_opts.mode = options->mode; + new_opts.overwrite_mode = options->overwrite_mode; + new_opts.enable_uncompressed_cache = options->enable_uncompressed_cache; + new_opts.disable_fsync = options->disable_fsync; + new_opts.process_whiteouts = options->process_whiteouts; + new_opts.no_copy_fallback = options->no_copy_fallback; + new_opts.subpath = options->subpath; + new_opts.devino_to_csum_cache = options->devino_to_csum_cache; + return ostree_repo_checkout_at (self, &new_opts, destination_dfd, + destination_path, commit, cancellable, error); +} + +/** + * ostree_repo_checkout_at: + * @self: Repo + * @options: (allow-none): Options + * @destination_dfd: Directory FD for destination + * @destination_path: Directory for destination + * @commit: Checksum for commit + * @cancellable: Cancellable + * @error: Error + * + * Similar to ostree_repo_checkout_tree(), but uses directory-relative + * paths for the destination, uses a new `OstreeRepoCheckoutAtOptions`, + * and takes a commit checksum and optional subpath pair, rather than + * requiring use of `GFile` APIs for the caller. + * + * It also replaces ostree_repo_checkout_at() which was not safe to + * use with GObject introspection. + * + * Note in addition that unlike ostree_repo_checkout_tree(), the + * default is not to use the repository-internal uncompressed objects + * cache. + */ +gboolean +ostree_repo_checkout_at (OstreeRepo *self, + OstreeRepoCheckoutAtOptions *options, + int destination_dfd, + const char *destination_path, + const char *commit, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; g_autoptr(GFile) commit_root = NULL; g_autoptr(GFile) target_dir = NULL; g_autoptr(GFileInfo) target_info = NULL; - OstreeRepoCheckoutOptions default_options = { 0, }; + OstreeRepoCheckoutAtOptions default_options = { 0, }; if (!options) { @@ -920,7 +964,7 @@ devino_equal (gconstpointer a, * ostree_repo_write_directory_to_mtree() using a (normally modified) * directory. In order for OSTree to optimally detect just the new * files, use this function and fill in the `devino_to_csum_cache` - * member of `OstreeRepoCheckoutOptions`, then call + * member of `OstreeRepoCheckoutAtOptions`, then call * ostree_repo_commit_set_devino_cache(). * * Returns: (transfer full): Newly allocated cache diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 872f9b81..28766a24 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -624,13 +624,14 @@ typedef struct { } OstreeRepoImportArchiveOptions; _OSTREE_PUBLIC -gboolean ostree_repo_import_archive_to_mtree (OstreeRepo *self, +gboolean ostree_repo_import_archive_to_mtree (OstreeRepo *self, OstreeRepoImportArchiveOptions *opts, - void *archive, /* Really struct archive * */ - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error); + void *archive, /* Really struct archive * */ + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GCancellable *cancellable, + GError **error); + /** * OstreeRepoExportArchiveOptions: * @@ -735,7 +736,7 @@ ostree_repo_checkout_tree (OstreeRepo *self, GError **error); /** - * OstreeRepoCheckoutOptions: + * OstreeRepoCheckoutOptions: (skip) * * An extensible options structure controlling checkout. Ensure that * you have entirely zeroed the structure, then set just the desired @@ -761,6 +762,32 @@ typedef struct { gpointer unused_ptrs[7]; } OstreeRepoCheckoutOptions; +/** + * OstreeRepoCheckoutAtOptions: + * + * An extensible options structure controlling checkout. Ensure that + * you have entirely zeroed the structure, then set just the desired + * options. This is used by ostree_repo_checkout_at() which + * supercedes previous separate enumeration usage in + * ostree_repo_checkout_tree() and ostree_repo_checkout_tree_at(). + */ +typedef struct { + OstreeRepoCheckoutMode mode; + OstreeRepoCheckoutOverwriteMode overwrite_mode; + + gboolean enable_uncompressed_cache; + gboolean disable_fsync; + gboolean process_whiteouts; + gboolean no_copy_fallback; + + const char *subpath; + + OstreeRepoDevInoCache *devino_to_csum_cache; + + int unused_ints[6]; + gpointer unused_ptrs[7]; +} OstreeRepoCheckoutAtOptions; + _OSTREE_PUBLIC GType ostree_repo_devino_cache_get_type (void); _OSTREE_PUBLIC @@ -779,6 +806,15 @@ gboolean ostree_repo_checkout_tree_at (OstreeRepo *self, GCancellable *cancellable, GError **error); +_OSTREE_PUBLIC +gboolean ostree_repo_checkout_at (OstreeRepo *self, + OstreeRepoCheckoutAtOptions *options, + int destination_dfd, + const char *destination_path, + const char *commit, + GCancellable *cancellable, + GError **error); + _OSTREE_PUBLIC gboolean ostree_repo_checkout_gc (OstreeRepo *self, GCancellable *cancellable,