From b2d10dcaaa7c2bd65916887cadb046033cebdc4e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Sun, 26 Mar 2017 11:01:25 +0200 Subject: [PATCH] commit: Add --canonical-permissions argument This adds to file permission masks the same bitmask that will be applied to file objects in bare-user* repos. This will be needed in the testsuite to ensure that the things we commit will be expressable in bare-user-only repos. Closes: #750 Approved by: cgwalters --- src/libostree/ostree-repo-commit.c | 29 ++++++++++++++++++++++++----- src/libostree/ostree-repo.h | 4 +++- src/ostree/ot-builtin-commit.c | 4 ++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 80c35f44..0e85bcb1 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2236,17 +2236,33 @@ _ostree_repo_commit_modifier_apply (OstreeRepo *self, GFileInfo *file_info, GFileInfo **out_modified_info) { - OstreeRepoCommitFilterResult result; + OstreeRepoCommitFilterResult result = OSTREE_REPO_COMMIT_FILTER_ALLOW; GFileInfo *modified_info; - if (modifier == NULL || modifier->filter == NULL) + if (modifier == NULL || + (modifier->filter == NULL && + (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) == 0)) { *out_modified_info = g_object_ref (file_info); return OSTREE_REPO_COMMIT_FILTER_ALLOW; } modified_info = g_file_info_dup (file_info); - result = modifier->filter (self, path, modified_info, modifier->user_data); + if (modifier->filter) + result = modifier->filter (self, path, modified_info, modifier->user_data); + + if ((modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) != 0) + { + + if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR) + { + guint current_mode = g_file_info_get_attribute_uint32 (modified_info, "unix::mode"); + g_file_info_set_attribute_uint32 (modified_info, "unix::mode", current_mode | 0744); + } + g_file_info_set_attribute_uint32 (modified_info, "unix::uid", 0); + g_file_info_set_attribute_uint32 (modified_info, "unix::gid", 0); + } + *out_modified_info = modified_info; return result; @@ -2283,7 +2299,9 @@ apply_commit_filter (OstreeRepo *self, GFileInfo *file_info, GFileInfo **out_modified_info) { - if (modifier == NULL || modifier->filter == NULL) + if (modifier == NULL || + (modifier->filter == NULL && + (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) == 0)) { *out_modified_info = g_object_ref (file_info); return OSTREE_REPO_COMMIT_FILTER_ALLOW; @@ -2312,7 +2330,8 @@ get_modified_xattrs (OstreeRepo *self, ret_xattrs = modifier->xattr_callback (self, relpath, file_info, modifier->xattr_user_data); } - else if (!(modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS) > 0) + else if (!(modifier && (modifier->flags & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS | + OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) > 0) && !self->disable_xattrs) { if (path && OSTREE_IS_REPO_FILE (path)) diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 34685cc6..b88b980f 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -536,11 +536,13 @@ typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *r * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE: No special flags * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS: Do not process extended attributes * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES: Generate size information. + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions for bare-user-only mode. */ typedef enum { OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE = 0, OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS = (1 << 0), - OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES = (1 << 1) + OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES = (1 << 1), + OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS = (1 << 2), } OstreeRepoCommitModifierFlags; /** diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 218fb701..e6738c89 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -45,6 +45,7 @@ static gboolean opt_link_checkout_speedup; static gboolean opt_skip_if_unchanged; static gboolean opt_tar_autocreate_parents; static gboolean opt_no_xattrs; +static gboolean opt_canonical_permissions; static char **opt_trees; static gint opt_owner_uid = -1; static gint opt_owner_gid = -1; @@ -84,6 +85,7 @@ static GOptionEntry options[] = { { "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, "Add a key/value pair to detached metadata", "KEY=VALUE" }, { "owner-uid", 0, 0, G_OPTION_ARG_INT, &opt_owner_uid, "Set file ownership user id", "UID" }, { "owner-gid", 0, 0, G_OPTION_ARG_INT, &opt_owner_gid, "Set file ownership group id", "GID" }, + { "canonical-permissions", 0, 0, G_OPTION_ARG_NONE, &opt_canonical_permissions, "Canonicalize permissions in the same way bare-user does for hardlinked files", NULL }, { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Do not import extended attributes", NULL }, { "link-checkout-speedup", 0, 0, G_OPTION_ARG_NONE, &opt_link_checkout_speedup, "Optimize for commits of trees composed of hardlinks into the repository", NULL }, { "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, "When loading tar archives, automatically create parent directories as needed", NULL }, @@ -399,6 +401,8 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError if (opt_no_xattrs) flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS; + if (opt_canonical_permissions) + flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS; if (opt_generate_sizes) flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES; if (opt_disable_fsync)