简体   繁体   中英

copyfile function on Mac OS X

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!

You are going to have to dig deeper yourself to find your problem, fortunately you can dig inside copyfile() itself. Apple provides the full source which you can link into your code and then trace through it to find the problem.

Note: You may have to tweak the source a little to get it to compile, but it is straightforward enough to do so. However if you try and get stuck ask another question with details of what you've tried and what's gone wrong, somebody will probably help you.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM