Resource forks and tar

Volume 11, Issue 24; 22 Feb 2008; last modified 08 Oct 2010

Mac filesystems have “data forks” and “resource forks”. This is usually a really good thing. But only usually.

The use of resource forks on the Mac is really very clever. Resource forks are where the Mac stores information about what application created the file, what icon it should have, etc. It's technically a much better solution to the problem than relying on the filename extension and it's almost always transparent to the user.

Almost.

When you create a tar archive, for example:

$ tar cf - `find api -type f | grep -v \\.svn` | gzip > api.tar.gz

The odds are overwhelmingly high that you don't really want all those resource forks manifested in the archive with magic filenames:

$ tar zvtf api.tar.gz | grep Makefile
-rw-r--r-- ndw/ndw         161 2008-02-07 10:26:49 api/1.2.0/._Makefile
-rw-r--r-- ndw/ndw         251 2008-02-07 10:26:49 api/1.2.0/Makefile
-rw-r--r-- ndw/ndw         161 2008-02-09 18:28:57 api/1.2.1/._Makefile
-rw-r--r-- ndw/ndw         421 2008-02-09 18:28:57 api/1.2.1/Makefile

It turns out that you can tell tar this, but not with a command-line option, instead with an environment variable: COPYFILE_DISABLE. Setting that to “true” (or perhaps any value) tells tar not to copy resource forks. For added confusion, this apparently undocumented environment variable used to be called COPY_EXTENDED_ATTRIBUTES_DISABLE in versions of Mac OS X prior to “Leopard”. At least that works with the tar that ships with OS X:

$ export COPYFILE_DISABLE=true
$ tar cf - `find api -type f | grep -v \\.svn` | gzip > api.tar.gz
$ tar zvtf api.tar.gz | grep Makefile
-rw-r--r-- ndw/ndw         251 2008-02-07 10:26:49 api/1.2.0/Makefile
-rw-r--r-- ndw/ndw         421 2008-02-09 18:28:57 api/1.2.1/Makefile

Please pardon me while I barf on my shoes.

I hope this essay is useful to someone. But mostly I hope it helps me remember this little bit of magic so I don't have to go searching all over creation next time I bang my head on this problem.

Comments

Thanks, I was getting really frustrated with this. I knew about the old environment variable but had no idea it had changed.

—Posted by Vili on 15 Jun 2008 @ 10:41 UTC #

Thanks! Cleaning up those "._" files had gotten real annoying.

—Posted by Bill on 24 Aug 2008 @ 12:30 UTC #

Exactly what I wanted. Thanks very much!

—Posted by Simon on 08 Oct 2008 @ 12:47 UTC #

I should just note that while such features have largely gone out of use with Mac OS X, the resource fork's capabilities go far beyond storing file-type information. The resource fork is nothing less than a comprehensive database capable of holding all sorts of information - including icons, pictures, text, programme code, and so on - in a standard format accessible using only standard system routines. In fact, prior to the switch to PowerPC, most programmes consisted entirely of resources, with nothing in their data fork whatsoever.

—Posted by David Arthur on 08 Oct 2008 @ 01:17 UTC #

That was the solution for me. I tried it with --exclude, but that didn't work for me. Thanks!

—Posted by Jochen on 21 Oct 2008 @ 12:59 UTC #

This almost reads like a submission to the Daily WTF...

Thanks for documenting these environment variables.

—Posted by D Herring on 29 Oct 2008 @ 05:50 UTC #

THANKS THANKS THANKS! I was looking for ages for this switch in Leopard.

—Posted by jagger on 01 Jul 2009 @ 01:26 UTC #

COPYFILE_DISABLE works on Snow Leopard as well.

—Posted by Ben Jencks on 12 Oct 2009 @ 02:52 UTC #

Made my day; thanks for this! I confirm, as well, that this works in Snow Leopard.

—Posted by Roshambo on 18 Oct 2009 @ 10:08 UTC #

Cheers for this article, its one of the better write-ups on the root cause and solution.

Nice work!

—Posted by Kyle on 12 Apr 2010 @ 09:52 UTC #

Thank you - I've been struggling with this for a while!

—Posted by Doug on 23 Jun 2011 @ 10:15 UTC #

Works on Lion too ! Thx.

Tauop-Mac:sshGate Tauop$ uname -a
Darwin Tauop-Mac.local 11.0.0 Darwin Kernel Version 11.0.0: Sat Jun 18 12:56:35 PDT 2011; root:xnu-1699.22.73~1/RELEASE_X86_64 x86_64

—Posted by Tauop on 08 Aug 2011 @ 03:39 UTC #

Thanks, just the thing I was looking for! Oh, and while not documented, it seems they've patched their version of GNU/tar (though on MacOS 10.7 it says "BSDtar"):

http://www.opensource.apple.com/source/gnutar/gnutar-451/patches/EA.diff

Thanks again,
C.

—Posted by CK on 22 Feb 2012 @ 02:07 UTC #