2013-08-15 17:17:37 +04:00
#!/bin/bash
#
# Copyright (C) 2011,2013 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
2013-08-15 17:17:37 +04:00
. $( dirname $0 ) /libtest.sh
2016-03-31 13:06:05 +03:00
skip_without_user_xattrs
2013-08-15 17:17:37 +04:00
bindatafiles = "bash true ostree"
morebindatafiles = "false ls"
2016-09-09 21:52:18 +03:00
echo '1..11'
2013-08-15 17:17:37 +04:00
mkdir repo
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo init --mode= archive-z2
2013-08-15 17:17:37 +04:00
mkdir files
for bin in ${ bindatafiles } ; do
cp $( which ${ bin } ) files
done
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo commit -b test -s test --tree= dir = files
2013-08-15 17:17:37 +04:00
function permuteFile( ) {
permutation = $(( $1 % 2 ))
output = $2
case $permutation in
0) dd if = /dev/zero count = 40 bs = 1 >> $output ; ;
1) echo aheader | cat - $output >> $output .new && mv $output .new $output ; ;
esac
}
function permuteDirectory( ) {
permutation = $1
dir = $2
for x in ${ dir } /*; do
for z in $( seq ${ permutation } ) ; do
permuteFile ${ z } ${ x }
done
done
}
2015-10-15 11:46:16 +03:00
get_assert_one_direntry_matching( ) {
local path = $1
local r = $2
local child = ""
local bn
for p in ${ path } /*; do
bn = $( basename $p )
if ! echo ${ bn } | grep -q " $r " ; then
continue
fi
if test -z " ${ child } " ; then
child = ${ bn }
else
assert_not_reached " Expected only one child matching ${ r } in ${ path } " ;
fi
done
if test -z " ${ child } " ; then
assert_not_reached " Failed to find child matching ${ r } "
fi
echo ${ child }
}
2015-03-03 15:13:54 +03:00
origrev = $( ${ CMD_PREFIX } ostree --repo= repo rev-parse test )
2015-01-13 17:09:43 +03:00
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --empty --to= ${ origrev }
2016-07-01 21:39:49 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --if-not-exists --empty --to= ${ origrev } > out.txt
assert_file_has_content out.txt " ${ origrev } already exists "
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ${ origrev } || exit 1
${ CMD_PREFIX } ostree --repo= repo prune
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ${ origrev } || exit 1
2015-01-13 17:09:43 +03:00
2013-08-15 17:17:37 +04:00
permuteDirectory 1 files
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo commit -b test -s test --tree= dir = files
2013-08-15 17:17:37 +04:00
2015-03-03 15:13:54 +03:00
newrev = $( ${ CMD_PREFIX } ostree --repo= repo rev-parse test )
2015-10-15 11:46:16 +03:00
2016-07-01 21:39:49 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --if-not-exists --from= ${ origrev } --to= ${ newrev } --inline
${ CMD_PREFIX } ostree --repo= repo static-delta generate --if-not-exists --from= ${ origrev } --to= ${ newrev } --inline > out.txt
assert_file_has_content out.txt " ${ origrev } - ${ newrev } already exists "
# Should regenerate
${ CMD_PREFIX } ostree --repo= repo static-delta generate --from= ${ origrev } --to= ${ newrev } --inline > out.txt
assert_not_file_has_content out.txt " ${ origrev } - ${ newrev } already exists "
2015-10-15 11:46:16 +03:00
deltaprefix = $( get_assert_one_direntry_matching repo/deltas '.' )
deltadir = $( get_assert_one_direntry_matching repo/deltas/${ deltaprefix } '-' )
assert_has_file repo/deltas/${ deltaprefix } /${ deltadir } /superblock
assert_not_has_file repo/deltas/${ deltaprefix } /${ deltadir } /0
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --from= ${ origrev } --to= ${ newrev }
2013-08-15 17:17:37 +04:00
2015-10-15 11:46:16 +03:00
assert_has_file repo/deltas/${ deltaprefix } /${ deltadir } /superblock
assert_has_file repo/deltas/${ deltaprefix } /${ deltadir } /0
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --disable-bsdiff --from= ${ origrev } --to= ${ newrev } 2>& 1 | grep "bsdiff=0 objects"
${ CMD_PREFIX } ostree --repo= repo static-delta generate --max-bsdiff-size= 0 --from= ${ origrev } --to= ${ newrev } 2>& 1 | grep "bsdiff=0 objects"
${ CMD_PREFIX } ostree --repo= repo static-delta generate --max-bsdiff-size= 10000 --from= ${ origrev } --to= ${ newrev } 2>& 1 | grep "bsdiff=[1-9]"
2015-07-29 11:26:27 +03:00
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ${ origrev } -${ newrev } || exit 1
2015-01-13 17:09:43 +03:00
2015-01-14 18:53:21 +03:00
if ${ CMD_PREFIX } ostree --repo= repo static-delta generate --from= ${ origrev } --to= ${ newrev } --empty 2>>err.txt; then
assert_not_reached " static-delta generate --from= ${ origrev } --empty unexpectedly succeeded "
fi
2015-09-14 04:35:10 +03:00
echo 'ok generate'
2016-02-23 19:00:18 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta show ${ origrev } -${ newrev } > show.txt
assert_file_has_content show.txt 'Endianness: \(little\|big\)'
echo 'ok show'
2016-02-24 22:29:56 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --swap-endianness --from= ${ origrev } --to= ${ newrev }
${ CMD_PREFIX } ostree --repo= repo static-delta show ${ origrev } -${ newrev } > show-swapped.txt
totalsize_orig = $( grep 'Total Size:' show.txt)
totalsize_swapped = $( grep 'Total Size:' show-swapped.txt)
assert_not_streq " ${ totalsize_orig } " ""
assert_streq " ${ totalsize_orig } " " ${ totalsize_swapped } "
echo 'ok generate + show endian swapped'
2016-03-31 20:29:44 +03:00
tar xf ${ test_srcdir } /pre-endian-deltas-repo-big.tar.xz
2016-02-25 01:04:04 +03:00
mv pre-endian-deltas-repo{ ,-big}
2016-03-31 20:29:44 +03:00
tar xf ${ test_srcdir } /pre-endian-deltas-repo-little.tar.xz
2016-02-25 01:04:04 +03:00
mv pre-endian-deltas-repo{ ,-little}
legacy_origrev = $( ${ CMD_PREFIX } ostree --repo= pre-endian-deltas-repo-big rev-parse main^)
legacy_newrev = $( ${ CMD_PREFIX } ostree --repo= pre-endian-deltas-repo-big rev-parse main)
${ CMD_PREFIX } ostree --repo= pre-endian-deltas-repo-big static-delta show ${ legacy_origrev } -${ legacy_newrev } > show-legacy-big.txt
totalsize_legacy_big = $( grep 'Total Size:' show-legacy-big.txt)
${ CMD_PREFIX } ostree --repo= pre-endian-deltas-repo-big static-delta show ${ legacy_origrev } -${ legacy_newrev } > show-legacy-little.txt
totalsize_legacy_little = $( grep 'Total Size:' show-legacy-little.txt)
for f in show-legacy-{ big,little} .txt; do
if grep 'Endianness:.*heuristic' $f ; then
found_heuristic = yes
break
fi
done
assert_streq " ${ found_heuristic } " "yes"
assert_streq " ${ totalsize_legacy_big } " " ${ totalsize_legacy_little } "
echo 'ok heuristic endian detection'
2016-08-10 01:39:41 +03:00
${ CMD_PREFIX } ostree --repo= repo summary -u
2015-11-09 15:03:35 +03:00
mkdir repo2 && ${ CMD_PREFIX } ostree --repo= repo2 init --mode= archive-z2
2016-08-10 01:39:41 +03:00
${ CMD_PREFIX } ostree --repo= repo2 pull-local --require-static-deltas repo ${ newrev }
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo2 fsck
${ CMD_PREFIX } ostree --repo= repo2 ls ${ newrev } >/dev/null
2015-09-14 04:35:10 +03:00
echo 'ok pull delta'
rm repo2 -rf
2015-11-09 15:03:35 +03:00
mkdir repo2 && ${ CMD_PREFIX } ostree --repo= repo2 init --mode= bare-user
2015-09-14 04:35:10 +03:00
mkdir deltadir
deltaprefix = $( get_assert_one_direntry_matching repo/deltas '.' )
deltadir = $( get_assert_one_direntry_matching repo/deltas/${ deltaprefix } '-' )
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo ${ origrev }
${ CMD_PREFIX } ostree --repo= repo2 ls ${ origrev } >/dev/null
${ CMD_PREFIX } ostree --repo= repo2 static-delta apply-offline repo/deltas/${ deltaprefix } /${ deltadir }
${ CMD_PREFIX } ostree --repo= repo2 fsck
${ CMD_PREFIX } ostree --repo= repo2 ls ${ newrev } >/dev/null
2015-10-15 11:46:16 +03:00
echo 'ok apply offline'
rm -rf repo/deltas/${ deltaprefix } /${ deltadir } /*
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta generate --from= ${ origrev } --to= ${ newrev } --inline
2015-10-15 11:46:16 +03:00
assert_not_has_file repo/deltas/${ deltaprefix } /${ deltadir } /0
rm repo2 -rf
mkdir repo2 && ostree --repo= repo2 init --mode= bare-user
2015-11-09 15:03:35 +03:00
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo ${ origrev }
${ CMD_PREFIX } ostree --repo= repo2 ls ${ origrev } >/dev/null
${ CMD_PREFIX } ostree --repo= repo2 static-delta apply-offline repo/deltas/${ deltaprefix } /${ deltadir }
${ CMD_PREFIX } ostree --repo= repo2 fsck
${ CMD_PREFIX } ostree --repo= repo2 ls ${ newrev } >/dev/null
2015-10-15 11:46:16 +03:00
echo 'ok apply offline inline'
2016-04-08 11:44:24 +03:00
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } -${ newrev } $ || exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } $ || exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta delete ${ origrev } || exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } -${ newrev } $ || exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } $ && exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta delete ${ origrev } -${ newrev } || exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } -${ newrev } $ && exit 1
${ CMD_PREFIX } ostree --repo= repo static-delta list | grep ^${ origrev } $ && exit 1
echo 'ok delete'
2016-07-30 19:00:04 +03:00
# Make another commit with no changes to create a delta with no parts
${ CMD_PREFIX } ostree --repo= repo commit -b test -s test --tree= dir = files
samerev = $( ${ CMD_PREFIX } ostree --repo= repo rev-parse test )
${ CMD_PREFIX } ostree --repo= repo static-delta generate --from= ${ newrev } --to= ${ samerev }
${ CMD_PREFIX } ostree --repo= repo static-delta show ${ newrev } -${ samerev } > show-empty.txt
nparts_empty = $( grep '^Number of parts:' show-empty.txt)
part0_meta_empty = $( grep '^PartMeta0:' show-empty.txt)
totalsize_empty = $( grep '^Total Uncompressed Size:' show-empty.txt)
assert_streq " ${ nparts_empty } " "Number of parts: 1"
assert_str_match " ${ part0_meta_empty } " "nobjects=0"
assert_streq " ${ totalsize_empty } " "Total Uncompressed Size: 0 (0 bytes)"
echo 'ok generate + show empty delta part'
2016-08-10 01:39:41 +03:00
${ CMD_PREFIX } ostree --repo= repo summary -u
2016-07-30 19:00:04 +03:00
rm -rf repo2
mkdir repo2 && ${ CMD_PREFIX } ostree --repo= repo2 init --mode= archive-z2
${ CMD_PREFIX } ostree --repo= repo2 pull-local repo ${ newrev }
2016-08-10 01:39:41 +03:00
${ CMD_PREFIX } ostree --repo= repo2 pull-local --require-static-deltas repo ${ samerev }
2016-07-30 19:00:04 +03:00
${ CMD_PREFIX } ostree --repo= repo2 fsck
${ CMD_PREFIX } ostree --repo= repo2 ls ${ samerev } >/dev/null
echo 'ok pull empty delta part'
2016-09-09 21:52:18 +03:00
if ${ CMD_PREFIX } ostree --repo= repo static-delta show GARBAGE 2> err.txt; then
assert_not_reached "static-delta show GARBAGE unexpectedly succeeded"
fi
assert_file_has_content err.txt "Invalid rev 'GARBAGE'"
echo 'ok handle bad delta name'