diff options
author | Colin Walters <walters@verbum.org> | 2023-05-03 08:24:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 08:24:21 -0400 |
commit | 8a2993a9d01cc358e4c2d936ca132174aabdc714 (patch) | |
tree | 5402001ab710dadfd51ba3e9071b044016030e3e /src/ostree/ot-builtin-checkout.c | |
parent | dd70c9b78cc34ccc7e638eda4c2df1ddd8ee3add (diff) | |
parent | c1044a02b28982ef6dd58af98b23a40482d26487 (diff) | |
download | ostree-8a2993a9d01cc358e4c2d936ca132174aabdc714.tar.gz |
Merge pull request #2565 from cgwalters/clang-format
Add .clang-format file + tree-wide: Run `clang-format`
Diffstat (limited to 'src/ostree/ot-builtin-checkout.c')
-rw-r--r-- | src/ostree/ot-builtin-checkout.c | 175 |
1 files changed, 89 insertions, 86 deletions
diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c index bfa43885..dfaec755 100644 --- a/src/ostree/ot-builtin-checkout.c +++ b/src/ostree/ot-builtin-checkout.c @@ -21,12 +21,12 @@ #include "config.h" -#include <string.h> #include <gio/gunixinputstream.h> +#include <string.h> -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_user_mode; @@ -50,10 +50,7 @@ static char *opt_selinux_policy; static char *opt_selinux_prefix; static gboolean -parse_fsync_cb (const char *option_name, - const char *value, - gpointer data, - GError **error) +parse_fsync_cb (const char *option_name, const char *value, gpointer data, GError **error) { gboolean val; @@ -71,32 +68,51 @@ parse_fsync_cb (const char *option_name, */ static GOptionEntry options[] = { - { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, "Do not change file ownership or initialize extended attributes", NULL }, - { "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Do not update or use the internal repository uncompressed object cache", NULL }, + { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, + "Do not change file ownership or initialize extended attributes", NULL }, + { "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, + "Do not update or use the internal repository uncompressed object cache", NULL }, { "subpath", 0, 0, G_OPTION_ARG_FILENAME, &opt_subpath, "Checkout sub-directory PATH", "PATH" }, - { "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, "Keep existing directories, overwrite existing files", NULL }, - { "union-add", 0, 0, G_OPTION_ARG_NONE, &opt_union_add, "Keep existing files/directories, only add new", NULL }, - { "union-identical", 0, 0, G_OPTION_ARG_NONE, &opt_union_identical, "When layering checkouts, error out if a file would be replaced with a different version, but add new files and directories", NULL }, - { "whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_whiteouts, "Process 'whiteout' (Docker style) entries", NULL }, - { "process-passthrough-whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_process_passthrough_whiteouts, "Enable overlayfs whiteout extraction into char 0:0 devices", NULL }, - { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, "Do nothing if specified path does not exist", NULL }, - { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, "Process many checkouts from standard input", NULL }, - { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, "Process many checkouts from input file", "FILE" }, - { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", "POLICY" }, - { "require-hardlinks", 'H', 0, G_OPTION_ARG_NONE, &opt_require_hardlinks, "Do not fall back to full copies if hardlinking fails", NULL }, - { "force-copy-zerosized", 'z', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_force_copy_zerosized, "Do not hardlink zero-sized files", NULL }, - { "force-copy", 'C', 0, G_OPTION_ARG_NONE, &opt_force_copy, "Never hardlink (but may reflink if available)", NULL }, - { "bareuseronly-dirs", 'M', 0, G_OPTION_ARG_NONE, &opt_bareuseronly_dirs, "Suppress mode bits outside of 0775 for directories (suid, world writable, etc.)", NULL }, - { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, "File containing list of files to skip", "FILE" }, - { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, "Set SELinux labels based on policy in root filesystem PATH (may be /); implies --force-copy", "PATH" }, - { "selinux-prefix", 0, 0, G_OPTION_ARG_STRING, &opt_selinux_prefix, "When setting SELinux labels, prefix all paths by PREFIX", "PREFIX" }, + { "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, + "Keep existing directories, overwrite existing files", NULL }, + { "union-add", 0, 0, G_OPTION_ARG_NONE, &opt_union_add, + "Keep existing files/directories, only add new", NULL }, + { "union-identical", 0, 0, G_OPTION_ARG_NONE, &opt_union_identical, + "When layering checkouts, error out if a file would be replaced with a different version, but " + "add new files and directories", + NULL }, + { "whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_whiteouts, + "Process 'whiteout' (Docker style) entries", NULL }, + { "process-passthrough-whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_process_passthrough_whiteouts, + "Enable overlayfs whiteout extraction into char 0:0 devices", NULL }, + { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, + "Do nothing if specified path does not exist", NULL }, + { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, + "Process many checkouts from standard input", NULL }, + { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, + "Process many checkouts from input file", "FILE" }, + { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", + "POLICY" }, + { "require-hardlinks", 'H', 0, G_OPTION_ARG_NONE, &opt_require_hardlinks, + "Do not fall back to full copies if hardlinking fails", NULL }, + { "force-copy-zerosized", 'z', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_force_copy_zerosized, + "Do not hardlink zero-sized files", NULL }, + { "force-copy", 'C', 0, G_OPTION_ARG_NONE, &opt_force_copy, + "Never hardlink (but may reflink if available)", NULL }, + { "bareuseronly-dirs", 'M', 0, G_OPTION_ARG_NONE, &opt_bareuseronly_dirs, + "Suppress mode bits outside of 0775 for directories (suid, world writable, etc.)", NULL }, + { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, + "File containing list of files to skip", "FILE" }, + { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, + "Set SELinux labels based on policy in root filesystem PATH (may be /); implies --force-copy", + "PATH" }, + { "selinux-prefix", 0, 0, G_OPTION_ARG_STRING, &opt_selinux_prefix, + "When setting SELinux labels, prefix all paths by PREFIX", "PREFIX" }, { NULL } }; static gboolean -handle_skiplist_line (const char *line, - void *data, - GError **error) +handle_skiplist_line (const char *line, void *data, GError **error) { GHashTable *files = data; g_hash_table_add (files, g_strdup (line)); @@ -104,10 +120,7 @@ handle_skiplist_line (const char *line, } static OstreeRepoCheckoutFilterResult -checkout_filter (OstreeRepo *self, - const char *path, - struct stat *st_buf, - gpointer user_data) +checkout_filter (OstreeRepo *self, const char *path, struct stat *st_buf, gpointer user_data) { GHashTable *skiplist = user_data; if (g_hash_table_contains (skiplist, path)) @@ -116,25 +129,22 @@ checkout_filter (OstreeRepo *self, } static gboolean -process_one_checkout (OstreeRepo *repo, - const char *resolved_commit, - const char *subpath, - const char *destination, - GCancellable *cancellable, - GError **error) +process_one_checkout (OstreeRepo *repo, const char *resolved_commit, const char *subpath, + const char *destination, GCancellable *cancellable, GError **error) { /* This strange code structure is to preserve testing * coverage of both `ostree_repo_checkout_tree` and * `ostree_repo_checkout_at` until such time as we have a more * convenient infrastructure for testing C APIs with data. */ - if (opt_disable_cache || opt_whiteouts || opt_require_hardlinks || - opt_union_add || opt_force_copy || opt_force_copy_zerosized || - opt_bareuseronly_dirs || opt_union_identical || - opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix || - opt_process_passthrough_whiteouts) + if (opt_disable_cache || opt_whiteouts || opt_require_hardlinks || opt_union_add || opt_force_copy + || opt_force_copy_zerosized || opt_bareuseronly_dirs || opt_union_identical + || opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix + || opt_process_passthrough_whiteouts) { - OstreeRepoCheckoutAtOptions checkout_options = { 0, }; + OstreeRepoCheckoutAtOptions checkout_options = { + 0, + }; /* do this early so option checking also catches force copy conflicts */ if (opt_selinux_policy) @@ -170,7 +180,7 @@ process_one_checkout (OstreeRepo *repo, if (subpath) checkout_options.subpath = subpath; - g_autoptr(OstreeSePolicy) policy = NULL; + g_autoptr (OstreeSePolicy) policy = NULL; if (opt_selinux_policy) { glnx_autofd int rootfs_dfd = -1; @@ -183,8 +193,8 @@ process_one_checkout (OstreeRepo *repo, checkout_options.sepolicy_prefix = opt_selinux_prefix; } - g_autoptr(GHashTable) skip_list = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) skip_list + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); if (opt_skiplist_file) { if (!ot_parse_file_by_line (opt_skiplist_file, handle_skiplist_line, skip_list, @@ -199,35 +209,31 @@ process_one_checkout (OstreeRepo *repo, checkout_options.force_copy_zerosized = opt_force_copy_zerosized; checkout_options.bareuseronly_dirs = opt_bareuseronly_dirs; - if (!ostree_repo_checkout_at (repo, &checkout_options, - AT_FDCWD, destination, - resolved_commit, + if (!ostree_repo_checkout_at (repo, &checkout_options, AT_FDCWD, destination, resolved_commit, cancellable, error)) return FALSE; } else { GError *tmp_error = NULL; - g_autoptr(GFile) root = NULL; - g_autoptr(GFile) destination_file = g_file_new_for_path (destination); + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) destination_file = g_file_new_for_path (destination); if (!ostree_repo_read_commit (repo, resolved_commit, &root, NULL, cancellable, error)) return FALSE; - g_autoptr(GFile) subtree = NULL; + g_autoptr (GFile) subtree = NULL; if (subpath) subtree = g_file_resolve_relative_path (root, subpath); else subtree = g_object_ref (root); - g_autoptr(GFileInfo) file_info - = g_file_query_info (subtree, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, &tmp_error); + g_autoptr (GFileInfo) file_info + = g_file_query_info (subtree, OSTREE_GIO_FAST_QUERYINFO, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &tmp_error); if (!file_info) { - if (opt_allow_noent - && g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if (opt_allow_noent && g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&tmp_error); /* Note early return */ @@ -242,8 +248,7 @@ process_one_checkout (OstreeRepo *repo, if (!ostree_repo_checkout_tree (repo, opt_user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0, opt_union ? OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES : 0, - destination_file, - OSTREE_REPO_FILE (subtree), file_info, + destination_file, OSTREE_REPO_FILE (subtree), file_info, cancellable, error)) return FALSE; } @@ -252,46 +257,44 @@ process_one_checkout (OstreeRepo *repo, } static gboolean -process_many_checkouts (OstreeRepo *repo, - const char *target, - GCancellable *cancellable, - GError **error) +process_many_checkouts (OstreeRepo *repo, const char *target, GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; gsize len; GError *temp_error = NULL; - g_autoptr(GInputStream) instream = NULL; - g_autoptr(GDataInputStream) datastream = NULL; + g_autoptr (GInputStream) instream = NULL; + g_autoptr (GDataInputStream) datastream = NULL; g_autofree char *revision = NULL; g_autofree char *subpath = NULL; g_autofree char *resolved_commit = NULL; if (opt_from_stdin) { - instream = (GInputStream*)g_unix_input_stream_new (0, FALSE); + instream = (GInputStream *)g_unix_input_stream_new (0, FALSE); } else { - g_autoptr(GFile) f = g_file_new_for_path (opt_from_file); + g_autoptr (GFile) f = g_file_new_for_path (opt_from_file); - instream = (GInputStream*)g_file_read (f, cancellable, error); + instream = (GInputStream *)g_file_read (f, cancellable, error); if (!instream) goto out; } datastream = g_data_input_stream_new (instream); - while ((revision = g_data_input_stream_read_upto (datastream, "", 1, &len, - cancellable, &temp_error)) != NULL) + while ( + (revision = g_data_input_stream_read_upto (datastream, "", 1, &len, cancellable, &temp_error)) + != NULL) { if (revision[0] == '\0') break; /* Read the null byte */ - (void) g_data_input_stream_read_byte (datastream, cancellable, NULL); + (void)g_data_input_stream_read_byte (datastream, cancellable, NULL); g_free (subpath); - subpath = g_data_input_stream_read_upto (datastream, "", 1, &len, - cancellable, &temp_error); + subpath = g_data_input_stream_read_upto (datastream, "", 1, &len, cancellable, &temp_error); if (temp_error) { g_propagate_error (error, temp_error); @@ -299,13 +302,12 @@ process_many_checkouts (OstreeRepo *repo, } /* Read the null byte */ - (void) g_data_input_stream_read_byte (datastream, cancellable, NULL); + (void)g_data_input_stream_read_byte (datastream, cancellable, NULL); if (!ostree_repo_resolve_rev (repo, revision, FALSE, &resolved_commit, error)) goto out; - if (!process_one_checkout (repo, resolved_commit, subpath, target, - cancellable, error)) + if (!process_one_checkout (repo, resolved_commit, subpath, target, cancellable, error)) { g_prefix_error (error, "Processing tree %s: ", resolved_commit); goto out; @@ -320,16 +322,18 @@ process_many_checkouts (OstreeRepo *repo, } ret = TRUE; - out: +out: return ret; } gboolean -ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT [DESTINATION]"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("COMMIT [DESTINATION]"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (opt_disable_fsync) @@ -362,9 +366,8 @@ ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error)) return FALSE; - if (!process_one_checkout (repo, resolved_commit, opt_subpath, - destination, - cancellable, error)) + if (!process_one_checkout (repo, resolved_commit, opt_subpath, destination, cancellable, + error)) return FALSE; } |