2017-01-19 14:23:30 +03:00
# This file is to be sourced, not executed
2014-12-05 16:28:16 +03:00
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
2016-01-27 19:44:10 +03:00
set -euo pipefail
2014-12-05 16:28:16 +03:00
2017-08-31 18:44:35 +03:00
echo " 1.. $(( 72 + ${ extra_basic_tests :- 0 } )) "
2017-02-17 18:22:43 +03:00
$CMD_PREFIX ostree --version > version.yaml
python -c 'import yaml; yaml.safe_load(open("version.yaml"))'
echo "ok yaml version"
2014-12-05 16:28:16 +03:00
2017-03-26 12:03:47 +03:00
CHECKOUT_U_ARG = ""
2017-09-09 00:07:45 +03:00
CHECKOUT_H_ARGS = "-H"
2017-03-26 12:03:47 +03:00
COMMIT_ARGS = ""
DIFF_ARGS = ""
2017-06-02 17:09:23 +03:00
if is_bare_user_only_repo repo; then
2017-03-26 12:03:47 +03:00
# 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 = "--canonical-permissions"
DIFF_ARGS = "--owner-uid=0 --owner-gid=0 --no-xattrs"
# Also, since we can't check out uid=0 files we need to check out in user mode
CHECKOUT_U_ARG = "-U"
2017-09-09 00:07:45 +03:00
CHECKOUT_H_ARGS = "-U -H"
else
if grep -E -q '^mode=bare-user' repo/config; then
CHECKOUT_H_ARGS = "-U -H"
fi
2017-03-26 12:03:47 +03:00
fi
2017-04-05 20:11:34 +03:00
validate_checkout_basic( ) {
( cd $1 ;
assert_has_file firstfile
assert_has_file baz/cow
assert_file_has_content baz/cow moo
assert_has_file baz/deeper/ohyeah
2017-04-18 17:13:45 +03:00
assert_symlink_has_content somelink nosuchfile
2017-04-05 20:11:34 +03:00
)
}
2014-12-05 16:28:16 +03:00
$OSTREE checkout test2 checkout-test2
2017-04-05 20:11:34 +03:00
validate_checkout_basic checkout-test2
2017-04-21 22:43:17 +03:00
if grep -q 'mode=bare$' repo/config; then
assert_not_streq $( stat -c '%h' checkout-test2/firstfile) 1
fi
2014-12-05 16:28:16 +03:00
echo "ok checkout"
2017-04-05 20:11:34 +03:00
# Note this tests bare-user *and* bare-user-only
rm checkout-test2 -rf
2017-04-21 22:43:17 +03:00
if grep -q bare-user repo/config; then
2017-04-05 20:11:34 +03:00
$OSTREE checkout -U -H test2 checkout-test2
else
$OSTREE checkout -H test2 checkout-test2
fi
validate_checkout_basic checkout-test2
rm checkout-test2 -rf
# Only do these tests on bare-user/bare, not bare-user-only
# since the latter automatically synthesizes -U if it's not passed.
2017-06-02 17:09:23 +03:00
if ! is_bare_user_only_repo repo; then
2017-04-05 20:11:34 +03:00
if grep -q bare-user repo/config; then
if $OSTREE checkout -H test2 checkout-test2 2>err.txt; then
assert_not_reached "checkout -H worked?"
fi
assert_file_has_content err.txt "User repository.*requires.*user"
else
if $OSTREE checkout -U -H test2 checkout-test2 2>err.txt; then
assert_not_reached "checkout -H worked?"
fi
assert_file_has_content err.txt "Bare repository mode cannot hardlink in user"
fi
fi
echo "ok checkout -H"
2017-04-21 22:43:17 +03:00
rm checkout-test2 -rf
$OSTREE checkout -C test2 checkout-test2
for file in firstfile baz/cow baz/alink; do
assert_streq $( stat -c '%h' checkout-test2/$file ) 1
done
echo "ok checkout -C"
2014-12-05 16:28:16 +03:00
$OSTREE rev-parse test2
$OSTREE rev-parse 'test2^'
2017-01-17 18:16:31 +03:00
$OSTREE rev-parse 'test2^^' 2>/dev/null && fatal "rev-parse test2^^ unexpectedly succeeded!"
2014-12-05 16:28:16 +03:00
echo "ok rev-parse"
checksum = $( $OSTREE rev-parse test2)
partial = ${ checksum : 0 : 6 }
echo "partial:" $partial
echo "corresponds to:" $checksum
$OSTREE rev-parse test2 > checksum
$OSTREE rev-parse $partial > partial-results
assert_file_has_content checksum $( cat partial-results)
echo "ok shortened checksum"
2015-03-03 15:13:54 +03:00
( cd repo && ${ CMD_PREFIX } ostree rev-parse test2)
2014-12-05 16:28:16 +03:00
echo "ok repo-in-cwd"
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
rm test-repo -rf
ostree_repo_init test-repo --mode= bare-user
ostree_repo_init test-repo --mode= bare-user
rm test-repo -rf
echo "ok repo-init on existing repo"
fi
if ! skip_one_without_user_xattrs; then
rm test-repo -rf
ostree_repo_init test-repo --mode= bare-user
${ CMD_PREFIX } ostree --repo= test-repo refs
rm -rf test-repo/tmp
${ CMD_PREFIX } ostree --repo= test-repo refs
assert_has_dir test-repo/tmp
echo "ok autocreate tmp"
fi
2017-07-19 17:35:06 +03:00
2017-04-05 20:11:34 +03:00
rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2
2014-12-05 16:28:16 +03:00
cd checkout-test2
rm firstfile
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s delete
2014-12-05 16:28:16 +03:00
cd $test_tmpdir
$OSTREE checkout test2 $test_tmpdir /checkout-test2-2
cd $test_tmpdir /checkout-test2-2
assert_not_has_file firstfile
assert_has_file baz/saucer
echo "ok removal"
mkdir -p a/nested/tree
echo one > a/nested/tree/1
echo two2 > a/nested/2
echo 3 > a/nested/3
touch a/4
echo fivebaby > a/5
touch a/6
echo whee > 7
mkdir -p another/nested/tree
echo anotherone > another/nested/tree/1
echo whee2 > another/whee
# FIXME - remove grep for .
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Another commit"
2014-12-05 16:28:16 +03:00
echo "ok commit"
cd ${ test_tmpdir }
$OSTREE checkout test2 $test_tmpdir /checkout-test2-3
cd checkout-test2-3
assert_has_file a/nested/2
assert_file_has_content a/nested/2 'two2'
echo "ok stdin contents"
cd ${ test_tmpdir } /checkout-test2-3
echo 4 > four
mkdir -p yet/another/tree
echo leaf > yet/another/tree/green
echo helloworld > yet/message
rm a/5
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Current directory"
2014-12-05 16:28:16 +03:00
echo "ok cwd commit"
cd ${ test_tmpdir }
$OSTREE checkout test2 $test_tmpdir /checkout-test2-4
cd checkout-test2-4
assert_file_has_content yet/another/tree/green 'leaf'
assert_file_has_content four '4'
echo "ok cwd contents"
2016-03-25 18:03:32 +03:00
cd ${ test_tmpdir }
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-no-parent -s '' $test_tmpdir /checkout-test2-4
2016-03-25 18:03:32 +03:00
assert_streq $( $OSTREE log test2-no-parent | grep '^commit' | wc -l) "1"
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-no-parent -s '' --parent= none $test_tmpdir /checkout-test2-4
2016-03-25 18:03:32 +03:00
assert_streq $( $OSTREE log test2-no-parent | grep '^commit' | wc -l) "1"
echo "ok commit no parent"
2016-05-23 21:49:37 +03:00
cd ${ test_tmpdir }
2017-06-22 22:49:22 +03:00
# Do the --bind-ref=<the other test branch>, so we store both branches sorted
# in metadata and thus the checksums remain the same.
empty_rev = $( $OSTREE commit ${ COMMIT_ARGS } -b test2-no-subject --bind-ref= test2-no-subject-2 -s '' --timestamp= "2005-10-29 12:43:29 +0000" $test_tmpdir /checkout-test2-4)
omitted_rev = $( $OSTREE commit ${ COMMIT_ARGS } -b test2-no-subject-2 --bind-ref= test2-no-subject --timestamp= "2005-10-29 12:43:29 +0000" $test_tmpdir /checkout-test2-4)
2016-05-23 21:49:37 +03:00
assert_streq $empty_rev $omitted_rev
echo "ok commit no subject"
2017-02-11 19:24:15 +03:00
cd ${ test_tmpdir }
cat >commitmsg.txt <<EOF
This is a long
commit message.
Build-Host: foo.example.com
Crunchy-With-Extra-Ketchup: true
EOF
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b branch-with-commitmsg -F commitmsg.txt -s 'a message' $test_tmpdir /checkout-test2-4
2017-02-11 19:24:15 +03:00
$OSTREE log branch-with-commitmsg > log.txt
assert_file_has_content log.txt '^ *This is a long$'
assert_file_has_content log.txt '^ *Build-Host:.*example.com$'
assert_file_has_content log.txt '^ *Crunchy-With.*true$'
$OSTREE refs --delete branch-with-commitmsg
echo "ok commit body file"
2016-03-25 18:03:32 +03:00
cd ${ test_tmpdir }
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-custom-parent -s '' $test_tmpdir /checkout-test2-4
$OSTREE commit ${ COMMIT_ARGS } -b test2-custom-parent -s '' $test_tmpdir /checkout-test2-4
$OSTREE commit ${ COMMIT_ARGS } -b test2-custom-parent -s '' $test_tmpdir /checkout-test2-4
2016-03-25 18:03:32 +03:00
assert_streq $( $OSTREE log test2-custom-parent | grep '^commit' | wc -l) "3"
prevparent = $( $OSTREE rev-parse test2-custom-parent^)
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-custom-parent -s '' --parent= ${ prevparent } $test_tmpdir /checkout-test2-4
2016-03-25 18:03:32 +03:00
assert_streq $( $OSTREE log test2-custom-parent | grep '^commit' | wc -l) "3"
echo "ok commit custom parent"
2016-03-29 17:53:50 +03:00
cd ${ test_tmpdir }
2017-03-26 12:03:47 +03:00
orphaned_rev = $( $OSTREE commit ${ COMMIT_ARGS } --orphan -s " $( date) " $test_tmpdir /checkout-test2-4)
2016-03-29 17:53:50 +03:00
$OSTREE ls ${ orphaned_rev } >/dev/null
$OSTREE prune --refs-only
if $OSTREE ls ${ orphaned_rev } 2>err.txt; then
assert_not_reached "Found orphaned commit"
fi
assert_file_has_content err.txt "No such metadata object"
echo "ok commit orphaned"
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
$OSTREE diff test2^ test2 > diff-test2
assert_file_has_content diff-test2 'D */a/5'
assert_file_has_content diff-test2 'A */yet$'
assert_file_has_content diff-test2 'A */yet/message$'
assert_file_has_content diff-test2 'A */yet/another/tree/green$'
echo "ok diff revisions"
cd ${ test_tmpdir } /checkout-test2-4
echo afile > oh-look-a-file
$OSTREE diff 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$'
echo "ok diff cwd"
2017-02-08 23:59:38 +03:00
cd ${ test_tmpdir } /checkout-test2-4
2017-03-26 12:03:47 +03:00
$OSTREE diff ${ DIFF_ARGS } test2 ./ > ${ test_tmpdir } /diff-test2
2017-02-08 23:59:38 +03:00
assert_file_empty ${ test_tmpdir } /diff-test2
2017-03-26 12:03:47 +03:00
$OSTREE diff ${ DIFF_ARGS } test2 --owner-uid= $(( ` id -u` + 1 )) ./ > ${ test_tmpdir } /diff-test2
2017-02-08 23:59:38 +03:00
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet$'
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet/message$'
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet/another/tree/green$'
echo "ok diff file with different uid"
2017-03-26 12:03:47 +03:00
$OSTREE diff ${ DIFF_ARGS } test2 --owner-gid= $(( ` id -g` + 1 )) ./ > ${ test_tmpdir } /diff-test2
2017-02-08 23:59:38 +03:00
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet$'
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet/message$'
assert_file_has_content ${ test_tmpdir } /diff-test2 'M */yet/another/tree/green$'
echo "ok diff file with different gid"
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir } /checkout-test2-4
rm four
mkdir four
touch four/other
$OSTREE diff test2 ./ > ${ test_tmpdir } /diff-test2-2
cd ${ test_tmpdir }
assert_file_has_content diff-test2-2 'M */four$'
echo "ok diff file changing type"
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
mkdir repo2
# Use a different mode to test hardlinking metadata only
if grep -q 'mode=archive' repo/config || is_bare_user_only_repo repo; then
opposite_mode = bare-user
else
opposite_mode = archive
fi
ostree_repo_init repo2 --mode= $opposite_mode
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo
test2_commitid = $( ${ CMD_PREFIX } ostree --repo= repo rev-parse test2)
test2_commit_relpath = /objects/${ test2_commitid : 0 : 2 } /${ test2_commitid : 2 } .commit
assert_files_hardlinked repo/${ test2_commit_relpath } repo2/${ test2_commit_relpath }
echo "ok pull-local (hardlinking metadata)"
2017-06-12 20:38:52 +03:00
fi
2014-12-05 16:28:16 +03:00
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
rm repo2 -rf && mkdir repo2
ostree_repo_init repo2 --mode= $opposite_mode
${ CMD_PREFIX } ostree --repo= repo2 pull-local --bareuseronly-files repo test2
${ CMD_PREFIX } ostree --repo= repo2 fsck -q
echo "ok pull-local --bareuseronly-files"
fi
2017-06-12 22:06:19 +03:00
# This is mostly a copy of the suid test in test-basic-user-only.sh,
# but for the `pull --bareuseronly-files` case.
cd ${ test_tmpdir }
rm repo-input -rf
ostree_repo_init repo-input init --mode= archive
cd ${ test_tmpdir }
cat > statoverride.txt <<EOF
2048 /some-setuid
EOF
mkdir -p files/
echo "a setuid file" > files/some-setuid
chmod 0644 files/some-setuid
$CMD_PREFIX ostree --repo= repo-input commit -b content-with-suid --statoverride= statoverride.txt --tree= dir = files
if $CMD_PREFIX ostree pull-local --repo= repo --bareuseronly-files repo-input content-with-suid 2>err.txt; then
assert_not_reached "copying suid file with --bareuseronly-files worked?"
fi
assert_file_has_content err.txt 'object.*\.file: invalid mode.*with bits 040.*'
echo "ok pull-local (bareuseronly files)"
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
${ CMD_PREFIX } ostree --repo= repo2 checkout ${ CHECKOUT_U_ARG } test2 test2-checkout-from-local-clone
cd test2-checkout-from-local-clone
assert_file_has_content yet/another/tree/green 'leaf'
echo "ok local clone checkout"
fi
2014-12-05 16:28:16 +03:00
$OSTREE checkout -U test2 checkout-user-test2
echo "ok user checkout"
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Another commit" --tree= ref = test2
2014-12-05 16:28:16 +03:00
echo "ok commit from ref"
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Another commit with modifier" --tree= ref = test2 --owner-uid= ` id -u`
2016-11-17 00:46:45 +03:00
echo "ok commit from ref with modifier"
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b trees/test2 -s 'ref with / in it' --tree= ref = test2
2014-12-05 16:28:16 +03:00
echo "ok commit ref with /"
old_rev = $( $OSTREE rev-parse test2)
2017-03-26 12:03:47 +03:00
$OSTREE ls -R -C test2
$OSTREE commit ${ COMMIT_ARGS } --skip-if-unchanged -b trees/test2 -s 'should not be committed' --tree= ref = test2
$OSTREE ls -R -C test2
2014-12-05 16:28:16 +03:00
new_rev = $( $OSTREE rev-parse test2)
assert_streq " ${ old_rev } " " ${ new_rev } "
echo "ok commit --skip-if-unchanged"
cd ${ test_tmpdir } /checkout-test2-4
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "no xattrs" --no-xattrs
2014-12-05 16:28:16 +03:00
echo "ok commit with no xattrs"
2016-07-19 05:14:26 +03:00
mkdir tree-A tree-B
touch tree-A/file-a tree-B/file-b
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test3-1 -s "Initial tree" --tree= dir = tree-A
$OSTREE commit ${ COMMIT_ARGS } -b test3-2 -s "Replacement tree" --tree= dir = tree-B
$OSTREE commit ${ COMMIT_ARGS } -b test3-combined -s "combined tree" --tree= ref = test3-1 --tree= ref = test3-2
2016-07-19 05:14:26 +03:00
$OSTREE checkout test3-combined checkout-test3-combined
assert_has_file checkout-test3-combined/file-a
assert_has_file checkout-test3-combined/file-b
echo "ok commit combined ref trees"
2016-04-22 19:35:48 +03:00
# NB: The + is optional, but we need to make sure we support it
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
cat > test-statoverride.txt <<EOF
2016-04-22 19:35:48 +03:00
+1048 /a/nested/2
2048 /a/nested/3
2017-06-30 16:40:37 +03:00
= 384 /a/readable-only
2014-12-05 16:28:16 +03:00
EOF
cd ${ test_tmpdir } /checkout-test2-4
2017-06-30 16:40:37 +03:00
echo readable only > a/readable-only
chmod 664 a/readable-only
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-override -s "with statoverride" --statoverride= ../test-statoverride.txt
2016-04-22 19:35:48 +03:00
cd ${ test_tmpdir }
$OSTREE checkout test2-override checkout-test2-override
Canonicalize bare-user-only perms with 0755 mask
For the flatpak use case where bare-user-only was introduced, we actually
don't want to support s{u,g} id files in particular.
Actually, I can't think of a reason to have anything outside of the
`0755 i.e. (u=rwx,g=rx,o=rx)` mask, so that's what we do here.
This will have the effect of treating existing `bare-user-only` repositories as
corrupted if they have files outside of that mask, but I think we should do this
now; most of the flatpak users will still be on `bare-user`, and we haven't
changed the semantics of that mode yet.
Note that in this patch we will also *reject* file content that doesn't
match this. This is somewhat asymmetric, since we aren't similarly rejecting
e.g. directory metadata. But, this will close off the biggest source
of the problem for flatpak (setuid binaries).
See: https://github.com/ostreedev/ostree/pull/908
See: https://github.com/flatpak/flatpak/pull/837
Closes: #909
Approved by: alexlarsson
2017-06-06 20:34:27 +03:00
if ! is_bare_user_only_repo repo; then
test -g checkout-test2-override/a/nested/2
test -u checkout-test2-override/a/nested/3
else
test '!' -g checkout-test2-override/a/nested/2
test '!' -u checkout-test2-override/a/nested/3
fi
2017-06-30 16:40:37 +03:00
assert_file_has_mode checkout-test2-override/a/readable-only 600
2016-04-22 19:35:48 +03:00
echo "ok commit statoverride"
cd ${ test_tmpdir }
cat > test-skiplist.txt <<EOF
/a/nested/3
EOF
cd ${ test_tmpdir } /checkout-test2-4
assert_has_file a/nested/3
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2-skiplist -s "with skiplist" --skip-list= ../test-skiplist.txt
2016-04-22 19:35:48 +03:00
cd ${ test_tmpdir }
$OSTREE checkout test2-skiplist checkout-test2-skiplist
assert_not_has_file checkout-test2-skiplist/a/nested/3
echo "ok commit skiplist"
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
$OSTREE prune
echo "ok prune didn't fail"
cd ${ test_tmpdir }
2017-06-07 22:25:21 +03:00
# Verify we can't cat dirs
for path in / /baz; do
if $OSTREE cat test2 $path 2>err.txt; then
assert_not_reached "cat directory"
fi
assert_file_has_content err.txt "open directory"
done
rm checkout-test2 -rf
2014-12-05 16:28:16 +03:00
$OSTREE cat test2 /yet/another/tree/green > greenfile-contents
assert_file_has_content greenfile-contents "leaf"
2017-06-07 22:25:21 +03:00
$OSTREE checkout test2 checkout-test2
ls -alR checkout-test2
ln -sr checkout-test2/{ four,four-link}
ln -sr checkout-test2/{ baz/cow,cow-link}
ln -sr checkout-test2/{ cow-link,cow-link-link}
$OSTREE commit -b test2-withlink --tree= dir = checkout-test2
if $OSTREE cat test2-withlink /four-link 2>err.txt; then
assert_not_reached "cat directory"
fi
assert_file_has_content err.txt "open directory"
for path in /cow-link /cow-link-link; do
$OSTREE cat test2-withlink $path >contents.txt
assert_file_has_content contents.txt moo
done
2014-12-05 16:28:16 +03:00
echo "ok cat-file"
cd ${ test_tmpdir }
$OSTREE checkout --subpath /yet/another test2 checkout-test2-subpath
cd checkout-test2-subpath
assert_file_has_content tree/green "leaf"
2017-05-12 03:29:21 +03:00
cd ${ test_tmpdir }
rm checkout-test2-subpath -rf
$OSTREE ls -R test2
# Test checking out a file
$OSTREE checkout --subpath /baz/saucer test2 checkout-test2-subpath
assert_file_has_content checkout-test2-subpath/saucer alien
# Test checking out a file without making a subdir
mkdir t
cd t
$OSTREE checkout --subpath /baz/saucer test2 .
assert_file_has_content saucer alien
rm t -rf
2014-12-05 16:28:16 +03:00
echo "ok checkout subpath"
cd ${ test_tmpdir }
2017-03-26 12:03:47 +03:00
$OSTREE checkout --union test2 checkout-test2-union
2014-12-05 16:28:16 +03:00
find checkout-test2-union | wc -l > union-files-count
2017-03-26 12:03:47 +03:00
$OSTREE checkout --union test2 checkout-test2-union
2014-12-05 16:28:16 +03:00
find checkout-test2-union | wc -l > union-files-count.new
cmp union-files-count{ ,.new}
cd checkout-test2-union
assert_file_has_content ./yet/another/tree/green "leaf"
echo "ok checkout union 1"
2017-03-02 06:42:07 +03:00
cd ${ test_tmpdir }
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test-union-add --tree= ref = test2
2017-03-02 06:42:07 +03:00
$OSTREE checkout test-union-add checkout-test-union-add
echo 'file for union add testing' > checkout-test-union-add/union-add-test
echo 'another file for union add testing' > checkout-test-union-add/union-add-test2
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test-union-add --tree= dir = checkout-test-union-add
2017-03-02 06:42:07 +03:00
rm checkout-test-union-add -rf
# Check out previous
$OSTREE checkout test-union-add^ checkout-test-union-add
assert_not_has_file checkout-test-union-add/union-add-test
assert_not_has_file checkout-test-union-add/union-add-test2
# Now create a file we don't want overwritten
echo 'existing file for union add' > checkout-test-union-add/union-add-test
$OSTREE checkout --union-add test-union-add checkout-test-union-add
assert_file_has_content checkout-test-union-add/union-add-test 'existing file for union add'
assert_file_has_content checkout-test-union-add/union-add-test2 'another file for union add testing'
echo "ok checkout union add"
2017-09-09 00:07:45 +03:00
# Test --union-identical <https://github.com/projectatomic/rpm-ostree/issues/982>
# Prepare data:
2017-08-31 18:44:35 +03:00
cd ${ test_tmpdir }
2017-09-09 00:07:45 +03:00
for x in $( seq 3) ; do
mkdir -p pkg${ x } /usr/{ bin,share/licenses}
# Separate binaries and symlinks
echo 'binary for pkg' ${ x } > pkg${ x } /usr/bin/pkg${ x }
ln -s pkg${ x } pkg${ x } /usr/bin/link${ x }
# But they share the GPL
echo 'this is the GPL' > pkg${ x } /usr/share/licenses/COPYING
ln -s COPYING pkg${ x } /usr/share/licenses/LICENSE
$OSTREE commit -b union-identical-pkg${ x } --tree= dir = pkg${ x }
done
rm union-identical-test -rf
for x in $( seq 3) ; do
$OSTREE checkout ${ CHECKOUT_H_ARGS } --union-identical union-identical-pkg${ x } union-identical-test
done
if $OSTREE checkout ${ CHECKOUT_H_ARGS /-H/ } --union-identical union-identical-pkg${ x } union-identical-test-tmp 2>err.txt; then
fatal "--union-identical without -H"
2017-08-31 18:44:35 +03:00
fi
2017-09-09 00:07:45 +03:00
assert_file_has_content err.txt "error:.*--union-identical requires --require-hardlinks"
for x in $( seq 3) ; do
for v in pkg link; do
assert_file_has_content union-identical-test/usr/bin/${ v } ${ x } "binary for pkg" ${ x }
done
for v in COPYING LICENSE; do
assert_file_has_content union-identical-test/usr/share/licenses/${ v } GPL
done
done
echo "ok checkout union identical merges"
# Make conflicting packages, one with regfile, one with symlink
mkdir -p pkg-conflict1bin/usr/{ bin,share/licenses}
echo 'binary for pkg-conflict1bin' > pkg-conflict1bin/usr/bin/pkg1
echo 'this is the GPL' > pkg-conflict1bin/usr/share/licenses/COPYING
$OSTREE commit -b union-identical-conflictpkg1bin --tree= dir = pkg-conflict1bin
mkdir -p pkg-conflict1link/usr/{ bin,share/licenses}
ln -s somewhere-else > pkg-conflict1link/usr/bin/pkg1
echo 'this is the GPL' > pkg-conflict1link/usr/share/licenses/COPYING
$OSTREE commit -b union-identical-conflictpkg1link --tree= dir = pkg-conflict1link
for v in bin link; do
rm union-identical-test -rf
$OSTREE checkout ${ CHECKOUT_H_ARGS } --union-identical union-identical-pkg1 union-identical-test
if $OSTREE checkout ${ CHECKOUT_H_ARGS } --union-identical union-identical-conflictpkg1${ v } union-identical-test 2>err.txt; then
fatal " union identical $v succeeded? "
fi
assert_file_has_content err.txt 'error:.*File exists'
done
echo "ok checkout union identical conflicts"
2017-08-31 18:44:35 +03:00
2017-06-13 20:26:33 +03:00
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
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
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
fi
rm dir-co -rf
echo "ok checkout bareuseronly dir"
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
rm -rf shadow-repo
mkdir shadow-repo
2017-03-24 17:35:59 +03:00
ostree_repo_init shadow-repo
2014-12-05 16:28:16 +03:00
${ CMD_PREFIX } ostree --repo= shadow-repo config set core.parent $( pwd ) /repo
rm -rf test2-checkout
2015-03-03 15:13:54 +03:00
parent_rev_test2 = $( ${ CMD_PREFIX } ostree --repo= repo rev-parse test2)
2017-03-26 12:03:47 +03:00
${ CMD_PREFIX } ostree --repo= shadow-repo checkout ${ CHECKOUT_U_ARG } " ${ parent_rev_test2 } " test2-checkout
2014-12-05 16:28:16 +03:00
echo "ok checkout from shadow repo"
cd ${ test_tmpdir }
2015-06-29 20:35:07 +03:00
if $OSTREE checkout test2 --subpath /enoent 2>err.txt; then
assert_not_reached "checking outnonexistent file unexpectedly succeeded!"
fi
assert_file_has_content err.txt 'No such file or directory'
2014-12-05 16:28:16 +03:00
echo "ok subdir enoent"
cd ${ test_tmpdir }
$OSTREE checkout test2 --allow-noent --subpath /enoent 2>/dev/null
echo "ok subdir noent"
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
mkdir repo3
ostree_repo_init repo3 --mode= bare-user
${ CMD_PREFIX } ostree --repo= repo3 pull-local --remote= aremote repo test2
${ CMD_PREFIX } ostree --repo= repo3 rev-parse aremote/test2
echo "ok pull-local with --remote arg"
fi
2014-12-05 16:28:16 +03:00
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
${ CMD_PREFIX } ostree --repo= repo3 prune
find repo3/objects -name '*.commit' > objlist-before-prune
rm repo3/refs/heads/* repo3/refs/mirrors/* repo3/refs/remotes/* -rf
${ CMD_PREFIX } ostree --repo= repo3 prune --refs-only
find repo3/objects -name '*.commit' > objlist-after-prune
if cmp -s objlist-before-prune objlist-after-prune; then
fatal "Prune didn't delete anything!"
fi
rm repo3 objlist-before-prune objlist-after-prune -rf
echo "ok prune"
2014-12-05 16:28:16 +03:00
fi
cd ${ test_tmpdir }
rm repo3 -rf
2017-03-24 17:35:59 +03:00
ostree_repo_init repo3 --mode= archive
2014-12-05 16:28:16 +03:00
${ CMD_PREFIX } ostree --repo= repo3 pull-local --remote= aremote repo test2
rm repo3/refs/remotes -rf
mkdir repo3/refs/remotes
2015-03-03 15:13:54 +03:00
${ CMD_PREFIX } ostree --repo= repo3 prune --refs-only
2014-12-05 16:28:16 +03:00
find repo3/objects -name '*.filez' > file-objects
if test -s file-objects; then
assert_not_reached "prune didn't delete all objects"
fi
2017-06-29 05:52:40 +03:00
echo "ok prune in archive deleted everything"
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
rm -rf test2-checkout
$OSTREE checkout test2 test2-checkout
2017-03-26 12:03:47 +03:00
( cd test2-checkout && $OSTREE commit ${ COMMIT_ARGS } --link-checkout-speedup -b test2 -s "tmp" )
2014-12-05 16:28:16 +03:00
echo "ok commit with link speedup"
cd ${ test_tmpdir }
$OSTREE ls test2
echo "ok ls with no argument"
cd ${ test_tmpdir }
if $OSTREE ls test2 /baz/cow/notadir 2>errmsg; then
assert_not_reached
fi
assert_file_has_content errmsg "Not a directory"
echo "ok ls of not a directory"
cd ${ test_tmpdir }
$OSTREE show test2
echo "ok show with non-checksum"
2015-07-21 16:41:39 +03:00
cd $test_tmpdir /checkout-test2
2017-03-26 12:03:47 +03:00
checksum = $( $OSTREE commit ${ COMMIT_ARGS } -b test4 -s "Third commit" )
2015-07-21 16:41:39 +03:00
cd ${ test_tmpdir }
2014-12-05 16:28:16 +03:00
$OSTREE show test4 > show-output
assert_file_has_content show-output "Third commit"
assert_file_has_content show-output " commit $checksum "
echo "ok show full output"
2015-07-21 16:41:39 +03:00
cd $test_tmpdir /checkout-test2
2017-03-26 12:03:47 +03:00
checksum1 = $( $OSTREE commit ${ COMMIT_ARGS } -b test5 -s "First commit" )
checksum2 = $( $OSTREE commit ${ COMMIT_ARGS } -b test5 -s "Second commit" )
2015-07-21 16:41:39 +03:00
cd ${ test_tmpdir }
2014-12-05 16:28:16 +03:00
$OSTREE log test5 > log-output
assert_file_has_content log-output "First commit"
assert_file_has_content log-output " commit $checksum1 "
assert_file_has_content log-output "Second commit"
assert_file_has_content log-output " commit $checksum2 "
echo "ok log output"
2015-07-21 16:41:39 +03:00
cd $test_tmpdir /checkout-test2
2017-03-26 12:03:47 +03:00
checksum1 = $( $OSTREE commit ${ COMMIT_ARGS } -b test6 -s "First commit" )
checksum2 = $( $OSTREE commit ${ COMMIT_ARGS } -b test6 -s "Second commit" )
2015-07-21 16:41:39 +03:00
cd ${ test_tmpdir }
2014-12-05 16:28:16 +03:00
$OSTREE show test6 > show-output
assert_file_has_content show-output " commit $checksum2 "
$OSTREE reset test6 $checksum1
$OSTREE show test6 > show-output
assert_file_has_content show-output " commit $checksum1 "
echo "ok basic reset"
cd ${ test_tmpdir }
rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2
touch checkout-test2/sometestfile
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -s sometest -b test2 checkout-test2
2014-12-05 16:28:16 +03:00
echo "ok commit with directory filename"
2015-07-21 16:41:39 +03:00
cd $test_tmpdir /checkout-test2
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Metadata string" --add-metadata-string= FOO = BAR --add-metadata-string= KITTENS = CUTE --add-detached-metadata-string= SIGNATURE = HANCOCK --tree= ref = test2
2015-07-21 16:41:39 +03:00
cd ${ test_tmpdir }
2014-12-05 16:28:16 +03:00
$OSTREE show --print-metadata-key= FOO test2 > test2-meta
assert_file_has_content test2-meta "BAR"
$OSTREE show --print-metadata-key= KITTENS test2 > test2-meta
assert_file_has_content test2-meta "CUTE"
$OSTREE show --print-detached-metadata-key= SIGNATURE test2 > test2-meta
assert_file_has_content test2-meta "HANCOCK"
echo "ok metadata commit with strings"
2017-08-29 19:02:43 +03:00
if ! skip_one_without_user_xattrs; then
cd ${ test_tmpdir }
rm repo2 -rf
mkdir repo2
ostree_repo_init repo2 --mode= bare-user
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo
${ CMD_PREFIX } ostree --repo= repo2 show --print-detached-metadata-key= SIGNATURE test2 > test2-meta
assert_file_has_content test2-meta "HANCOCK"
echo "ok pull-local after commit metadata"
fi
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
${ CMD_PREFIX } ostree --repo= repo remote --set= tls-permissive= true add aremote http://remote.example.com/repo testos/buildmaster/x86_64-runtime
assert_file_has_content repo/config 'tls-permissive=true'
assert_file_has_content repo/config 'remote\.example\.com'
echo "ok remote add with set"
cd ${ test_tmpdir }
${ CMD_PREFIX } ostree --repo= repo remote show-url aremote > aremote-url.txt
assert_file_has_content aremote-url.txt 'http.*remote\.example\.com/repo'
echo "ok remote show-url"
cd ${ test_tmpdir }
rm -rf test2-checkout
2014-12-17 19:34:10 +03:00
if grep bare-user repo/config; then
$OSTREE checkout -U test2 test2-checkout
else
$OSTREE checkout test2 test2-checkout
fi
2014-12-05 16:28:16 +03:00
stat '--format=%Y' test2-checkout/baz/cow > cow-mtime
2016-09-08 14:11:52 +03:00
assert_file_has_content cow-mtime 0
2015-02-19 02:18:21 +03:00
stat '--format=%Y' test2-checkout/baz/deeper > deeper-mtime
2016-09-08 14:11:52 +03:00
assert_file_has_content deeper-mtime 0
2014-12-05 16:28:16 +03:00
echo "ok content mtime"
cd ${ test_tmpdir }
rm -rf test2-checkout
mkdir -p test2-checkout
cd test2-checkout
mkfifo afifo
2017-03-26 12:03:47 +03:00
if $OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Attempt to commit a FIFO" 2>../errmsg; then
2014-12-05 16:28:16 +03:00
assert_not_reached "Committing a FIFO unexpetedly succeeded!"
assert_file_has_content ../errmsg "Unsupported file type"
fi
echo "ok commit of fifo was rejected"
2015-04-07 01:29:01 +03:00
cd ${ test_tmpdir }
rm repo2 -rf
mkdir repo2
2017-03-24 17:35:59 +03:00
ostree_repo_init repo2 --mode= archive
2015-04-07 01:29:01 +03:00
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo
rm -rf test2-checkout
${ CMD_PREFIX } ostree --repo= repo2 checkout -U --disable-cache test2 test2-checkout
if test -d repo2/uncompressed-objects-cache; then
ls repo2/uncompressed-objects-cache > ls.txt
if test -s ls.txt; then
assert_not_reached "repo has uncompressed objects"
fi
fi
rm test2-checkout -rf
${ CMD_PREFIX } ostree --repo= repo2 checkout -U test2 test2-checkout
assert_file_has_content test2-checkout/baz/cow moo
assert_has_dir repo2/uncompressed-objects-cache
2017-06-02 20:41:33 +03:00
ls repo2/uncompressed-objects-cache > ls.txt
if ! test -s ls.txt; then
assert_not_reached "repo didn't cache uncompressed objects"
fi
2017-06-02 17:09:23 +03:00
# we're in archive mode, but the repo we pull-local from might be
# bare-user-only, in which case, we skip these checks since bare-user-only
# doesn't store permission bits
if ! is_bare_user_only_repo repo; then
assert_file_has_mode test2-checkout/baz/cowro 600
assert_file_has_mode test2-checkout/baz/deeper/ohyeahx 755
fi
2015-04-07 01:29:01 +03:00
echo "ok disable cache checkout"
2016-04-19 19:11:01 +03:00
cd ${ test_tmpdir }
rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2
2016-04-19 22:19:46 +03:00
date > checkout-test2/date.txt
rm repo/tmp/* -rf
export TEST_BOOTID = 3072029c-8b10-60d1-d31b-8422eeff9b42
if env OSTREE_REPO_TEST_ERROR = pre-commit OSTREE_BOOTID = ${ TEST_BOOTID } \
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s '' $test_tmpdir /checkout-test2 2>err.txt; then
2016-04-19 19:11:01 +03:00
assert_not_reached "Should have hit OSTREE_REPO_TEST_ERROR_PRE_COMMIT"
fi
assert_file_has_content err.txt OSTREE_REPO_TEST_ERROR_PRE_COMMIT
2016-04-19 22:19:46 +03:00
found_staging = 0
for d in $( find repo/tmp/ -maxdepth 1 -type d) ; do
bn = $( basename $d )
if test ${ bn ##staging- } != ${ bn } ; then
assert_str_match " ${ bn } " " ^staging- ${ TEST_BOOTID } - "
found_staging = 1
fi
done
assert_streq " ${ found_staging } " 1
echo "ok test error pre commit/bootid"
2016-04-19 19:11:01 +03:00
2016-02-14 19:57:59 +03:00
# Whiteouts
cd ${ test_tmpdir }
mkdir -p overlay/baz/
2016-08-05 22:41:05 +03:00
if touch overlay/baz/.wh.cow && touch overlay/.wh.deeper; then
touch overlay/anewfile
mkdir overlay/anewdir/
touch overlay/anewdir/blah
2017-03-26 12:03:47 +03:00
$OSTREE --repo= repo commit ${ COMMIT_ARGS } -b overlay -s 'overlay' --tree= dir = overlay
2016-08-05 22:41:05 +03:00
rm overlay -rf
for branch in test2 overlay; do
$OSTREE --repo= repo checkout --union --whiteouts ${ branch } overlay-co
done
for f in .wh.deeper baz/cow baz/.wh.cow; do
assert_not_has_file overlay-co/${ f }
done
assert_not_has_dir overlay-co/deeper
assert_has_file overlay-co/anewdir/blah
assert_has_file overlay-co/anewfile
echo "ok whiteouts enabled"
# Now double check whiteouts are not processed without --whiteouts
rm overlay-co -rf
for branch in test2 overlay; do
$OSTREE --repo= repo checkout --union ${ branch } overlay-co
done
for f in .wh.deeper baz/cow baz/.wh.cow; do
assert_has_file overlay-co/${ f }
done
assert_not_has_dir overlay-co/deeper
assert_has_file overlay-co/anewdir/blah
assert_has_file overlay-co/anewfile
echo "ok whiteouts disabled"
else
echo "ok # SKIP whiteouts do not work, are you using aufs?"
echo "ok # SKIP whiteouts do not work, are you using aufs?"
fi
2016-02-14 19:57:59 +03:00
2014-12-05 16:28:16 +03:00
cd ${ test_tmpdir }
rm -rf test2-checkout
mkdir -p test2-checkout
cd test2-checkout
touch should-not-be-fsynced
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Unfsynced commit" --fsync= false
2015-02-04 05:44:38 +03:00
2015-04-02 15:09:33 +03:00
# Run this test only as non-root user. When run as root, the chmod
# won't have any effect.
if test " $( id -u) " != "0" ; then
cd ${ test_tmpdir }
rm -f expected-fail error-message
2017-06-29 05:52:40 +03:00
$OSTREE init --mode= archive --repo= repo-noperm
2015-05-14 05:11:39 +03:00
chmod -w repo-noperm/objects
2015-04-02 15:09:33 +03:00
$OSTREE --repo= repo-noperm pull-local repo 2> error-message || touch expected-fail
2015-05-14 05:17:26 +03:00
chmod +w repo-noperm/objects
2015-04-02 15:09:33 +03:00
assert_has_file expected-fail
assert_file_has_content error-message "Permission denied"
echo "ok unwritable repo was caught"
2016-03-04 02:00:54 +03:00
else
echo "ok # SKIP not run when root"
2015-04-02 15:09:33 +03:00
fi
2015-05-14 04:59:17 +03:00
cd ${ test_tmpdir }
rm -rf test2-checkout
mkdir -p test2-checkout
cd test2-checkout
touch blah
2016-03-04 18:53:47 +03:00
stat --printf= "%.Y\n" ${ test_tmpdir } /repo > ${ test_tmpdir } /timestamp-orig.txt
2017-03-26 12:03:47 +03:00
$OSTREE commit ${ COMMIT_ARGS } -b test2 -s "Should bump the mtime"
2016-03-04 18:53:47 +03:00
stat --printf= "%.Y\n" ${ test_tmpdir } /repo > ${ test_tmpdir } /timestamp-new.txt
2015-05-14 04:59:17 +03:00
cd ..
2016-03-04 18:53:47 +03:00
if cmp timestamp-{ orig,new} .txt; then
2015-05-14 04:59:17 +03:00
assert_not_reached "failed to update mtime on repo"
fi
2016-03-04 18:53:47 +03:00
echo "ok mtime updated"
2016-04-13 23:44:21 +03:00
cd ${ test_tmpdir }
$OSTREE init --mode= bare --repo= repo-extensions
assert_has_dir repo-extensions/extensions
echo "ok extensions dir"