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:
- Is there a way to make xattr accept this large value? Somehow pipe it in via standard input? man page does not show it, but I am not an expert and maybe there is some creative way to do it
- Can anyone tell me the proper way to apply a large extended attribute using stock command line tools?
- if there is no stock command line tools, any recommendations for 3rd party tools?