4

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!

ATSOTECK
  • 79
  • 1
  • 5
  • Does it always fail on the same files? Does it fail on that file if that's the only one you attempt to copy? Are you sure that it's not possible that there's really an I/O error when reading the source or writing the destination? Check the system console log to see if any actual disk I/O errors are logged. – Ken Thomases May 15 '15 at 07:51
  • There are 841 files that fail to copy, this is when I attempt to copy the whole disk. It is consistent in what fails to copy. If I go into the console there are error messages that say "app_name on open file_path input output error". I could understand this if it were just the drive being bad but I can go to these files in Finder and copy/paste them just fine, and both drives pass the SMART test with no errors. – ATSOTECK May 15 '15 at 22:34
  • Did you ever find the answer to this? – uchuugaka Feb 15 '19 at 04:25
  • I ask, because I see the same result. – uchuugaka Feb 15 '19 at 04:26

1 Answers1

1

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

CRD
  • 52,522
  • 5
  • 70
  • 86
  • Thanks, I will try that and see if I can get any useful errors from that. – ATSOTECK May 15 '15 at 22:29
  • This is a suggested approach but not really an answer to the question. – uchuugaka Feb 15 '19 at 04:26
  • 1
    @uchuugaka - True, because it wasn't possible to know what the actual issue was but it was possible to suggest how to track it down. If you are facing the same issue you can try the same method to discover the problem. Good hunting! – CRD Feb 16 '19 at 05:52
  • I’m actually doing that. Figuring out all the makefiles now. – uchuugaka Feb 17 '19 at 06:03