Quarantined Files in Leopard

This short post will share some information I learned about quarantined files on Leopard and how I recursively removed my isolated files from quarantine.

Today I was working on a MacPort for RabbitMQ and noticed something odd when I tar‘d up the package:

$ tar cvfz rabbitmq-server-macport-1.5.3.tar.gz net
./._net
net/
net/._rabbitmq-server
net/rabbitmq-server/
net/rabbitmq-server/._files
...

Initially I was really confused by the files ._net, ._rabbitmq-server, etc., because they did not exist in the directory. Finally I noticed something interesting about the ls output:

$ ls -ld net
drwxr-xr-x@ 3 cpettitt  staff  102 Feb 24 22:35 net

The file had a special attribute (denoted by the @). A quick read of the ls manpage revealed that I could learn more about the @ property with ls -@:

$ ls -@ld net
drwxr-xr-x@ 3 cpettitt  staff  102 Feb 24 22:35 net
        com.apple.quarantine     42

Immediately I remembered that downloaded files are automatically quarantined by Leopard. It just so happens that I had download the package to test it and make changes. The files in the subdirectories of net were also quarantined, so I came up with a quick command to remove a tree of files from quarantine:

$ find . -print0 | xargs -0 xattr -l | grep com.apple.quarantine | 
         cut -d: -f1 | xargs -I% xattr -d com.apple.quarantine %

This command searches for all files starting from the root directory (.) and sends them to xargs. I used -print0 and -0 so that xargs handled files with whitespace correctly.

The xattr -l command lists all extended attributes for the file and the subsequent grep filters out all files but those that are quarantined. The cut pattern just pulls the filename from what appears to be a colon (:) separated list.

Finally I tell xattr to delete the quarantine attribute. I used the -I option to set up a replacement for % because it also forces xargs to only split on newlines and not all whitespace (including spaces in filenames).

Having freed my files, tar worked as I expected:

$ !tar
tar cvfz rabbitmq-server-macport-1.5.3.tar.gz net
net/
net/rabbitmq-server/
net/rabbitmq-server/files/
net/rabbitmq-server/files/rabbitmqctl_wrapper
net/rabbitmq-server/Portfile

Hopefully this will save someone else some time!

Comments

Add a Comment

Comment on this Article