# tar on Mac does not like empty tar from git archive

5 messages from 2013-04-08 to 2013-04-10. Participants: BJ Hargrave, Jeff King, René Scharfe.
Thread: https://gitlist.dev/t/33437

## BJ Hargrave, 2013-04-08 18:36

Subject: tar on Mac does not like empty tar from git archive
Message-ID: <ABD0C67A-0B2B-4E32-AF49-93FBABC032A7@bjhargrave.com>
URL: https://gitlist.dev/e/ABD0C67A-0B2B-4E32-AF49-93FBABC032A7%40bjhargrave.com

```
Git 1.8.2.1 includes commit bd54cf17 - archive: handle commits with an empty tree

Test 2 of t5004-archive-corner-cases, "tar archive of empty tree is empty", fails on Mac OS X 10.8.3 (with XCode 4.6.1) since the tar command exits with return code 1 on the generated  tar file.

expecting success: 
	git archive --format=tar HEAD >empty.tar &&
	make_dir extract &&
	"$TAR" xf empty.tar -C extract &&
	check_dir extract

tar: Damaged tar archive
tar: Error exit delayed from previous errors.
not ok 2 - tar archive of empty tree is empty

tar tf "trash directory.t5004-archive-corner-cases/empty.tar"; echo $?
tar: Damaged tar archive
tar: Error exit delayed from previous errors.
1

tar --version
bsdtar 2.8.3 - libarchive 2.8.3

It appears that bsdtar does not like the empty tar files created by git archive. An empty tar file created by bsdtar is accepted.

tar cT /dev/null | tar t; echo $?
0

-- 

BJ Hargrave

```

## Jeff King, 2013-04-08 21:05

Subject: Re: tar on Mac does not like empty tar from git archive
Message-ID: <20130408210536.GB9649@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20130408210536.GB9649%40sigill.intra.peff.net
In-Reply-To: <ABD0C67A-0B2B-4E32-AF49-93FBABC032A7@bjhargrave.com>

```
On Mon, Apr 08, 2013 at 02:36:05PM -0400, BJ Hargrave wrote:

> Git 1.8.2.1 includes commit bd54cf17 - archive: handle commits with an
> empty tree
> 
> Test 2 of t5004-archive-corner-cases, "tar archive of empty tree is
> empty", fails on Mac OS X 10.8.3 (with XCode 4.6.1) since the tar
> command exits with return code 1 on the generated  tar file.

Hmm. So I guess the question is: do we need to work around this in the
test for platforms that do not like empty tar files, or are the empty
tarfiles we are making wrong somehow?

> tar --version
> bsdtar 2.8.3 - libarchive 2.8.3
> 
> It appears that bsdtar does not like the empty tar files created by
> git archive. An empty tar file created by bsdtar is accepted.
> 
> tar cT /dev/null | tar t; echo $?
> 0

That makes me think the latter ("we are wrong"). I don't have my OS X
box handy; can you provide a sample empty tarfile that it creates?

-Peff

```

## BJ Hargrave, 2013-04-08 22:07

Subject: Re: tar on Mac does not like empty tar from git archive
Message-ID: <9AA8143E-C8A2-4EB3-AB35-27C7031B4ED7@bjhargrave.com>
URL: https://gitlist.dev/e/9AA8143E-C8A2-4EB3-AB35-27C7031B4ED7%40bjhargrave.com
In-Reply-To: <20130408210536.GB9649@sigill.intra.peff.net>

```

On Apr 8, 2013, at 17:05 , Jeff King <peff@peff.net> wrote:

> That makes me think the latter ("we are wrong"). I don't have my OS X
> box handy; can you provide a sample empty tarfile that it creates?

I created mac.tar on my Mac and linux.tar on a RHEL6.3 machine (tar (GNU tar) 1.23). Both were created with 

tar cTf /dev/null xxx.tar

Both files are accepted by tar on both the Mac and the RHEL machines. (Both files contain nothing but zeros.)

-- 

BJ Hargrave



```

## René Scharfe, 2013-04-09 19:37

Subject: Re: tar on Mac does not like empty tar from git archive
Message-ID: <51646E12.2030506@lsrfire.ath.cx>
URL: https://gitlist.dev/e/51646E12.2030506%40lsrfire.ath.cx
In-Reply-To: <20130408210536.GB9649@sigill.intra.peff.net>

```
Am 08.04.2013 23:05, schrieb Jeff King:
> On Mon, Apr 08, 2013 at 02:36:05PM -0400, BJ Hargrave wrote:
> 
>> Git 1.8.2.1 includes commit bd54cf17 - archive: handle commits with an
>> empty tree
>>
>> Test 2 of t5004-archive-corner-cases, "tar archive of empty tree is
>> empty", fails on Mac OS X 10.8.3 (with XCode 4.6.1) since the tar
>> command exits with return code 1 on the generated  tar file.
> 
> Hmm. So I guess the question is: do we need to work around this in the
> test for platforms that do not like empty tar files, or are the empty
> tarfiles we are making wrong somehow?
> 
>> tar --version
>> bsdtar 2.8.3 - libarchive 2.8.3
>>
>> It appears that bsdtar does not like the empty tar files created by
>> git archive. An empty tar file created by bsdtar is accepted.
>>
>> tar cT /dev/null | tar t; echo $?
>> 0
> 
> That makes me think the latter ("we are wrong"). I don't have my OS X
> box handy; can you provide a sample empty tarfile that it creates?

libarchive (on which bsdtar is based) doesn't like extended pax headers
at the end of archives.  Here's the relevant source file:

https://github.com/libarchive/libarchive/blob/master/libarchive/archive_read_support_format_tar.c

tar_read_header() calls header_pax_global() to handle a global pax
header, which in turn calls tar_read_header() again to fetch the next
header.  If it reaches the end of the archive then err is set to
ARCHIVE_EOF and "Damaged tar archive" is reported at the end of this
function.

I tried come up with a small patch that convinces it to ignore such a
condition, but it's apparently not as easy as it looks -- I just made
bsdtar report even more obscure errors.  Will look deeper into it
later this week.

René

```

## René Scharfe, 2013-04-10 17:00

Subject: Re: tar on Mac does not like empty tar from git archive
Message-ID: <51659AA4.80203@lsrfire.ath.cx>
URL: https://gitlist.dev/e/51659AA4.80203%40lsrfire.ath.cx
In-Reply-To: <ABD0C67A-0B2B-4E32-AF49-93FBABC032A7@bjhargrave.com>

```
Am 08.04.2013 20:36, schrieb BJ Hargrave:
> Git 1.8.2.1 includes commit bd54cf17 - archive: handle commits with
> an empty tree
> 
> Test 2 of t5004-archive-corner-cases, "tar archive of empty tree is
> empty", fails on Mac OS X 10.8.3 (with XCode 4.6.1) since the tar
> command exits with return code 1 on the generated tar file.
> 
> expecting success:
> 	git archive --format=tar HEAD >empty.tar &&
> 	make_dir extract &&
> 	"$TAR" xf empty.tar -C extract &&
> 	check_dir extract
> 
> tar: Damaged tar archive
> tar: Error exit delayed from previous errors.
> not ok 2 - tar archive of empty tree is empty
> 
> tar tf "trash directory.t5004-archive-corner-cases/empty.tar"; echo $?
> tar: Damaged tar archive
> tar: Error exit delayed from previous errors.
> 1
> 
> tar --version
> bsdtar 2.8.3 - libarchive 2.8.3
> 
> It appears that bsdtar does not like the empty tar files created by
> git archive. An empty tar file created by bsdtar is accepted.
> 
> tar cT /dev/null | tar t; echo $?
> 0

I've opened an issue for libarchive for that behaviour:
http://code.google.com/p/libarchive/issues/detail?id=314

We can work around bsdtar's dislike of not-quite-empty tar archives by
leaving out the comment that contains the commit hash.

-- >8 --
Subject: t5004: fix issue with empty archive test and bsdtar

bsdtar, which is the default tar on Mac OS X, handles empty archives
just fine but reports archives containing only a pax extended header
comment as damaged.  Work around the issue by explicitly generating
the archive for the tree and not the commit, which causes git archive
to omit the commit hash comment record from the tar file.

Reported-by: BJ Hargrave <bj@bjhargrave.com>
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 t/t5004-archive-corner-cases.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index cdb7d7a..bfdb56a 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -28,7 +28,7 @@ check_dir() {
 }
 
 test_expect_success 'tar archive of empty tree is empty' '
-	git archive --format=tar HEAD >empty.tar &&
+	git archive --format=tar HEAD: >empty.tar &&
 	make_dir extract &&
 	"$TAR" xf empty.tar -C extract &&
 	check_dir extract
-- 
1.8.2.1

```
