Resource forks and tar
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.
Thanks! Cleaning up those "._" files had gotten real annoying.
Exactly what I wanted. Thanks very much!
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.
That was the solution for me. I tried it with --exclude, but that didn't work for me. Thanks!
This almost reads like a submission to the Daily WTF...
Thanks for documenting these environment variables.
THANKS THANKS THANKS! I was looking for ages for this switch in Leopard.
COPYFILE_DISABLE works on Snow Leopard as well.
Made my day; thanks for this! I confirm, as well, that this works in Snow Leopard.
Cheers for this article, its one of the better write-ups on the root cause and solution.
Nice work!
Thank you - I've been struggling with this for a while!
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
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"):
Thanks again,
C.