Skip to contentSkip to conversation

making t5000 "tar xf" tests more lenient

LHF In review Junio C Hamano 4 participants 23 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I've been running testsuite on a few platforms that are unfamiliar to me, and was bitten by BSD implementation of tar that do not grok the extended pax headers. I've already fixed one in t9502 [*1*] where we produce a tarball with "git archive" and then try to validate it with the platform implementation of "tar" so that the test won't barf when it sees the extended pax header.

t5000 is littered with similar tests that break unnecessarily with BSD implementations. I think what it wants to test are:

- "archive" produces tarball, and "tar" can extract from it. If your "tar" does not understand pax header, you may get it as an extra file that shouldn't be there, but that should not cause the test to fail---in real life, people without a pax-aware "tar" will just ignore and remove the header and can go on.

- "get-tar-commmit-id" can inspect a tarball produced by "archive" to recover the object name of the commit even on a platform without a pax-aware "tar".

Perhaps t5000 can be restructured like so:

- create a tarball with the commit-id and test with "get-tar-commit-id" to validate it; also create a tarball out of a tree to make sure it does not have commit-id and check with "get-tar-commit-id". Do this on any and all platform, even on the ones without a pax-aware "tar".

- check platform implementation of "tar" early to see if extracting a simple output from "git archive" results in an extra pax header file. If so, remember this fact and produce any and all tarballs used in the remainder of the test by forcing ^{tree}.

so that people on platforms without pax-aware "tar" do not have to install GNU tar only to pass this test.

It would be a good exercise during the holiday week for somebody on BSD (it seems NetBSD is more troublesome than OpenBSD) to come up with a patch to help users on these platforms.

Thanks.

[Footnote]

*1* http://thread.gmane.org/gmane.comp.version-control.git/211803

#1 lore raw

Am 24.12.2012 21:49, schrieb Junio C Hamano:

Quoted 33 lines

I've been running testsuite on a few platforms that are unfamiliar to me, and was bitten by BSD implementation of tar that do not grok the extended pax headers. I've already fixed one in t9502 [*1*] where we produce a tarball with "git archive" and then try to validate it with the platform implementation of "tar" so that the test won't barf when it sees the extended pax header.

t5000 is littered with similar tests that break unnecessarily with BSD implementations. I think what it wants to test are:

- "archive" produces tarball, and "tar" can extract from it. If your "tar" does not understand pax header, you may get it as an extra file that shouldn't be there, but that should not cause the test to fail---in real life, people without a pax-aware "tar" will just ignore and remove the header and can go on.

- "get-tar-commmit-id" can inspect a tarball produced by "archive" to recover the object name of the commit even on a platform without a pax-aware "tar".

Perhaps t5000 can be restructured like so:

- create a tarball with the commit-id and test with "get-tar-commit-id" to validate it; also create a tarball out of a tree to make sure it does not have commit-id and check with "get-tar-commit-id". Do this on any and all platform, even on the ones without a pax-aware "tar".

- check platform implementation of "tar" early to see if extracting a simple output from "git archive" results in an extra pax header file. If so, remember this fact and produce any and all tarballs used in the remainder of the test by forcing ^{tree}.

Quoted 6 lines

so that people on platforms without pax-aware "tar" do not have to install GNU tar only to pass this test.

It would be a good exercise during the holiday week for somebody on BSD (it seems NetBSD is more troublesome than OpenBSD) to come up with a patch to help users on these platforms.

I got around to building a virtual machine with NetBSD 6.0.1, which involved a bit of cursing because networking only seems to work when I turn off ACPI and SMP -- and running tests is a lot more pleasant with more than one CPU.

Anyway, I don't think the pax headers are to blame here. The patch below fixes the tar failures for me, but I'm not sure why. There must be something special about some (not all!) directory entries with trailing slashes after directory names.

Several ZIP tests still fail, however, because NetBSD's unzip doesn't seem to support (our flavour of) symlinks and streamed files.

I'll take a deeper look into it over the weekend.

René

---
 archive-tar.c | 2 ++
 1 file changed, 2 insertions(+)
archive-tar.c +2 -0
index 0ba3f25..fd2d3e8 100644
@@ -215,6 +215,8 @@ static int write_tar_entry(struct archiver_args *args,
 	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
 		*header.typeflag = TYPEFLAG_DIR;
 		mode = (mode | 0777) & ~tar_umask;
+		if (pathlen && path[pathlen - 1] == '/')
+			pathlen--;
 	} else if (S_ISLNK(mode)) {
 		*header.typeflag = TYPEFLAG_LNK;
 		mode |= 0777;
Signature · 1 line
1.7.12
#2 lore raw
Quoted 1 line · René Scharfe

Anyway, I don't think the pax headers are to blame here.

Hmph, I am reasonably sure I saw a test that created an archive from a commit (hence with pax header), asked platform tar to either list the contents or actually extracted to the filesystem, and tried to ensure nothing but the paths in the repository existed in the archive. When the platform tar implementation treated the pax header as an extra file, such a test sees something not in the repository and fails.

This was on (and I am still on) NetBSD 6.0 not 6.0.1, by the way.

#3 lore raw

Am 05.01.2013 21:11, schrieb Junio C Hamano:

Quoted 11 lines
Quoted 1 line · René Scharfe

Anyway, I don't think the pax headers are to blame here.

Hmph, I am reasonably sure I saw a test that created an archive from a commit (hence with pax header), asked platform tar to either list the contents or actually extracted to the filesystem, and tried to ensure nothing but the paths in the repository existed in the archive. When the platform tar implementation treated the pax header as an extra file, such a test sees something not in the repository and fails.

t5000 avoids that issue by comparing only the contents of a subdirectory. The script could do with a little cleanup, in any case. Moving ZIP testing into its own file, more explicit pax header file handling, speaking file and directory names, and modern coding style would all be nice. :)

René

#4 lore raw
In reply to René Scharfe
Quoted 7 lines · René Scharfe

Anyway, I don't think the pax headers are to blame here. The patch below fixes the tar failures for me, but I'm not sure why. There must be something special about some (not all!) directory entries with trailing slashes after directory names.

Several ZIP tests still fail, however, because NetBSD's unzip doesn't seem to support (our flavour of) symlinks and streamed files.

Just FYI, I found that unzip that comes with base distro and the one you can add via pkg_add (or pkgin) are different, and the latter seemed to behave better.

#5 lore raw

PATCH 1/1 archive-tar: split long paths more carefully

In reply to Junio C Hamano

The name field of a tar header has a size of 100 characters. This limit was extended long ago in a backward compatible way by providing the additional prefix field, which can hold 155 additional characters. The actual path is constructed at extraction time by concatenating the prefix field, a slash and the name field.

get_path_prefix() is used to determine which slash in the path is used as the cutting point and thus which part of it is placed into the field prefix and which into the field name. It tries to cram as much into the prefix field as possible. (And only if we can't fit a path into the provided 255 characters we use a pax extended header to store it.)

If a path is longer than 100 but shorter than 156 characters and ends with a slash (i.e. is for a directory) then get_path_prefix() puts the whole path in the prefix field and leaves the name field empty. GNU tar reconstructs the path without complaint, but the tar included with NetBSD 6 does not: It reports the header to be invalid.

For compatibility with this version of tar, make sure to never leave the name field empty. In order to do that, trim the trailing slash from the part considered as possible prefix, if it exists -- that way the last path component (or more, but not less) will end up in the name field.

---
 archive-tar.c | 2 ++
 1 file changed, 2 insertions(+)
archive-tar.c +2 -0
index 0ba3f25..923daf5 100644
@@ -153,6 +153,8 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
 static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen)
 {
 	size_t i = pathlen;
+	if (i > 1 && path[i - 1] == '/')
+		i--;
 	if (i > maxlen)
 		i = maxlen;
 	do {
Signature · 1 line
1.7.12
#6 lore raw

Re: [PATCH] archive-tar: split long paths more carefully

archive-tar.c static unsigned int ustar_header_chksum(const struct ustar_header *header) · line 157

Quoted 8 lines · René Scharfe
archive-tar.c +2 -0
@@ -153,6 +153,8 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
 static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen)
 {
 	size_t i = pathlen;
+	if (i > 1 && path[i - 1] == '/')
+		i--;

Beautiful.

#7 lore raw

Re: [PATCH] archive-tar: split long paths more carefully

In reply to René Scharfe
Quoted 18 lines · René Scharfe

The name field of a tar header has a size of 100 characters. This limit was extended long ago in a backward compatible way by providing the additional prefix field, which can hold 155 additional characters. The actual path is constructed at extraction time by concatenating the prefix field, a slash and the name field.

get_path_prefix() is used to determine which slash in the path is used as the cutting point and thus which part of it is placed into the field prefix and which into the field name. It tries to cram as much into the prefix field as possible. (And only if we can't fit a path into the provided 255 characters we use a pax extended header to store it.)

If a path is longer than 100 but shorter than 156 characters and ends with a slash (i.e. is for a directory) then get_path_prefix() puts the whole path in the prefix field and leaves the name field empty. GNU tar reconstructs the path without complaint, but the tar included with NetBSD 6 does not: It reports the header to be invalid.

Quoted 4 lines

For compatibility with this version of tar, make sure to never leave the name field empty. In order to do that, trim the trailing slash from the part considered as possible prefix, if it exists -- that way the last path component (or more, but not less) will end up in the name field.

Nicely explained; thanks.

Makes me wonder what we should do for a file inside a directory whose name is 10 bytes long, and whose filename is 120 bytes long, though.

Sounds like people on NetBSD are SOL due to the 155+'/'+100 in such a case and there is nothing we can do, I guess.

Quoted 18 lines
---
 archive-tar.c | 2 ++
 1 file changed, 2 insertions(+)
archive-tar.c +2 -0
index 0ba3f25..923daf5 100644
@@ -153,6 +153,8 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
 static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen)
 {
 	size_t i = pathlen;
+	if (i > 1 && path[i - 1] == '/')
+		i--;
 	if (i > maxlen)
 		i = maxlen;
 	do {
#8 lore raw

PATCH 1/1 archive-zip: write uncompressed size into header even with streaming

In reply to Junio C Hamano

We record the uncompressed and compressed sizes and the CRC of streamed files as zero in the local header of the file. The actual values are recorded in an extra data descriptor after the file content, and in the usual ZIP directory entry at the end of the archive.

While we know the compressed size and the CRC only after we processed the contents, we actually know the uncompressed size right from the start. And for files that we store uncompressed we also already know their final size.

Do it like InfoZIP's zip and recored the known values, even though they can be reconstructed using the ZIP directory and the data descriptors alone. InfoZIP's unzip worked fine before, but NetBSD's version actually depends on these fields.

The uncompressed size is already set by sha1_object_info(). We just need to initialize the compressed size to zero or the uncompressed size depending on the compression method (0 means storing). The CRC was propertly initialized already.

---
 archive-zip.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
archive-zip.c +2 -5
index 55f66b4..d3aef53 100644
@@ -240,7 +240,7 @@ static int write_zip_entry(struct archiver_args *args,
 			(mode & 0111) ? ((mode) << 16) : 0;
 		if (S_ISREG(mode) && args->compression_level != 0 && size > 0)
 			method = 8;
-		compressed_size = size;
+		compressed_size = (method == 0) ? size : 0;
 
 		if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
 		    size > big_file_threshold) {
@@ -313,10 +313,7 @@ static int write_zip_entry(struct archiver_args *args,
 	copy_le16(header.compression_method, method);
 	copy_le16(header.mtime, zip_time);
 	copy_le16(header.mdate, zip_date);
-	if (flags & ZIP_STREAM)
-		set_zip_header_data_desc(&header, 0, 0, 0);
-	else
-		set_zip_header_data_desc(&header, size, compressed_size, crc);
+	set_zip_header_data_desc(&header, size, compressed_size, crc);
 	copy_le16(header.filename_length, pathlen);
 	copy_le16(header.extra_length, ZIP_EXTRA_MTIME_SIZE);
 	write_or_die(1, &header, ZIP_LOCAL_HEADER_SIZE);
Signature · 1 line
1.7.12
#9 lore raw

cover ZIP test fixes

In reply to Junio C Hamano

Fix a bug in two scripts that call unzip, use the opportunity for a small cleanup, move all ZIP related tests out of t5000 and finally skip testing symlinks if unzip doesn't support them.

The first one allows running t5000 with the unzip from pkgsrc manually on NetBSD, which succeeds. The last one -- together with the archive-zip streaming patch I sent earlier today -- makes the ZIP tests succeed on that platform out of the box.

René

t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead t0024, t5000: use test_lazy_prereq for UNZIP t5000, t5002: move ZIP tests into their own script
t5002: check if unzip supports symlinks

 t/t0024-crlf-archive.sh      |  16 +++---
 t/t5000-tar-tree.sh          |  71 -----------------------
 t/t5002-archive-zip.sh       | 131 +++++++++++++++++++++++++++++++++++++++++++
 t/t5002/infozip-symlinks.zip | Bin 0 -> 328 bytes
 t/test-lib.sh                |   2 +
 5 files changed, 140 insertions(+), 80 deletions(-)
 create mode 100755 t/t5002-archive-zip.sh
 create mode 100644 t/t5002/infozip-symlinks.zip
Signature · 1 line
1.7.12
#10 lore raw

PATCH 1/4 t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead

InfoZIP's unzip takes default parameters from the environment variable UNZIP. Unset it in the test library and use GIT_UNZIP for specifying alternate versions of the unzip command instead.

t0024 wasn't even using variable for the actual extraction. t5000 was, but when setting it to InfoZIP's unzip it would try to extract from itself (because it treats the contents of $UNZIP as parameters), which failed of course.

---
 t/t0024-crlf-archive.sh |  6 +++---
 t/t5000-tar-tree.sh     | 10 +++++-----
 t/test-lib.sh           |  2 ++
 3 files changed, 10 insertions(+), 8 deletions(-)
t/t0024-crlf-archive.sh +3 -3
index ec6c1b3..080fe5c 100755
@@ -3,7 +3,7 @@
 test_description='respect crlf in git archive'
 
 . ./test-lib.sh
-UNZIP=${UNZIP:-unzip}
+GIT_UNZIP=${GIT_UNZIP:-unzip}
 
 test_expect_success setup '
 
@@ -26,7 +26,7 @@ test_expect_success 'tar archive' '
 
 '
 
-"$UNZIP" -v >/dev/null 2>&1
+"$GIT_UNZIP" -v >/dev/null 2>&1
 if [ $? -eq 127 ]; then
 	say "Skipping ZIP test, because unzip was not found"
 else
@@ -37,7 +37,7 @@ test_expect_success UNZIP 'zip archive' '
 
 	git archive --format=zip HEAD >test.zip &&
 
-	( mkdir unzipped && cd unzipped && unzip ../test.zip ) &&
+	( mkdir unzipped && cd unzipped && "$GIT_UNZIP" ../test.zip ) &&
 
 	test_cmp sample unzipped/sample
 
t/t5000-tar-tree.sh +5 -5
index ecf00ed..1f7593d 100755
@@ -25,7 +25,7 @@ commit id embedding:
 '
 
 . ./test-lib.sh
-UNZIP=${UNZIP:-unzip}
+GIT_UNZIP=${GIT_UNZIP:-unzip}
 GZIP=${GZIP:-gzip}
 GUNZIP=${GUNZIP:-gzip -d}
 
@@ -37,9 +37,9 @@ check_zip() {
 	dir=$1
 	dir_with_prefix=$dir/$2
 
-	test_expect_success UNZIP " extract ZIP archive" "
-		(mkdir $dir && cd $dir && $UNZIP ../$zipfile)
-	"
+	test_expect_success UNZIP " extract ZIP archive" '
+		(mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
+	'
 
 	test_expect_success UNZIP " validate filenames" "
 		(cd ${dir_with_prefix}a && find .) | sort >$listfile &&
@@ -201,7 +201,7 @@ test_expect_success \
       test_cmp a/substfile2 g/prefix/a/substfile2
 '
 
-$UNZIP -v >/dev/null 2>&1
+"$GIT_UNZIP" -v >/dev/null 2>&1
 if [ $? -eq 127 ]; then
 	say "Skipping ZIP tests, because unzip was not found"
 else
t/test-lib.sh +2 -0
index 8a12cbb..d8ec408 100644
@@ -85,6 +85,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
 		.*_TEST
 		PROVE
 		VALGRIND
+		UNZIP
 		PERF_AGGREGATING_LATER
 	));
 	my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
@@ -128,6 +129,7 @@ fi
 unset CDPATH
 
 unset GREP_OPTIONS
+unset UNZIP
 
 case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
 1|2|true)
Signature · 1 line
1.7.12
Reviewed-by on v1 1/4
#11 lore raw

Re: [PATCH 1/4] t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead

Quoted 8 lines · René Scharfe

InfoZIP's unzip takes default parameters from the environment variable UNZIP. Unset it in the test library and use GIT_UNZIP for specifying alternate versions of the unzip command instead.

t0024 wasn't even using variable for the actual extraction. t5000 was, but when setting it to InfoZIP's unzip it would try to extract from itself (because it treats the contents of $UNZIP as parameters), which failed of course.

That would only happen if the UNZIP variable was already exported, right?

The patch makes sense and takes care of all uses of ${UNZIP} I can find, and it even makes the quoting consistent so a person can put their copy of unzip under "/Program Files". For what it's worth,

#12 lore raw

Re: [PATCH 1/4] t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead

Am 07.01.2013 06:16, schrieb Jonathan Nieder:

Quoted 6 lines
Quoted 4 lines · René Scharfe

InfoZIP's unzip takes default parameters from the environment variable UNZIP. Unset it in the test library and use GIT_UNZIP for specifying alternate versions of the unzip command instead.

Quoted 7 lines
Quoted 4 lines

t0024 wasn't even using variable for the actual extraction. t5000 was, but when setting it to InfoZIP's unzip it would try to extract from itself (because it treats the contents of $UNZIP as parameters), which failed of course.

That would only happen if the UNZIP variable was already exported, right?

We don't want any parameters a user may have been specified influence the test. I'm not sure if someone actually sets that variable for that purpose, though.

My main use case is running individual test scripts with an alternative unzip binary, and with the patch this works as expected:

	$ cd t
	$ GIT_UNZIP=/usr/pkg/bin/unzip ./t5000-tar-tree.sh
Quoted 5 lines

The patch makes sense and takes care of all uses of ${UNZIP} I can find, and it even makes the quoting consistent so a person can put their copy of unzip under "/Program Files". For what it's worth,

Thanks!

René

#13 lore raw

PATCH 2/4 t0024, t5000: use test_lazy_prereq for UNZIP

In reply to René Scharfe

This change makes the code smaller and we can put it at the top of the script, its rightful place as setup code.

---
 t/t0024-crlf-archive.sh | 12 +++++-------
 t/t5000-tar-tree.sh     | 12 +++++-------
 2 files changed, 10 insertions(+), 14 deletions(-)
t/t0024-crlf-archive.sh +5 -7
index 080fe5c..ba397bb 100755
@@ -5,6 +5,11 @@ test_description='respect crlf in git archive'
 . ./test-lib.sh
 GIT_UNZIP=${GIT_UNZIP:-unzip}
 
+test_lazy_prereq UNZIP '
+	"$GIT_UNZIP" -v >/dev/null 2>&1
+	test $? -ne 127
+'
+
 test_expect_success setup '
 
 	git config core.autocrlf true &&
@@ -26,13 +31,6 @@ test_expect_success 'tar archive' '
 
 '
 
-"$GIT_UNZIP" -v >/dev/null 2>&1
-if [ $? -eq 127 ]; then
-	say "Skipping ZIP test, because unzip was not found"
-else
-	test_set_prereq UNZIP
-fi
-
 test_expect_success UNZIP 'zip archive' '
 
 	git archive --format=zip HEAD >test.zip &&
t/t5000-tar-tree.sh +5 -7
index 1f7593d..6702157 100755
@@ -31,6 +31,11 @@ GUNZIP=${GUNZIP:-gzip -d}
 
 SUBSTFORMAT=%H%n
 
+test_lazy_prereq UNZIP '
+	"$GIT_UNZIP" -v >/dev/null 2>&1
+	test $? -ne 127
+'
+
 check_zip() {
 	zipfile=$1.zip
 	listfile=$1.lst
@@ -201,13 +206,6 @@ test_expect_success \
       test_cmp a/substfile2 g/prefix/a/substfile2
 '
 
-"$GIT_UNZIP" -v >/dev/null 2>&1
-if [ $? -eq 127 ]; then
-	say "Skipping ZIP tests, because unzip was not found"
-else
-	test_set_prereq UNZIP
-fi
-
 test_expect_success \
     'git archive --format=zip' \
     'git archive --format=zip HEAD >d.zip'
Signature · 1 line
1.7.12
#14 lore raw

Re: [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP

Quoted 2 lines · René Scharfe

This change makes the code smaller and we can put it at the top of the script, its rightful place as setup code.

Would it be better to add the setting of GIT_UNZIP and test_lazy_prereq to test-lib.sh so they aren't duplicated in both t0024-crlf-archive.sh and t5000-tar-tree.sh, something like the following (modulo UNZIP/GIT_UNZIP)?

Signature · 2 lines
Matt Kraai
https://ftbfs.org/kraai
t/t0024-crlf-archive.sh +0 -8
index ec6c1b3..084f33c 100755
@@ -3,7 +3,6 @@
 test_description='respect crlf in git archive'
 
 . ./test-lib.sh
-UNZIP=${UNZIP:-unzip}
 
 test_expect_success setup '
 
@@ -26,13 +25,6 @@ test_expect_success 'tar archive' '
 
 '
 
-"$UNZIP" -v >/dev/null 2>&1
-if [ $? -eq 127 ]; then
-	say "Skipping ZIP test, because unzip was not found"
-else
-	test_set_prereq UNZIP
-fi
-
 test_expect_success UNZIP 'zip archive' '
 
 	git archive --format=zip HEAD >test.zip &&
t/t5000-tar-tree.sh +0 -8
index ecf00ed..85b64ae 100755
@@ -25,7 +25,6 @@ commit id embedding:
 '
 
 . ./test-lib.sh
-UNZIP=${UNZIP:-unzip}
 GZIP=${GZIP:-gzip}
 GUNZIP=${GUNZIP:-gzip -d}
 
@@ -201,13 +200,6 @@ test_expect_success \
       test_cmp a/substfile2 g/prefix/a/substfile2
 '
 
-$UNZIP -v >/dev/null 2>&1
-if [ $? -eq 127 ]; then
-	say "Skipping ZIP tests, because unzip was not found"
-else
-	test_set_prereq UNZIP
-fi
-
 test_expect_success \
     'git archive --format=zip' \
     'git archive --format=zip HEAD >d.zip'
t/test-lib.sh +7 -0
index 8a12cbb..4ceabad 100644
@@ -752,6 +752,13 @@ test_lazy_prereq AUTOIDENT '
 	git var GIT_AUTHOR_IDENT
 '
 
+UNZIP=${UNZIP:-unzip}
+
+test_lazy_prereq UNZIP '
+	"$UNZIP" -v >/dev/null 2>&1
+	test $? -ne 127
+'
+
 # When the tests are run as root, permission tests will report that
 # things are writable when they shouldn't be.
 test -w / || test_set_prereq SANITY
#15 lore raw

Re: [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP

Am 06.01.2013 19:06, schrieb Matt Kraai:

Quoted 8 lines · René Scharfe
Quoted 2 lines

This change makes the code smaller and we can put it at the top of the script, its rightful place as setup code.

Would it be better to add the setting of GIT_UNZIP and test_lazy_prereq to test-lib.sh so they aren't duplicated in both t0024-crlf-archive.sh and t5000-tar-tree.sh, something like the following (modulo UNZIP/GIT_UNZIP)?

We could do that in a follow-up patch, but I'm not sure it's worth it for the two use cases.

René

Reviewed-by on v1 2/4
#16 lore raw

Re: [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP

In reply to René Scharfe

t/t0024-crlf-archive.sh test_description='respect crlf in git archive' · line 10

Quoted 9 lines · René Scharfe
t/t0024-crlf-archive.sh +3 -0
@@ -5,6 +5,11 @@ test_description='respect crlf in git archive'
 . ./test-lib.sh
 GIT_UNZIP=${GIT_UNZIP:-unzip}
 
+test_lazy_prereq UNZIP '
+	"$GIT_UNZIP" -v >/dev/null 2>&1
+	test $? -ne 127

Micronit: now that this is part of a test, there is no more need to silence its output. The "unzip -v" output could be useful to people debugging with "t0024-crlf-archive.sh -v -i".

With or without that change, this is a nice cleanup and obviously correct, so

#17 lore raw

Re: [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP

Am 07.01.2013 09:45, schrieb Jonathan Nieder:

Quoted 8 lines
Quoted 6 lines · René Scharfe
t/t0024-crlf-archive.sh +0 -0
@@ -5,6 +5,11 @@ test_description='respect crlf in git archive'
  . ./test-lib.sh
  GIT_UNZIP=${GIT_UNZIP:-unzip}
 
Quoted 7 lines

t/t0024-crlf-archive.sh test_description='respect crlf in git archive' · line 10

Quoted 3 lines
t/t0024-crlf-archive.sh +3 -0
+test_lazy_prereq UNZIP '
+	"$GIT_UNZIP" -v >/dev/null 2>&1
+	test $? -ne 127

Micronit: now that this is part of a test, there is no more need to silence its output. The "unzip -v" output could be useful to people debugging with "t0024-crlf-archive.sh -v -i".

Oh, yes, good point.

Quoted 3 lines

With or without that change, this is a nice cleanup and obviously correct, so

Thanks,
René

#18 lore raw

PATCH 3/4 t5000, t5002: move ZIP tests into their own script

In reply to René Scharfe

This makes ZIP specific tweaks easier.

---
 t/t5000-tar-tree.sh    |  69 ----------------------------
 t/t5002-archive-zip.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+), 69 deletions(-)
 create mode 100755 t/t5002-archive-zip.sh
t/t5000-tar-tree.sh +0 -69
index 6702157..e7c240f 100755
@@ -25,37 +25,11 @@ commit id embedding:
 '
 
 . ./test-lib.sh
-GIT_UNZIP=${GIT_UNZIP:-unzip}
 GZIP=${GZIP:-gzip}
 GUNZIP=${GUNZIP:-gzip -d}
 
 SUBSTFORMAT=%H%n
 
-test_lazy_prereq UNZIP '
-	"$GIT_UNZIP" -v >/dev/null 2>&1
-	test $? -ne 127
-'
-
-check_zip() {
-	zipfile=$1.zip
-	listfile=$1.lst
-	dir=$1
-	dir_with_prefix=$dir/$2
-
-	test_expect_success UNZIP " extract ZIP archive" '
-		(mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
-	'
-
-	test_expect_success UNZIP " validate filenames" "
-		(cd ${dir_with_prefix}a && find .) | sort >$listfile &&
-		test_cmp a.lst $listfile
-	"
-
-	test_expect_success UNZIP " validate file contents" "
-		diff -r a ${dir_with_prefix}a
-	"
-}
-
 test_expect_success \
     'populate workdir' \
     'mkdir a b c &&
@@ -206,55 +180,12 @@ test_expect_success \
       test_cmp a/substfile2 g/prefix/a/substfile2
 '
 
-test_expect_success \
-    'git archive --format=zip' \
-    'git archive --format=zip HEAD >d.zip'
-
-check_zip d
-
-test_expect_success \
-    'git archive --format=zip in a bare repo' \
-    '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
-
-test_expect_success \
-    'git archive --format=zip vs. the same in a bare repo' \
-    'test_cmp d.zip d1.zip'
-
-test_expect_success 'git archive --format=zip with --output' \
-    'git archive --format=zip --output=d2.zip HEAD &&
-    test_cmp d.zip d2.zip'
-
-test_expect_success 'git archive with --output, inferring format' '
-	git archive --output=d3.zip HEAD &&
-	test_cmp d.zip d3.zip
-'
-
 test_expect_success 'git archive with --output, override inferred format' '
 	git archive --format=tar --output=d4.zip HEAD &&
 	test_cmp b.tar d4.zip
 '
 
 test_expect_success \
-    'git archive --format=zip with prefix' \
-    'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
-
-check_zip e prefix/
-
-test_expect_success 'git archive -0 --format=zip on large files' '
-	test_config core.bigfilethreshold 1 &&
-	git archive -0 --format=zip HEAD >large.zip
-'
-
-check_zip large
-
-test_expect_success 'git archive --format=zip on large files' '
-	test_config core.bigfilethreshold 1 &&
-	git archive --format=zip HEAD >large-compressed.zip
-'
-
-check_zip large-compressed
-
-test_expect_success \
     'git archive --list outside of a git repo' \
     'GIT_DIR=some/non-existing/directory git archive --list'
 
t/t5002-archive-zip.sh new file +119 -0

119 lines not on this page · raw message

Signature · 1 line
1.7.12
#19 lore raw

PATCH 4/4 t5002: check if unzip supports symlinks

In reply to René Scharfe

Only add a symlink to the repository if both the filesystem and unzip support symlinks. To check the latter, add a ZIP file containing a symlink, created like this with InfoZIP zip 3.0:

	$ echo sample text >textfile
	$ ln -s textfile symlink
	$ zip -y infozip-symlinks.zip textfile symlink

If we can extract it successfully, we add a symlink to the test repository for git archive --format=zip, or otherwise skip that step. Users can see the skipped test and perhaps run it again with a different unzip version.

---
 t/t5002-archive-zip.sh       |  26 +++++++++++++++++++-------
 t/t5002/infozip-symlinks.zip | Bin 0 -> 328 bytes
 2 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100644 t/t5002/infozip-symlinks.zip
t/t5002-archive-zip.sh +19 -7
index ac9c6d4..d35aa24 100755
@@ -12,6 +12,15 @@ test_lazy_prereq UNZIP '
 	test $? -ne 127
 '
 
+test_lazy_prereq UNZIP_SYMLINKS '
+	(
+		mkdir unzip-symlinks &&
+		cd unzip-symlinks &&
+		"$GIT_UNZIP" "$TEST_DIRECTORY"/t5002/infozip-symlinks.zip &&
+		test -h symlink
+	)
+'
+
 check_zip() {
 	zipfile=$1.zip
 	listfile=$1.lst
@@ -40,15 +49,18 @@ test_expect_success \
      cp /bin/sh a/bin &&
      printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
      printf "A not substituted O" >a/substfile2 &&
-     if test_have_prereq SYMLINKS; then
-	ln -s a a/l1
-     else
-	printf %s a > a/l1
-     fi &&
      (p=long_path_to_a_file && cd a &&
       for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
-      echo text >file_with_long_path) &&
-     (cd a && find .) | sort >a.lst'
+      echo text >file_with_long_path)
+'
+
+test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
+	ln -s a a/symlink_to_a
+'
+
+test_expect_success 'prepare file list' '
+	(cd a && find .) | sort >a.lst
+'
 
 test_expect_success \
     'add ignored file' \
t/t5002/infozip-symlinks.zip new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..065728c631cf1f7ab20a045a83abc3e08455eeba
GIT binary patch
Signature · 1 line
1.7.12
#20 lore raw

Re: [PATCH 4/4] t5002: check if unzip supports symlinks

Quoted 7 lines · René Scharfe

Only add a symlink to the repository if both the filesystem and unzip support symlinks. To check the latter, add a ZIP file containing a symlink, created like this with InfoZIP zip 3.0:

	$ echo sample text >textfile
	$ ln -s textfile symlink
	$ zip -y infozip-symlinks.zip textfile symlink

Hm. Do some implementations of "unzip" not support symlinks, or is the problem that some systems build Info-ZIP without the SYMLINKS option?

#21 lore raw

Re: [PATCH 4/4] t5002: check if unzip supports symlinks

Am 07.01.2013 09:52, schrieb Jonathan Nieder:

Quoted 6 lines
Quoted 4 lines · René Scharfe

Only add a symlink to the repository if both the filesystem and unzip support symlinks. To check the latter, add a ZIP file containing a symlink, created like this with InfoZIP zip 3.0:

Quoted 7 lines
Quoted 3 lines
	$ echo sample text >textfile
	$ ln -s textfile symlink
	$ zip -y infozip-symlinks.zip textfile symlink

Hm. Do some implementations of "unzip" not support symlinks, or is the problem that some systems build Info-ZIP without the SYMLINKS option?

The unzip supplied with NetBSD 6.0.1, which is based on libarchive, doesn't support symlinks. It creates a file with the link target path as its only content for such entries.

I assume that Info-ZIP is compiled with the SYMLINKS option on all platforms whose default filesystem supports symbolic links. Except on Windows perhaps, where it's complicated.

For the test script there is no difference: If we don't have a tool to verify symlinks in archives, we better skip that part.

René

#22 lore raw

Re: [PATCH 4/4] t5002: check if unzip supports symlinks

Quoted 9 lines · René Scharfe

Am 07.01.2013 09:52, schrieb Jonathan Nieder:

Quoted 3 lines

Hm. Do some implementations of "unzip" not support symlinks, or is the problem that some systems build Info-ZIP without the SYMLINKS option?

The unzip supplied with NetBSD 6.0.1, which is based on libarchive, doesn't support symlinks. It creates a file with the link target path as its only content for such entries.

Ok, that makes sense. A quick search finds
<https://code.google.com/p/libarchive/issues/detail?id=104>, which if I understand correctly was fixed in libarchive 3.0.2. NetBSD 6 uses a patched 2.8.4.

[...]

Quoted 2 lines

For the test script there is no difference: If we don't have a tool to verify symlinks in archives, we better skip that part.

Yeah, I just wanted to see if there were other parts of the world that needed fixing while at it. Thanks for explaining.

Ciao,
Jonathan