Wednesday, December 6, 2023

NSFileManager’s File Copy Error Messages Lie

Jeff Johnson:

The error says that the source file InstallHistory.plist doesn’t exist, but the file does exist! The true reason for the copy failure is that the destination directory /Users/Shared/nonexistent/ doesn’t exist. Sigh.

I tested my command-line tool all the way back to macOS 10.13 High Sierra, and the behavior is the same! This is an old bug in NSFileManager. And note that the bug is not restricted to path-based API: it also affects NSFileManager URL-based API.

This is a really old bug, and it affects other types of failures, not just NSFileNoSuchFileError. I first encountered it when working on the SpamSieve installer for Apple Mail. I would ask NSBundle for the copy of the plug-in that was built into the app and then try to copy it to a protected folder, but the error message would say that it didn’t have permission to read the source path that was in the app itself.

Comments RSS · Twitter · Mastodon

Leave a Comment