|
rpm-build |
0fba15 |
#!/bin/bash
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# Copyright (C) 2016 Colin Walters <walters@verbum.org>
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
# modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
# License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
# version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
# Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
# License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
# Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
set -euo pipefail
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
. $(dirname $0)/libtest.sh
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
skip_without_fuse
|
|
rpm-build |
0fba15 |
skip_without_user_xattrs
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
setup_test_repository "bare"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "1..11"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
mkdir mnt
|
|
rpm-build |
0fba15 |
# The default content set amazingly doesn't have a non-broken link
|
|
rpm-build |
0fba15 |
ln -s firstfile files/firstfile-link
|
|
rpm-build |
0fba15 |
$OSTREE commit -b test2 --tree=dir=files
|
|
rpm-build |
0fba15 |
$OSTREE checkout -H test2 checkout-test2
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
rofiles-fuse checkout-test2 mnt
|
|
rpm-build |
0fba15 |
cleanup_fuse() {
|
|
rpm-build |
0fba15 |
fusermount -u ${test_tmpdir}/mnt || true
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
libtest_exit_cmds+=(cleanup_fuse)
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/firstfile first
|
|
rpm-build |
0fba15 |
echo "ok mount"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test open(O_TRUNC) directly and via symlink
|
|
rpm-build |
0fba15 |
for path in firstfile{,-link}; do
|
|
rpm-build |
0fba15 |
if cp /dev/null mnt/${path} 2>err.txt; then
|
|
rpm-build |
0fba15 |
assert_not_reached "inplace mutation ${path}"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
assert_file_has_content err.txt "Read-only file system"
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/firstfile first
|
|
rpm-build |
0fba15 |
assert_file_has_content checkout-test2/firstfile first
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
echo "ok failed inplace mutation (open O_TRUNCATE)"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test chmod
|
|
rpm-build |
0fba15 |
if chmod 0600 mnt/firstfile 2>err.txt; then
|
|
rpm-build |
0fba15 |
assert_not_reached "chmod inplace"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
assert_file_has_content err.txt "chmod:.*Read-only file system"
|
|
rpm-build |
0fba15 |
# Test chown with regfiles and symlinks
|
|
rpm-build |
0fba15 |
for path in firstfile baz/alink; do
|
|
rpm-build |
0fba15 |
if chown -h $(id -u) mnt/${path} 2>err.txt; then
|
|
rpm-build |
0fba15 |
assert_not_reached "chown inplace ${path}"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
assert_file_has_content err.txt "chown:.*Read-only file system"
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
# And test via dereferencing a symlink
|
|
rpm-build |
0fba15 |
if chown $(id -u) mnt/firstfile-link 2>err.txt; then
|
|
rpm-build |
0fba15 |
assert_not_reached "chown inplace firstfile-link"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
assert_file_has_content err.txt "chown:.*Read-only file system"
|
|
rpm-build |
0fba15 |
echo "ok failed mutation chmod + chown"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test creating new files, using chown + chmod on them as well
|
|
rpm-build |
0fba15 |
echo anewfile-for-fuse > mnt/anewfile-for-fuse
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/anewfile-for-fuse anewfile-for-fuse
|
|
rpm-build |
0fba15 |
assert_file_has_content checkout-test2/anewfile-for-fuse anewfile-for-fuse
|
|
rpm-build |
0fba15 |
ln -s anewfile-for-fuse mnt/anewfile-for-fuse-link
|
|
rpm-build |
0fba15 |
# And also test modifications through a symlink
|
|
rpm-build |
0fba15 |
echo writevialink > mnt/anewfile-for-fuse-link
|
|
rpm-build |
0fba15 |
for path in anewfile-for-fuse{,-link}; do
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/${path} writevialink
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
chown $(id -u) mnt/anewfile-for-fuse-link
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
mkdir mnt/newfusedir
|
|
rpm-build |
0fba15 |
for i in $(seq 5); do
|
|
rpm-build |
0fba15 |
echo ${i}-morenewfuse-${i} > mnt/newfusedir/test-morenewfuse.${i}
|
|
rpm-build |
0fba15 |
chmod 0600 mnt/newfusedir/test-morenewfuse.${i}
|
|
rpm-build |
0fba15 |
chown $(id -u) mnt/newfusedir/test-morenewfuse.${i}
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
assert_file_has_content checkout-test2/newfusedir/test-morenewfuse.3 3-morenewfuse-3
|
|
rpm-build |
0fba15 |
echo "ok new content"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
rm mnt/baz/cow
|
|
rpm-build |
0fba15 |
assert_not_has_file checkout-test2/baz/cow
|
|
rpm-build |
0fba15 |
rm mnt/baz/another -rf
|
|
rpm-build |
0fba15 |
assert_not_has_dir checkout-test2/baz/another
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "ok deletion"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
${CMD_PREFIX} ostree --repo=repo commit -b test2 -s fromfuse --link-checkout-speedup --tree=dir=checkout-test2
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "ok commit"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
${CMD_PREFIX} ostree --repo=repo checkout -U test2 mnt/test2-checkout-copy-fallback
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/test2-checkout-copy-fallback/anewfile-for-fuse writevialink
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if ${CMD_PREFIX} ostree --repo=repo checkout -UH test2 mnt/test2-checkout-copy-hardlinked 2>err.txt; then
|
|
rpm-build |
0fba15 |
assert_not_reached "Checking out via hardlinks across mountpoint unexpectedly succeeded!"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
assert_file_has_content err.txt "Unable to do hardlink checkout across devices"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "ok checkout copy fallback"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# check that O_RDONLY|O_CREAT is handled correctly; used by flock(1) at least
|
|
rpm-build |
0fba15 |
flock mnt/nonexistent-file echo "ok create file in ro mode"
|
|
rpm-build |
0fba15 |
echo "ok flock"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# And now with --copyup enabled
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
copyup_reset() {
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
fusermount -u mnt
|
|
rpm-build |
0fba15 |
rm checkout-test2 -rf
|
|
rpm-build |
0fba15 |
$OSTREE checkout -H test2 checkout-test2
|
|
rpm-build |
0fba15 |
rofiles-fuse --copyup checkout-test2 mnt
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
assert_test_file() {
|
|
rpm-build |
0fba15 |
t=$1
|
|
rpm-build |
0fba15 |
f=$2
|
|
rpm-build |
0fba15 |
if ! test ${t} "${f}"; then
|
|
rpm-build |
0fba15 |
ls -al "${f}"
|
|
rpm-build |
0fba15 |
fatal "Failed test ${t} ${f}"
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
copyup_reset
|
|
rpm-build |
0fba15 |
assert_file_has_content mnt/firstfile first
|
|
rpm-build |
0fba15 |
echo "ok copyup mount"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test O_TRUNC directly
|
|
rpm-build |
0fba15 |
firstfile_orig_inode=$(stat -c %i checkout-test2/firstfile)
|
|
rpm-build |
0fba15 |
echo -n truncating > mnt/firstfile
|
|
rpm-build |
0fba15 |
assert_streq "$(cat mnt/firstfile)" truncating
|
|
rpm-build |
0fba15 |
firstfile_new_inode=$(stat -c %i checkout-test2/firstfile)
|
|
rpm-build |
0fba15 |
assert_not_streq "${firstfile_orig_inode}" "${firstfile_new_inode}"
|
|
rpm-build |
0fba15 |
assert_test_file -f checkout-test2/firstfile
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
copyup_reset
|
|
rpm-build |
0fba15 |
firstfile_link_orig_inode=$(stat -c %i checkout-test2/firstfile-link)
|
|
rpm-build |
0fba15 |
firstfile_orig_inode=$(stat -c %i checkout-test2/firstfile)
|
|
rpm-build |
0fba15 |
# Now write via the symlink
|
|
rpm-build |
0fba15 |
echo -n truncating > mnt/firstfile-link
|
|
rpm-build |
0fba15 |
assert_streq "$(cat mnt/firstfile)" truncating
|
|
rpm-build |
0fba15 |
firstfile_new_inode=$(stat -c %i checkout-test2/firstfile)
|
|
rpm-build |
0fba15 |
firstfile_link_new_inode=$(stat -c %i checkout-test2/firstfile-link)
|
|
rpm-build |
0fba15 |
assert_not_streq "${firstfile_orig_inode}" "${firstfile_new_inode}"
|
|
rpm-build |
0fba15 |
assert_streq "${firstfile_link_orig_inode}" "${firstfile_link_new_inode}"
|
|
rpm-build |
0fba15 |
assert_test_file -f checkout-test2/firstfile
|
|
rpm-build |
0fba15 |
# Verify we didn't replace the link with a regfile somehow
|
|
rpm-build |
0fba15 |
assert_test_file -L checkout-test2/firstfile-link
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# These both end up creating new files; in the sed case we'll then do a rename()
|
|
rpm-build |
0fba15 |
copyup_reset
|
|
rpm-build |
0fba15 |
echo "hello new file" > mnt/a-new-non-copyup-file
|
|
rpm-build |
0fba15 |
assert_file_has_content_literal mnt/a-new-non-copyup-file "hello new file"
|
|
rpm-build |
0fba15 |
sed -i -e s,first,second, mnt/firstfile
|
|
rpm-build |
0fba15 |
assert_file_has_content_literal mnt/firstfile "second"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "ok copyup"
|