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

3.7k Views Asked by At

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?
2

There are 2 best solutions below

3
On BEST ANSWER

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.

0
On

The accepted answer did not work for me, so I continued and found another solution, which I post here in case other people need it.

My problem was copying vlc-2.1.4 to the /Applications folder. It kept saying:

The Finder can’t complete the operation because some data in “VLC” can’t be read or written.
(Error code -36)

And If I tried using a cp in the terminal i was getting the error indicated in this thread.

So what I did was to execute the following commands in the console (summarizing I tar the VLC and untar it in its destination, so ... it works as a cp):

cd /Volumes/vlc-2.1.4/
tar cf /Applications/vlc.tar  VLC.app
cd /Applications/
tar xf vlc.tar 
rm vlc.tar

I hope this will be useful for others with the same problem.