Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit: automatically skip xattrs in bare-user-only mode #2418

Merged
merged 4 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libostree/ostree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
if (OSTREE_IS_REPO_FILE (a))
{
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile*)a);
if (repo->disable_xattrs)
if (repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
flags |= OSTREE_DIFF_FLAGS_IGNORE_XATTRS;
}
if (OSTREE_IS_REPO_FILE (b))
{
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile*)b);
if (repo->disable_xattrs)
if (repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
flags |= OSTREE_DIFF_FLAGS_IGNORE_XATTRS;
}

Expand Down
5 changes: 3 additions & 2 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3382,8 +3382,9 @@ get_final_xattrs (OstreeRepo *self,
/* track whether the returned xattrs differ from the file on disk */
gboolean modified = TRUE;
const gboolean skip_xattrs = (modifier &&
modifier->flags & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS |
OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) > 0;
(modifier->flags & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS |
OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) > 0) ||
self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY;

/* fetch on-disk xattrs if needed & not disabled */
g_autoptr(GVariant) original_xattrs = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/libostree/ostree-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *r
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL: If a devino cache hit is found, skip modifier filters (non-directories only); Since: 2017.14
*
* Flags modifying commit behavior. In bare-user-only mode, @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS
* is automatically enabled.
* and @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS are automatically enabled.
*
*/
typedef enum {
Expand Down
6 changes: 3 additions & 3 deletions src/ostree/ot-builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
goto out;
}

if (opt_no_xattrs)
if (opt_canonical_permissions || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS;
if (opt_no_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS;
if (opt_consume)
flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME;
Expand All @@ -581,8 +583,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
opt_link_checkout_speedup = TRUE; /* Imply this */
flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL;
}
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)
Expand Down
19 changes: 10 additions & 9 deletions tests/basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ COMMIT_ARGS=""
DIFF_ARGS=""
if is_bare_user_only_repo repo; then
# In bare-user-only repos we can only represent files with uid/gid 0, no
# xattrs and canonical permissions, so we need to commit them as such, or
# we end up with repos that don't pass fsck
COMMIT_ARGS="--no-xattrs"
DIFF_ARGS="--owner-uid=0 --owner-gid=0 --no-xattrs"
# xattrs and canonical permissions.
DIFF_ARGS="--owner-uid=0 --owner-gid=0"
# Also, since we can't check out uid=0 files we need to check out in user mode
CHECKOUT_U_ARG="-U"
CHECKOUT_H_ARGS="-U -H"
Expand Down Expand Up @@ -314,7 +312,7 @@ echo "ok diff revisions"

cd ${test_tmpdir}/checkout-test2-4
echo afile > oh-look-a-file
$OSTREE diff test2 ./ > ${test_tmpdir}/diff-test2-2
$OSTREE diff ${DIFF_ARGS} test2 ./ > ${test_tmpdir}/diff-test2-2
rm oh-look-a-file
cd ${test_tmpdir}
assert_file_has_content diff-test2-2 'A *oh-look-a-file$'
Expand Down Expand Up @@ -787,11 +785,14 @@ cd ${test_tmpdir}
rm files -rf && mkdir files
mkdir files/worldwritable-dir
chmod a+w files/worldwritable-dir
$CMD_PREFIX ostree --repo=repo commit -b content-with-dir-world-writable --tree=dir=files
$OSTREE commit ${COMMIT_ARGS} -b content-with-dir-world-writable --tree=dir=files
$OSTREE fsck
rm dir-co -rf
$CMD_PREFIX ostree --repo=repo checkout -U -H -M content-with-dir-world-writable dir-co
assert_file_has_mode dir-co/worldwritable-dir 775
if ! is_bare_user_only_repo repo; then
$OSTREE checkout -U -H -M content-with-dir-world-writable dir-co
if is_bare_user_only_repo repo; then
assert_file_has_mode dir-co/worldwritable-dir 755
else
assert_file_has_mode dir-co/worldwritable-dir 775
rm dir-co -rf
$CMD_PREFIX ostree --repo=repo checkout -U -H content-with-dir-world-writable dir-co
assert_file_has_mode dir-co/worldwritable-dir 777
Expand Down
25 changes: 8 additions & 17 deletions tests/test-basic-user-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set -euo pipefail

mode="bare-user-only"
setup_test_repository "$mode"
extra_basic_tests=7
extra_basic_tests=6
. $(dirname $0)/basic-test.sh

$CMD_PREFIX ostree --version > version.yaml
Expand Down Expand Up @@ -63,8 +63,8 @@ rm files -rf && mkdir files
echo "a group writable file" > files/some-group-writable
chmod 0664 files/some-group-writable
$CMD_PREFIX ostree --repo=repo-input commit -b content-with-group-writable --tree=dir=files
$CMD_PREFIX ostree pull-local --repo=repo repo-input
$CMD_PREFIX ostree --repo=repo checkout -U -H content-with-group-writable groupwritable-co
$OSTREE pull-local repo-input
$OSTREE checkout -U -H content-with-group-writable groupwritable-co
assert_file_has_mode groupwritable-co/some-group-writable 664
echo "ok supported group writable"

Expand All @@ -75,8 +75,8 @@ rm files -rf && mkdir files
mkdir files/worldwritable-dir
chmod a+w files/worldwritable-dir
$CMD_PREFIX ostree --repo=repo-input commit -b content-with-dir-world-writable --tree=dir=files
$CMD_PREFIX ostree pull-local --repo=repo repo-input
$CMD_PREFIX ostree --repo=repo checkout -U -H content-with-dir-world-writable dir-co
$OSTREE pull-local repo-input
$OSTREE checkout -U -H content-with-dir-world-writable dir-co
assert_file_has_mode dir-co/worldwritable-dir 775
echo "ok didn't make world-writable dir"

Expand Down Expand Up @@ -106,21 +106,12 @@ rm repo -rf
ostree_repo_init repo init --mode=bare-user-only
rm files -rf && mkdir files
echo afile > files/afile
chmod 0777 files/afile
$OSTREE commit ${COMMIT_ARGS} -b perms files
rm out -rf
$OSTREE checkout --force-copy perms out
$OSTREE checkout ${CHECKOUT_H_ARGS} --union-identical perms out
$OSTREE fsck
echo "ok checkout checksum with canonical perms"

cd ${test_tmpdir}
rm repo -rf
ostree_repo_init repo init --mode=bare-user-only
rm files -rf && mkdir files
echo afile > files/afile
$OSTREE commit ${COMMIT_ARGS} -b perms files
rm out -rf
$OSTREE checkout --force-copy perms out
assert_file_has_mode out/afile 755
$OSTREE checkout ${CHECKOUT_H_ARGS} --union-identical perms out
$OSTREE fsck
assert_file_has_mode out/afile 755
echo "ok automatic canonical perms for bare-user-only"