libarchive icon indicating copy to clipboard operation
libarchive copied to clipboard

Creating a tar archive with --no-xattr doesn't exclude extended attributes

Open AndrewBelt opened this issue 1 year ago • 1 comments

On MacOS 15.2 compiled from Homebrew, when creating a tar archive with the tar command, --no-xattr doesn't ignore extended attributes of files.

$ tar --version
bsdtar 3.5.3 - libarchive 3.5.3 zlib/1.2.12 liblzma/5.4.3 bz2lib/1.0.8 

$ touch test
# Add an extended attribute
$ xattr -w hello world test 
# Verify that it was added
$ xattr -l test 
hello: world

$ tar -c --no-xattr -f test.tar test

# Extract it to a new directory
$ mkdir a
$ tar -xf test.tar -C a
# Extended attribute is still there despite --no-xattr
$ xattr -l a/test 
hello: world

AndrewBelt avatar Jan 22 '25 22:01 AndrewBelt

On macOS, tar has two ways of storing extended attributes: as extended attributes and in AppleDouble format. By default it does both. --no-xattr disables only the former. --no-mac-metadata disables only the latter.

To exclude all extended attributes, in your example above, you can use:

$ tar -c --no-xattr --no-mac-metadata -f test.tar test

bshand avatar Oct 13 '25 14:10 bshand