问题
My app works with user txt-files (create, change, delete) inside any user-selected folder. I just internally store the bookmark to get access to that user-selected folder and files.
Now, with macOS Catalina when the source folder is inside iCloud Drive, system still allows me to create and edit files. But doesn't allow to trash one. When I try to do it via [[NSFileManager defaultManager] trashItemAtURL: ... ]
I get the following error:
Error Domain=NSCocoaErrorDomain
Code=3328
"<filename> couldn’t be moved to the trash
because the volume “<APFS volume name>”
doesn’t have one."
UserInfo={
NSURL=file:///... <filepath>.txt,
NSUserStringVariant=Trash
}
Note: this only happens when the app is sandboxed.
Any ideas how to get the file trashed correctly?
P.S. I know there is a NSWorkspace recycle...
method, but it makes an extra deletion prompt that is not suitable for me.
P.P.S. I am still able to use [[NSFileManager defaultManager] removeItemAtURL: ...]
method, but I need the target file to be restorable in case user changes his mind.
回答1:
Ok. Looks like it's a rare case. But if you've got into the same situation, here is what I've ended up with:
There is a deprecated function - FSMoveObjectToTrashSync
- that still works just fine. It saved my ass for now.
来源:https://stackoverflow.com/questions/58665074/trash-files-inside-user-selected-folder-inside-icloud-drive