[Mac] file copy

Miles Kaufmann milesck at umich.edu
Tue Jun 23 16:42:48 EDT 2009


On Jun 23, 2009, at 9:52 AM, Tobias Weber wrote:

> Hi,
> which is the best way to copy files on OS X? I want to preserve  
> resource
> forks and extended attributes.
>
> ...
>
> bin/cp -p

This.  cp -p, mv, rsync -E, tar, and other utilities will use the  
copyfile(3) API to preserve extended attributes, resource forks, and  
ACLs.  cp -Rp should be just as safe as a Finder copy--moreso if you  
run it as root--with the exception of preserving creation dates.  Or  
if you're worried about hard links, check out ditto(1).

You presumably already know this, but avoid shutil at all costs.

BackupBouncer (http://www.n8gray.org/code/backup-bouncer/) makes  
testing what gets preserved by various methods of copying quick and  
easy.

The results for a Finder copy:

Verifying:    basic-permissions ... FAIL (Critical)
Verifying:           timestamps ... ok (Critical)
Verifying:             symlinks ... ok (Critical)
Verifying:    symlink-ownership ... FAIL
Verifying:            hardlinks ... FAIL (Important)
Verifying:       resource-forks ...
    Sub-test:             on files ... ok (Critical)
    Sub-test:  on hardlinked files ... FAIL (Important)
Verifying:         finder-flags ... ok (Critical)
Verifying:         finder-locks ... ok
Verifying:        creation-date ... ok
Verifying:            bsd-flags ... ok
Verifying:       extended-attrs ...
    Sub-test:             on files ... ok (Important)
    Sub-test:       on directories ... ok (Important)
    Sub-test:          on symlinks ... ok
Verifying: access-control-lists ...
    Sub-test:             on files ... ok (Important)
    Sub-test:              on dirs ... ok (Important)
Verifying:                 fifo ... FAIL
Verifying:              devices ... FAIL
Verifying:          combo-tests ...
    Sub-test:  xattrs + rsrc forks ... ok
    Sub-test:     lots of metadata ... FAIL

sudo cp -Rp:

Verifying:    basic-permissions ... ok (Critical)
Verifying:           timestamps ... ok (Critical)
Verifying:             symlinks ... ok (Critical)
Verifying:    symlink-ownership ... ok
Verifying:            hardlinks ... FAIL (Important)
Verifying:       resource-forks ...
    Sub-test:             on files ... ok (Critical)
    Sub-test:  on hardlinked files ... FAIL (Important)
Verifying:         finder-flags ... ok (Critical)
Verifying:         finder-locks ... ok
Verifying:        creation-date ... FAIL
Verifying:            bsd-flags ... ok
Verifying:       extended-attrs ...
    Sub-test:             on files ... ok (Important)
    Sub-test:       on directories ... ok (Important)
    Sub-test:          on symlinks ... ok
Verifying: access-control-lists ...
    Sub-test:             on files ... ok (Important)
    Sub-test:              on dirs ... ok (Important)
Verifying:                 fifo ... ok
Verifying:              devices ... ok
Verifying:          combo-tests ...
    Sub-test:  xattrs + rsrc forks ... ok
    Sub-test:     lots of metadata ... ok

-Miles




More information about the Python-list mailing list