I'm trying to copy extended attributes from one file to another using the OSX "xattr" utility. The background is that we are building a backup tool and the files/structure must retain all attributes, ACLs, etc... Everything is working fine except large attributes like resource forks. Small attributes work fine using method below. Attempting this on OS X 10.7.5 Here is what I am doing:
First I identify the attributes on a file using "ls -l@". Result below:
-rwxrwxrwx@ 1 testuser staff 0 3 Jan 2011 File
com.apple.FinderInfo 32
com.apple.ResourceFork 237246
Now I export the attribute (com.apple.ResourceFork is the one causing issues):
xattr -px com.apple.ResourceFork File > attribfile
I now want to apply this attribute to the copy of the file on another mac using this command:
xattr -wx com.apple.ResourceFork "`cat attribfile`" File
This results in:
-bash: /usr/bin/xattr: Argument list too long
I think I know why it is happening... the resource fork data is way too long to fit in an argument. I have not established the threshold at which it starts to break but I suspect it has to do with ARG_MAX. xargs doesn't help here since it is not several smaller arguments, but one very large one.
So multiple questions:
I don't know of a way to do it with xattr
, but there's an old filesystem trick you can use. Note: this is basically obsolete, but still works in 10.8.2; I make no promises about 10.8.3 etc. If the attribfile is in hex format, use this:
xxd -r -p attribfile >File/..namedfork/rsrc
If the attribfile is raw, use cat
instead of xxd -r -p
. If the attribute is something other than the resource fork, ... I have no idea.