|
rpm-build |
0fba15 |
#!/bin/bash
|
|
rpm-build |
0fba15 |
#
|
|
rpm-build |
0fba15 |
# Copyright (C) 2011 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 |
if ! ostree --version | grep -q -e '- libarchive'; then
|
|
rpm-build |
0fba15 |
echo "1..0 #SKIP no libarchive support compiled in"
|
|
rpm-build |
0fba15 |
exit 0
|
|
rpm-build |
0fba15 |
fi
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
. $(dirname $0)/libtest.sh
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
echo "1..18"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
setup_test_repository "bare"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
mkdir foo
|
|
rpm-build |
0fba15 |
cd foo
|
|
rpm-build |
0fba15 |
mkdir -p usr/bin usr/lib
|
|
rpm-build |
0fba15 |
echo contents > usr/bin/foo
|
|
rpm-build |
0fba15 |
touch usr/bin/foo0
|
|
rpm-build |
0fba15 |
ln usr/bin/foo usr/bin/bar
|
|
rpm-build |
0fba15 |
ln usr/bin/foo0 usr/bin/bar0
|
|
rpm-build |
0fba15 |
ln -s foo usr/bin/sl
|
|
rpm-build |
0fba15 |
mkdir -p usr/local/bin
|
|
rpm-build |
0fba15 |
ln usr/bin/foo usr/local/bin/baz
|
|
rpm-build |
0fba15 |
ln usr/bin/foo0 usr/local/bin/baz0
|
|
rpm-build |
0fba15 |
ln usr/bin/sl usr/local/bin/slhl
|
|
rpm-build |
0fba15 |
touch usr/bin/setuidme
|
|
rpm-build |
0fba15 |
touch usr/bin/skipme
|
|
rpm-build |
0fba15 |
echo "a library" > usr/lib/libfoo.so
|
|
rpm-build |
0fba15 |
echo "another library" > usr/lib/libbar.so
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Create a tar archive
|
|
rpm-build |
0fba15 |
tar -c -z -f ../foo.tar.gz .
|
|
rpm-build |
0fba15 |
# Create a cpio archive
|
|
rpm-build |
0fba15 |
find . | cpio -o -H newc > ../foo.cpio
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ..
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cat > statoverride.txt <
|
|
rpm-build |
0fba15 |
2048 /usr/bin/setuidme
|
|
rpm-build |
0fba15 |
EOF
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cat > skiplist.txt <
|
|
rpm-build |
0fba15 |
/usr/bin/skipme
|
|
rpm-build |
0fba15 |
EOF
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
$OSTREE commit -s "from tar" -b test-tar \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.tar.gz
|
|
rpm-build |
0fba15 |
echo "ok tar commit"
|
|
rpm-build |
0fba15 |
$OSTREE commit -s "from cpio" -b test-cpio \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.cpio
|
|
rpm-build |
0fba15 |
echo "ok cpio commit"
|
|
rpm-build |
0fba15 |
cat foo.tar.gz | $OSTREE commit -s "from tar" -b test-tar-stdin \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=-
|
|
rpm-build |
0fba15 |
echo "ok tar commit from stdin"
|
|
rpm-build |
0fba15 |
cat foo.cpio | $OSTREE commit -s "from cpio" -b test-cpio-stdin \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=-
|
|
rpm-build |
0fba15 |
echo "ok cpio commit from stdin"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
assert_valid_checkout () {
|
|
rpm-build |
0fba15 |
ref=$1
|
|
rpm-build |
0fba15 |
rm test-${ref}-checkout -rf
|
|
rpm-build |
0fba15 |
$OSTREE checkout test-${ref} test-${ref}-checkout
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
assert_valid_content test-${ref}-checkout
|
|
rpm-build |
0fba15 |
rm -rf test-${ref}-checkout
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
assert_valid_content () {
|
|
rpm-build |
0fba15 |
dn=$1
|
|
rpm-build |
0fba15 |
cd ${dn}
|
|
rpm-build |
0fba15 |
# basic content check
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/bin/foo contents
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/bin/bar contents
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/local/bin/baz contents
|
|
rpm-build |
0fba15 |
assert_file_empty usr/bin/foo0
|
|
rpm-build |
0fba15 |
assert_file_empty usr/bin/bar0
|
|
rpm-build |
0fba15 |
assert_file_empty usr/local/bin/baz0
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/lib/libfoo.so 'a library'
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/lib/libbar.so 'another library'
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# hardlinks
|
|
rpm-build |
0fba15 |
assert_files_hardlinked usr/bin/foo usr/bin/bar
|
|
rpm-build |
0fba15 |
assert_files_hardlinked usr/bin/foo usr/local/bin/baz
|
|
rpm-build |
0fba15 |
assert_files_hardlinked usr/bin/foo0 usr/bin/bar0
|
|
rpm-build |
0fba15 |
assert_files_hardlinked usr/bin/foo0 usr/local/bin/baz0
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# symlinks
|
|
rpm-build |
0fba15 |
assert_symlink_has_content usr/bin/sl foo
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/bin/sl contents
|
|
rpm-build |
0fba15 |
# ostree checkout doesn't care if two symlinks are actually hardlinked
|
|
rpm-build |
0fba15 |
# together (which is fine). checking that it's also a symlink is good enough.
|
|
rpm-build |
0fba15 |
assert_symlink_has_content usr/local/bin/slhl foo
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# stat override
|
|
rpm-build |
0fba15 |
test -u usr/bin/setuidme
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# skip list
|
|
rpm-build |
0fba15 |
test ! -f usr/bin/skipme
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
assert_valid_checkout tar
|
|
rpm-build |
0fba15 |
echo "ok tar contents"
|
|
rpm-build |
0fba15 |
assert_valid_checkout cpio
|
|
rpm-build |
0fba15 |
echo "ok cpio contents"
|
|
rpm-build |
0fba15 |
assert_valid_checkout tar-stdin
|
|
rpm-build |
0fba15 |
echo "ok tar contents from stdin"
|
|
rpm-build |
0fba15 |
assert_valid_checkout cpio-stdin
|
|
rpm-build |
0fba15 |
echo "ok cpio contents from stdin"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
mkdir multicommit-files
|
|
rpm-build |
0fba15 |
cd multicommit-files
|
|
rpm-build |
0fba15 |
mkdir -p files1/subdir files2/subdir
|
|
rpm-build |
0fba15 |
echo "to be overwritten file" > files1/testfile
|
|
rpm-build |
0fba15 |
echo "not overwritten" > files1/otherfile
|
|
rpm-build |
0fba15 |
echo "overwriting file" > files2/testfile
|
|
rpm-build |
0fba15 |
ln -s "to-be-overwritten-symlink" files1/testsymlink
|
|
rpm-build |
0fba15 |
ln -s "overwriting-symlink" files2/testsymlink
|
|
rpm-build |
0fba15 |
ln -s "not overwriting symlink" files2/ohersymlink
|
|
rpm-build |
0fba15 |
echo "original" > files1/subdir/original
|
|
rpm-build |
0fba15 |
echo "new" > files2/subdir/new
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
tar -c -C files1 -z -f files1.tar.gz .
|
|
rpm-build |
0fba15 |
tar -c -C files2 -z -f files2.tar.gz .
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
$OSTREE commit -s 'multi tar' -b multicommit --tree=tar=files1.tar.gz --tree=tar=files2.tar.gz
|
|
rpm-build |
0fba15 |
echo "ok tar multicommit"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
$OSTREE checkout multicommit multicommit-checkout
|
|
rpm-build |
0fba15 |
cd multicommit-checkout
|
|
rpm-build |
0fba15 |
assert_file_has_content testfile "overwriting file"
|
|
rpm-build |
0fba15 |
assert_file_has_content otherfile "not overwritten"
|
|
rpm-build |
0fba15 |
assert_file_has_content subdir/original "original"
|
|
rpm-build |
0fba15 |
assert_file_has_content subdir/new "new"
|
|
rpm-build |
0fba15 |
echo "ok tar multicommit contents"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}/multicommit-files
|
|
rpm-build |
0fba15 |
tar -c -C files1 -z -f partial.tar.gz subdir/original
|
|
rpm-build |
0fba15 |
$OSTREE commit -s 'partial' -b partial --tar-autocreate-parents --tree=tar=partial.tar.gz
|
|
rpm-build |
0fba15 |
echo "ok tar partial commit"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
$OSTREE checkout partial partial-checkout
|
|
rpm-build |
0fba15 |
cd partial-checkout
|
|
rpm-build |
0fba15 |
assert_file_has_content subdir/original "original"
|
|
rpm-build |
0fba15 |
echo "ok tar partial commit contents"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
uid=$(id -u)
|
|
rpm-build |
0fba15 |
gid=$(id -g)
|
|
rpm-build |
0fba15 |
autocreate_args="--tar-autocreate-parents --owner-uid=${uid} --owner-gid=${gid}"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
tar -cf empty.tar.gz -T /dev/null
|
|
rpm-build |
0fba15 |
$OSTREE commit -b tar-empty ${autocreate_args} --tree=tar=empty.tar.gz
|
|
rpm-build |
0fba15 |
$OSTREE ls tar-empty > ls.txt
|
|
rpm-build |
0fba15 |
assert_file_has_content ls.txt "d00755 ${uid} ${gid} 0 /"
|
|
rpm-build |
0fba15 |
echo "ok tar autocreate with owner uid/gid"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# noop pathname filter
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
$OSTREE commit -b test-tar ${autocreate_args} \
|
|
rpm-build |
0fba15 |
--tar-pathname-filter='^nosuchfile/,nootherfile/' \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.tar.gz
|
|
rpm-build |
0fba15 |
rm test-tar-co -rf
|
|
rpm-build |
0fba15 |
$OSTREE checkout test-tar test-tar-co
|
|
rpm-build |
0fba15 |
assert_valid_content ${test_tmpdir}/test-tar-co
|
|
rpm-build |
0fba15 |
echo "ok tar pathname filter prefix (noop)"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Add a prefix
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
# Update the metadata overrides matching our pathname filter
|
|
rpm-build |
0fba15 |
for f in statoverride.txt skiplist.txt; do
|
|
rpm-build |
0fba15 |
sed -i -e 's,/usr/,/foo/usr/,' $f
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
$OSTREE commit -b test-tar ${autocreate_args} \
|
|
rpm-build |
0fba15 |
--tar-pathname-filter='^,foo/' \
|
|
rpm-build |
0fba15 |
--statoverride=statoverride.txt \
|
|
rpm-build |
0fba15 |
--skip-list=skiplist.txt \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.tar.gz
|
|
rpm-build |
0fba15 |
rm test-tar-co -rf
|
|
rpm-build |
0fba15 |
$OSTREE checkout test-tar test-tar-co
|
|
rpm-build |
0fba15 |
assert_has_dir test-tar-co/foo
|
|
rpm-build |
0fba15 |
assert_valid_content ${test_tmpdir}/test-tar-co/foo
|
|
rpm-build |
0fba15 |
echo "ok tar pathname filter prefix"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test anchored and not-anchored
|
|
rpm-build |
0fba15 |
for filter in '^usr/bin/,usr/sbin/' '/bin/,/sbin/'; do
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
$OSTREE commit -b test-tar ${autocreate_args} \
|
|
rpm-build |
0fba15 |
--tar-pathname-filter=$filter \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.tar.gz
|
|
rpm-build |
0fba15 |
rm test-tar-co -rf
|
|
rpm-build |
0fba15 |
$OSTREE checkout test-tar test-tar-co
|
|
rpm-build |
0fba15 |
cd test-tar-co
|
|
rpm-build |
0fba15 |
# Check that we just had usr/bin → usr/sbin
|
|
rpm-build |
0fba15 |
assert_not_has_file usr/bin/foo
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/sbin/foo contents
|
|
rpm-build |
0fba15 |
assert_not_has_file usr/sbin/libfoo.so
|
|
rpm-build |
0fba15 |
assert_file_has_content usr/lib/libfoo.so 'a library'
|
|
rpm-build |
0fba15 |
echo "ok tar pathname filter modification: ${filter}"
|
|
rpm-build |
0fba15 |
done
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
# Test sizes metadata. This needs an archive repo, so a separate repo is used.
|
|
rpm-build |
0fba15 |
cd ${test_tmpdir}
|
|
rpm-build |
0fba15 |
rm -rf repo2
|
|
rpm-build |
0fba15 |
ostree_repo_init repo2 --mode=archive
|
|
rpm-build |
0fba15 |
${CMD_PREFIX} ostree --repo=repo2 commit \
|
|
rpm-build |
0fba15 |
-s "from tar" -b test-tar \
|
|
rpm-build |
0fba15 |
--generate-sizes \
|
|
rpm-build |
0fba15 |
--tree=tar=foo.tar.gz
|
|
rpm-build |
0fba15 |
${CMD_PREFIX} ostree --repo=repo2 show --print-sizes test-tar > sizes.txt
|
|
rpm-build |
0fba15 |
assert_file_has_content sizes.txt 'Compressed size (needed/total): 0[ ]bytes/1.1[ ]kB'
|
|
rpm-build |
0fba15 |
assert_file_has_content sizes.txt 'Unpacked size (needed/total): 0[ ]bytes/900[ ]bytes'
|
|
rpm-build |
0fba15 |
assert_file_has_content sizes.txt 'Number of objects (needed/total): 0/12'
|
|
rpm-build |
0fba15 |
echo "ok tar sizes metadata"
|