I am working on a program that copies files and folders from point a to point b, it's pretty simple for the most part. I decided to use the copyfile function to do the actual copying because it handles all of the metadata. For whatever reason there are many files that it can't copy, even if I'm running it as root. An example file that can't be copied is /usr/share/emacs/22.1/etc/BABYL
I don't know why it does this. The file itself is good, I can go to it in Finder and copy and paste it like it was any other ordinary file. Is there some permission issue that I am missing? It seems to do this only for system files, but not all of them. It is consistent in what it will and will not copy.
The actual function call looks like this
copyfile(filePath, destPath, gState,
COPYFILE_DATA | COPYFILE_ACL | COPYFILE_STAT | COPYFILE_XATTR);
The error I'm getting is not very useful, just IO error 5.
Is there something I am missing that causes it not to work for some files? Or will copyfile just not do certian things? Are there better ways than copyfile to copy files and all of their attributes/metadata?
Please don't suggest other programs that copy files, that's not what I'm here for. Thanks!