aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/m_rootgnutar/mkgnutar.pl12
-rw-r--r--tests/m_rootgnutar/script43
2 files changed, 41 insertions, 14 deletions
diff --git a/tests/m_rootgnutar/mkgnutar.pl b/tests/m_rootgnutar/mkgnutar.pl
index cb4d6c27f..516124cdb 100644
--- a/tests/m_rootgnutar/mkgnutar.pl
+++ b/tests/m_rootgnutar/mkgnutar.pl
@@ -59,6 +59,7 @@ foreach my $fname (@entries) {
my $content = "";
my $type;
my $linkname = "";
+ my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
if (S_ISLNK($mode)) {
$type = 2;
$linkname = readlink $fname;
@@ -74,17 +75,18 @@ foreach my $fname (@entries) {
'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12',
$fname,
sprintf('%07o', $mode & 07777),
- sprintf('%07o', 1000), # uid
- sprintf('%07o', 1000), # gid
+ sprintf('%07o', $<), # uid
+ sprintf('%07o', $(), # gid
sprintf('%011o', length $content), # size
- sprintf('%011o', $mtime), # mtime
+ sprintf('%011o', $mtime),
+ # mtime
'', # checksum
$type,
$linkname, # linkname
"ustar ", # magic
" ", # version
- "josch", # username
- "josch", # groupname
+ "$username", # username
+ "$username", # groupname
'', # dev major
'', # dev minor
'', # prefix
diff --git a/tests/m_rootgnutar/script b/tests/m_rootgnutar/script
index 3d5cd7957..79fd2225b 100644
--- a/tests/m_rootgnutar/script
+++ b/tests/m_rootgnutar/script
@@ -1,5 +1,7 @@
# vim: filetype=sh
+use_mkgnutar=
+
test_description="create fs image from GNU tarball"
if ! test -x "$DEBUGFS_EXE"; then
echo "$test_name: $test_description: skipped (no debugfs)"
@@ -10,6 +12,21 @@ if [ "$(grep -c 'define HAVE_ARCHIVE_H' ../lib/config.h)" -eq 0 ]; then
exit 0
fi
+if test -z "$use_mkgnutar" ; then
+ if type ztar > /dev/null 2>&1 && \
+ tar --version 2>&1 | head -1 | grep -q "GNU tar" ; then
+ TAR=tar
+ elif type gtar > /dev/null 2>&1 && \
+ gtar --version 2>&1 | head -1 | grep -q "GNU tar" ; then
+ TAR=gtar
+ else
+ # if GNU tar is not available, fall back to using mkgnutar.pl
+ use_mkgnutar=yes
+# echo "$test_name: $test_description: skipped (no GNU tar)"
+# exit 0
+ fi
+fi
+
MKFS_TAR="$TMPFILE.tar"
MKFS_DIR="$TMPFILE.dir"
OUT="$test_name.log"
@@ -28,21 +45,26 @@ mkdir "$MKFS_DIR/test/emptydir"
mkdir "$MKFS_DIR/test/dir"
echo "will be overwritten" > "$MKFS_DIR/test/dir/file"
-if false; then
+if test -z "$use_mkgnutar"; then
# debugfs rdump does not preserve the timestamps when it extracts the
# files so we ignore them by using tar --clamp-mtime
# first write a partial tar
- tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cf "$MKFS_TAR.dupl" test
+ $TAR --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime \
+ --format=gnu -cf "$MKFS_TAR.dupl" test
# now overwrite the contents of a file
echo "Test me" > "$MKFS_DIR/test/dir/file"
# and update the tar so that it contains two entries for the same file
# we need this to test the code path that first unlinks and then overwrites an
# existing file
- tar -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -rf "$MKFS_TAR.dupl" test/dir/file
+ $TAR -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime \
+ --format=gnu -rf "$MKFS_TAR.dupl" test/dir/file
# also add a duplicate directory entry because those must not be unlinked
- echo test | tar -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -rf "$MKFS_TAR.dupl" --no-recursion --verbatim-files-from --files-from=-
+ echo test | $TAR -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime \
+ --format=gnu -rf "$MKFS_TAR.dupl" --no-recursion \
+ --verbatim-files-from --files-from=-
# also create a tarball of the directory with only one entry per file
- tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cf "$MKFS_TAR.uniq" test
+ $TAR --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime \
+ --format=gnu -cf "$MKFS_TAR.uniq" test
else
# same as above but without using GNU tar
perl $test_dir/mkgnutar.pl --nopadding --directory="$MKFS_DIR" --mtime "$DEBUGFS_EXE_MTIME" test > "$MKFS_TAR.dupl"
@@ -102,9 +124,11 @@ for ext in uniq dupl; do
$DEBUGFS -R "rdump /test $MKFS_DIR" "$TMPFILE.$ext" 2>&1;
echo Exit status is $?;
# debugfs rdump does not preserve the timestamps when it extracts the
- # files so we ignore them by using tar --clamp-mtime
- if false; then
- tar --sort=name -C "$MKFS_DIR" --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu -cvf "$TMPFILE.new.tar" test 2>&1;
+ if test -z "$use_mkgnutar"; then
+ # files so we ignore them by using tar --clamp-mtime
+ $TAR --sort=name -C "$MKFS_DIR" \
+ --mtime="$DEBUGFS_EXE" --clamp-mtime --format=gnu \
+ -cvf "$TMPFILE.new.tar" test 2>&1;
else
perl $test_dir/mkgnutar.pl --verbose --directory="$MKFS_DIR" --mtime "$DEBUGFS_EXE_MTIME" test 2>&1 > "$TMPFILE.new.tar";
fi;
@@ -140,5 +164,6 @@ else
diff $DIFF_OPTS "$EXP" "$OUT" > "$test_name.failed"
fi
-rm -rf "$MKFS_TAR.dupl" "$MKFS_TAR.uniq" "$TMPFILE.cmd1" "$TMPFILE.cmd2" "$TMPFILE.log"
+rm -rf "$MKFS_TAR.dupl" "$MKFS_TAR.uniq" "$TMPFILE.cmd1" "$TMPFILE.cmd2" \
+ "$TMPFILE.log" "$TMPFILE.dupl" "$TMPFILE.uniq" "$TMPFILE.testme"
unset MKFS_TAR MKFS_DIR OUT EXP