I have a sandboxed Cocoa app that allows the user to open and manipulate directories.
I'd like to disallow deleting special system folders such as the user's Documents and Desktop folders.
How can I tell if a file URL points to a special, protected system folder as defined in FileManager.SearchPathDirectory?
I use NSOpenPanel
to open a folder. For the desktop folder, I get:
/Users/bob/Desktop
Now, FileManager
has the handy method url(for:in:appropriateFor:create:)
for locating special directories. For example:
FileManager.default.url(for: .desktopDirectory,
in : .userDomainMask, appropriateFor: nil, create: false)
returns:
/Users/bob/Library/Containers/com.mycompany.app/Data/Desktop
... which is expected, as this is a sandboxed app. But the problem now is that comparing these two urls fails, although semantically, they represent the same folder. How can I tell that they indeed point to the same folder?