2008-04-05 08:16:47 +05:30
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 2008 by Denys Vlasenko
|
2010-08-16 23:44:46 +05:30
|
|
|
# Licensed under GPLv2, see file LICENSE in this source tree.
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2009-11-05 05:11:22 +05:30
|
|
|
. ./testing.sh
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2010-08-11 12:03:57 +05:30
|
|
|
umask 022
|
|
|
|
|
2008-07-12 03:13:11 +05:30
|
|
|
# ls -ln shows date. Need to remove that, it's variable.
|
2008-04-05 08:16:47 +05:30
|
|
|
# sed: coalesce spaces
|
|
|
|
# cut: remove date
|
2010-03-28 23:37:42 +05:30
|
|
|
# grep: remove "total NNN" lines
|
|
|
|
FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9- | grep -v '^total '"
|
2008-04-05 08:16:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
# newc cpio archive of directory cpio.testdir with empty x and y hardlinks
|
|
|
|
hexdump="\
|
2008-07-12 03:13:11 +05:30
|
|
|
\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
|
|
|
|
\x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
|
|
|
|
\x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
|
|
|
|
\x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
|
|
|
|
\x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
|
|
|
|
\x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
|
|
|
|
\x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
|
|
|
|
\x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
|
|
|
|
\xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
|
|
|
|
\x14\x24\x19\x07\xa4\x63\x00"
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2008-05-03 03:16:30 +05:30
|
|
|
user=$(id -u)
|
|
|
|
group=$(id -g)
|
|
|
|
|
2008-07-12 03:13:11 +05:30
|
|
|
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2008-07-12 03:13:11 +05:30
|
|
|
# testing "test name" "command" "expected result" "file input" "stdin"
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2010-05-11 08:02:04 +05:30
|
|
|
optional FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
|
2008-04-05 08:16:47 +05:30
|
|
|
testing "cpio extracts zero-sized hardlinks" \
|
2010-04-26 17:23:57 +05:30
|
|
|
"$ECHO -ne '$hexdump' | bzcat | cpio -i 2>&1; echo \$?;
|
2008-07-12 03:13:11 +05:30
|
|
|
ls -ln cpio.testdir | $FILTER_LS" \
|
2008-04-05 08:16:47 +05:30
|
|
|
"\
|
|
|
|
1 blocks
|
|
|
|
0
|
2008-05-03 03:16:30 +05:30
|
|
|
-rw-r--r-- 2 $user $group 0 x
|
|
|
|
-rw-r--r-- 2 $user $group 0 y
|
2010-06-18 05:30:55 +05:30
|
|
|
" "" ""
|
2010-05-11 07:23:57 +05:30
|
|
|
SKIP=
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2010-01-10 07:17:32 +05:30
|
|
|
|
2009-07-18 19:52:26 +05:30
|
|
|
test x"$SKIP_KNOWN_BUGS" = x"" && {
|
2009-05-28 05:33:29 +05:30
|
|
|
# Currently fails. Numerous buglets: "1 blocks" versus "1 block",
|
2010-04-26 17:23:57 +05:30
|
|
|
# does not list cpio.testdir/x and cpio.testdir/y
|
2008-04-05 08:16:47 +05:30
|
|
|
testing "cpio lists hardlinks" \
|
2008-07-12 03:13:11 +05:30
|
|
|
"$ECHO -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
|
2008-04-05 08:16:47 +05:30
|
|
|
"\
|
|
|
|
cpio.testdir
|
|
|
|
cpio.testdir/x
|
|
|
|
cpio.testdir/y
|
2010-01-05 09:13:21 +05:30
|
|
|
1 blocks
|
2008-04-05 08:16:47 +05:30
|
|
|
0
|
2010-06-18 05:30:55 +05:30
|
|
|
" "" ""
|
2009-07-18 19:52:26 +05:30
|
|
|
}
|
2008-04-05 08:16:47 +05:30
|
|
|
|
2010-01-10 07:17:32 +05:30
|
|
|
|
2008-07-12 03:13:11 +05:30
|
|
|
# More complex case
|
|
|
|
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
|
|
|
|
mkdir cpio.testdir
|
|
|
|
touch cpio.testdir/solo
|
|
|
|
touch cpio.testdir/empty
|
|
|
|
echo x >cpio.testdir/nonempty
|
|
|
|
ln cpio.testdir/empty cpio.testdir/empty1
|
|
|
|
ln cpio.testdir/nonempty cpio.testdir/nonempty1
|
|
|
|
mkdir cpio.testdir2
|
|
|
|
|
2010-05-11 08:02:04 +05:30
|
|
|
optional FEATURE_CPIO_O LONG_OPTS FEATURE_LS_SORTFILES FEATURE_LS_TIMESTAMPS
|
2008-07-12 03:13:11 +05:30
|
|
|
testing "cpio extracts zero-sized hardlinks 2" \
|
2010-04-26 17:23:57 +05:30
|
|
|
"find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i 2>&1); echo \$?;
|
2008-07-12 03:13:11 +05:30
|
|
|
ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
|
|
|
|
"\
|
2009-05-28 05:33:29 +05:30
|
|
|
2 blocks
|
2008-07-12 03:13:11 +05:30
|
|
|
0
|
|
|
|
-rw-r--r-- 2 $user $group 0 empty
|
|
|
|
-rw-r--r-- 2 $user $group 0 empty1
|
|
|
|
-rw-r--r-- 2 $user $group 2 nonempty
|
|
|
|
-rw-r--r-- 2 $user $group 2 nonempty1
|
|
|
|
-rw-r--r-- 1 $user $group 0 solo
|
2010-06-18 05:30:55 +05:30
|
|
|
" "" ""
|
2010-05-10 07:46:43 +05:30
|
|
|
SKIP=
|
2008-07-12 03:13:11 +05:30
|
|
|
|
2010-01-10 07:17:32 +05:30
|
|
|
# Was trying to create "/usr/bin", correct is "usr/bin".
|
|
|
|
rm -rf cpio.testdir
|
2010-05-10 07:46:43 +05:30
|
|
|
optional FEATURE_CPIO_P
|
2010-01-10 07:17:32 +05:30
|
|
|
testing "cpio -p with absolute paths" \
|
2010-04-26 17:23:57 +05:30
|
|
|
"echo /usr/bin | cpio -dp cpio.testdir 2>&1; echo \$?;
|
2010-01-10 07:17:32 +05:30
|
|
|
ls cpio.testdir" \
|
|
|
|
"\
|
|
|
|
1 blocks
|
|
|
|
0
|
|
|
|
usr
|
2010-06-18 05:30:55 +05:30
|
|
|
" "" ""
|
|
|
|
SKIP=
|
|
|
|
|
2010-06-18 15:58:05 +05:30
|
|
|
# chown on a link was affecting file, dropping its suid/sgid bits
|
2010-06-18 05:30:55 +05:30
|
|
|
rm -rf cpio.testdir
|
2010-07-06 01:07:12 +05:30
|
|
|
optional FEATURE_CPIO_O FEATURE_STAT_FORMAT
|
2010-06-18 05:30:55 +05:30
|
|
|
mkdir cpio.testdir
|
|
|
|
touch cpio.testdir/file
|
2010-06-18 15:58:05 +05:30
|
|
|
chmod 6755 cpio.testdir/file # sets suid/sgid bits
|
2010-06-18 05:30:55 +05:30
|
|
|
ln -sf file cpio.testdir/link
|
2010-06-18 15:58:05 +05:30
|
|
|
testing "cpio restores suid/sgid bits" \
|
2010-06-18 05:30:55 +05:30
|
|
|
"cd cpio.testdir && { echo file; echo link; } | cpio -ovHnewc >pack.cpio && rm ???? && cpio -idmvu <pack.cpio 2>/dev/null;
|
|
|
|
stat -c '%a %n' file" \
|
|
|
|
"\
|
|
|
|
file
|
|
|
|
link
|
|
|
|
6755 file
|
|
|
|
" "" ""
|
2010-05-10 07:46:43 +05:30
|
|
|
SKIP=
|
2010-01-10 07:17:32 +05:30
|
|
|
|
2010-10-18 04:24:51 +05:30
|
|
|
# avoid 'not created: newer or same age file exists' message for directories
|
|
|
|
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
|
|
|
|
mkdir cpio.testdir
|
|
|
|
testing "cpio extracts in existing directory" \
|
|
|
|
"$ECHO -ne '$hexdump' | bzcat | cpio -id 2>&1; echo \$?" \
|
|
|
|
"\
|
|
|
|
1 blocks
|
|
|
|
0
|
|
|
|
" "" ""
|
|
|
|
SKIP=
|
2010-01-10 07:17:32 +05:30
|
|
|
|
2016-11-03 03:55:05 +05:30
|
|
|
testing "cpio uses by default uid/gid" \
|
|
|
|
"echo $0 | cpio -o -H newc | cpio -tv 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \
|
|
|
|
"\
|
|
|
|
$user/$group
|
|
|
|
0
|
|
|
|
" "" ""
|
|
|
|
SKIP=
|
|
|
|
|
|
|
|
testing "cpio -R with create" \
|
|
|
|
"echo $0 | cpio -o -H newc -R 1234:5678 | cpio -tv 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \
|
|
|
|
"\
|
|
|
|
1234/5678
|
|
|
|
0
|
|
|
|
" "" ""
|
|
|
|
SKIP=
|
|
|
|
|
|
|
|
testing "cpio -R with extract" \
|
|
|
|
"echo $0 | cpio -o -H newc | cpio -tv -R 8765:4321 2>&1 | tail -n +2 | awk ' { print \$2 } '; echo \$?" \
|
|
|
|
"\
|
|
|
|
8765/4321
|
|
|
|
0
|
|
|
|
" "" ""
|
|
|
|
SKIP=
|
|
|
|
|
2008-07-12 03:13:11 +05:30
|
|
|
# Clean up
|
|
|
|
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
|
2008-04-05 08:16:47 +05:30
|
|
|
|
|
|
|
exit $FAILCOUNT
|