Skip to content

ci: change tar command on macOS runners #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

williamboman
Copy link

@williamboman williamboman commented Apr 22, 2025

There seems to be some weird behaviour going on when creating compressed
tarballs with bsdtar this way (redirecting stdout). The produced files
seems OK, but gzip itself struggles to decompress it without errors,
resulting in a "trailing garbage ignored" error message and exit code 2
(it still decompresses the file just fine though). This error doesn't
surface when decompressing using bsdtar directly, but it does when
using gnutar.

See mason-org/mason-registry#9775.

If you have a Mac you should be able to reproduce this assuming tar -> bsdtar and that you have gnutar installed as gtar.

 $ echo Hello > file
 $ tar -cvz file > archive.tar.gz
 $ gzip -d -c archive.tar.gz > /dev/null
 # exit code 2 and gzip: archive.tar.gz: trailing garbage ignored

 # Method 1: Create tarball first and then gzip
 $ tar -cv file > archive.tar
 $ gzip archive.tar
 $ gzip -d -c archive.tar.gz > /dev/null
 # works fine!

 # Method 2: Create compressed tarball with the -f flag
 $ tar -czf archive.tar.gz file
 $ gzip -d -c archive.tar.gz > /dev/null
 # works fine!

I figured I'd open a PR since I found this somewhat interesting and
spent some time debugging it. Not entirely sure I've even found the root
cause but I believe this should help.

On my system this is the hexdump difference: https://www.diffchecker.com/z7Xqcfu8/. Right side is redirecting stdout, left side is using -f.

There seems to be some weird behaviour going on when creating compressed
tarballs with `bsdtar` this way (redirecting stdout). The produced files
seems OK, but `gzip` itself struggles to decompress it without errors,
resulting in a "trailing garbage ignored" error message and exit code 2
(it still decompresses the file just fine though). This error doesn't
surface when decompressing using `bsdtar` directly, but it does when
using `gnutar`.

See mason-org/mason-registry#9775.

If you have a Mac you should be able to reproduce this assuming `tar ->
bsdtar` and that you have `gnutar` installed as `gtar`.

```sh
 $ echo Hello > file
 $ tar -cvz file > archive.tar.gz
 $ gzip -d -c archive.tar.gz > /dev/null
 # exit code 2 and gzip: archive.tar.gz: trailing garbage ignored

 # Method 1: Create tarball first and then gzip
 $ tar -cv file > archive.tar
 $ gzip archive.tar
 $ gzip -d -c archive.tar.gz > /dev/null
 # works fine!

 # Method 2: Create compressed tarball with the -f flag
 $ tar -czf archive.tar.gz file
 $ gzip -d -c archive.tar.gz > /dev/null
 # works fine!
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant