Trash files inside user-selected folder inside iCloud Drive

混江龙づ霸主 提交于 2020-12-09 04:24:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!