Manpage Monday: copyfile(3)
copyfile(3) is an API for copying and moving files within the file-system:
DESCRIPTION
These functions are used to copy a file’s data and/or metadata. (Metadata consists of permissions, extended attributes, access control lists, and so forth.)
The
copyfile()function can copy the namedfromfile to the namedtofile; thefcopyfile()function does the same, but using the file descriptors of already-opened files.
The
copyfile()andfcopyfile()functions can also have their behavior modified by the following flags:
COPYFILE_CHECKReturn a bitmask (corresponding to the flags argument) indicating which contents would be copied; no data are actually copied. (E.g., if
flagswas set toCOPYFILE_CHECK|COPYFILE_METADATA, and thefromfile had extended attributes but no ACLs, the return value would beCOPYFILE_XATTR.)COPYFILE_PACKSerialize the
fromfile. Thetofile is an AppleDouble-format file.COPYFILE_UNPACKUnserialize the
fromfile. Thefromfile is an AppleDouble-format file; thetofile will have the extended attributes, ACLs, resource fork, and FinderInfo data from thetofile, regardless of theflagsargument passed in.
File Manager also has APIs for copying files, in both asynchronous and synchronous flavors. Those APIs don’t provide as much control over management of metadata, but they do offer asynchronous operation, whereas the copyfile(3) APIs appear to be synchronous.
And, of course, I should mention NSWorkspace operations, which you use with the performFileOperation:source:destination:files:tag:
method. Unlike the other two, this API has been around since 10.0. On the other hand, like copyfile(3), it’s synchronous only.