t5000: test long filenames

Add a file with a long name to the test archive in order to check entries with pax extended headers. Also add a check for tar versions that doen't understand this format. Those versions should extract the headers as a regular files. Add code to check_tar() to interpret the path header if present, so that our tests work even with those tar versions. It's important to use the fallback code only if needed to still be able to detect git archive errorously creating pax headers as regular file entries (with a suitable tar version, of course). The archive used to check for pax header support in tar was generated using GNU tar 1.26 and its option --format=pax. Tested successfully on NetBSD 6.1, which has a tar version lacking pax header support. Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 20, 2013 at 11:58 UTC 9bf1ac41d215f9b1c026fe585a38ffa0555a5670
2 files changed +46
t/t5000-tar-tree.sh
+46
@@ -30,6 +30,32 @@ GUNZIP=${GUNZIP:-gzip -d}
30
31 SUBSTFORMAT=%H%n
32
33 +test_lazy_prereq TAR_NEEDS_PAX_FALLBACK '
34 + (
35 + mkdir pax &&
36 + cd pax &&
37 + "$TAR" xf "$TEST_DIRECTORY"/t5000/pax.tar &&
38 + test -f PaxHeaders.1791/file
39 + )
40 +'
41 +
42 +get_pax_header() {
43 + file=$1
44 + header=$2=
45 +
46 + while read len rest
47 + do
48 + if test "$len" = $(echo "$len $rest" | wc -c)
49 + then
50 + case "$rest" in
51 + $header*)
52 + echo "${rest#$header}"
53 + ;;
54 + esac
55 + fi
56 + done <"$file"
57 +}
58 +
59 check_tar() {
60 tarfile=$1.tar
61 listfile=$1.lst
@@ -40,6 +66,24 @@ check_tar() {
66 (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile
67 '
68
69 + test_expect_success TAR_NEEDS_PAX_FALLBACK ' interpret pax headers' '
70 + (
71 + cd $dir &&
72 + for header in *.paxheader
73 + do
74 + data=${header%.paxheader}.data &&
75 + if test -h $data -o -e $data
76 + then
77 + path=$(get_pax_header $header path) &&
78 + if test -n "$path"
79 + then
80 + mv "$data" "$path"
81 + fi
82 + fi
83 + done
84 + )
85 + '
86 +
87 test_expect_success ' validate filenames' '
88 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
89 test_cmp a.lst $listfile
@@ -54,6 +98,8 @@ test_expect_success \
98 'populate workdir' \
99 'mkdir a &&
100 echo simple textfile >a/a &&
101 + ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
102 + echo long filename >a/four$hundred &&
103 mkdir a/bin &&
104 cp /bin/sh a/bin &&
105 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
t/t5000/pax.tar
Binary files /dev/null and b/t/t5000/pax.tar differ