Search code examples
macosshellcommand-linexattrfile-forks

Copy Mac com.apple.ResourceFork extended attribute causing "Argument list too long"


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:

  1. 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
  2. Can anyone tell me the proper way to apply a large extended attribute using stock command line tools?
  3. if there is no stock command line tools, any recommendations for 3rd party tools?

Solution

  • 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.