OS X tarballs: a saga of extended attributes

Are you a Mac user? Creating a tarball? Beware!

Today I ran into a problem where a tar file that I created had a bunch of ._ files:

$ tar tvf ../bokeh-0.2.tgz
drwxr-xr-x 0 pwang staff 0 Oct 23 15:12 bokeh-0.2/
-rw-r--r-- 0 pwang staff 226 Oct 23 15:04 bokeh-0.2/._.gitattributes
-rw-r--r-- 0 pwang staff 31 Oct 23 15:04 bokeh-0.2/.gitattributes
-rw-r--r-- 0 pwang staff 226 Oct 23 15:04 bokeh-0.2/._.gitignore
-rw-r--r-- 0 pwang staff 1047 Oct 23 15:04 bokeh-0.2/.gitignore
-rwxr-xr-x 0 pwang staff 226 Oct 23 15:04 bokeh-0.2/._bokeh
drwxr-xr-x 0 pwang staff 0 Oct 23 15:04 bokeh-0.2/bokeh/
-rwxr-xr-x 0 pwang staff 226 Oct 23 15:04 bokeh-0.2/._bokeh-server
-rwxr-xr-x 0 pwang staff 1681 Oct 23 15:04 bokeh-0.2/bokeh-server
-rw-r--r-- 0 pwang staff 226 Oct 23 15:04 bokeh-0.2/._CHANGELOG
-rw-r--r-- 0 pwang staff 1388 Oct 23 15:04 bokeh-0.2/CHANGELOG
...

When I looked in the source directory which I was tarring up, I see no such files. What gives?

It turns out that OS X’s version of tar will automatically create these ._ versions for each file that has extended properties and attributes, because it does not want that information lost. Extended attributes are an aspect of the HFS+ filesystem which OS X uses. If you ever do an “ls -l” and see an “@” symbol near the permissions on your files, that indicates that it has extended attributes:

$ ls -l
total 128
-rw-r--r--@ 1 pwang staff 1388 Oct 23 15:04 CHANGELOG
-rw-r--r--@ 1 pwang staff 2587 Oct 23 15:04 QUICKSTART.md

To list these attributes, you do “ls -@”:

$ ls -@l
total 128
-rw-r--r--@ 1 pwang staff 1388 Oct 23 15:04 CHANGELOG
com.apple.quarantine 71
-rw-r--r--@ 1 pwang staff 2587 Oct 23 15:04 QUICKSTART.md
com.apple.quarantine 71

To strip these off, you use the xattr command:

$ xattr -d com.apple.quarantine CHANGELOG

To strip the attributes off of all files in a directory tree, use find:

$ find . -xattr -exec xattr -d com.apple.quarantine {} \;

Now you can create a tarball that won’t be offensive to your friends!

Advertisements

One thought on “OS X tarballs: a saga of extended attributes

  1. Aaron Meurer says:

    To be fair to Apple, the tar manpage says

    STANDARDS
    There is no current POSIX standard for the tar command; it appeared in ISO/IEC 9945-1:1996 (“POSIX.1”) but was dropped from IEEE Std
    1003.1-2001 (“POSIX.1”). The options used by this implementation were developed by surveying a number of existing tar implementations
    as well as the old POSIX specification for tar and the current POSIX specification for pax.

    The ustar and pax interchange file formats are defined by IEEE Std 1003.1-2001 (“POSIX.1”) for the pax command.

    So I guess they are free to modify it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: