In macOS FileProviderExtension, when user deletes an item in Finder, a deleteItem callback is invoked. And here I don't mean trashing the item but really deleting it.
Now let's consider following scenario:
- User selects an item (file or folder) in Finder
- User on keyboard presses
Cmd+Backspace
to Delete the item - Item disappears in Finder
- A
deleteItem(identifier:version:options:request:completionHandler)
is invoked - In
deleteItem
we try to delete the item on the server - Server responds with 403 Forbidden
- Now we would like to return the deleted item so that it reappears in the Finder because it couldn't be deleted on the server (since ie the user doesn't have the permission to delete the relevant file)
Is there a way we can achieve this rollback of deleted item so that it reappears in the Finder after unsuccessful deletion on the server?
I know that we can control whether Finder should allow item deletion by setting allowsDeleting
capability in FileProviderItem
's capabilities
.
However, for whatever reason, it could be that on item-delete attempt, server responds with error indicating that the user does NOT have the permission to delete the file.
So as a result, the file (or folder) should reappear in the Finder instead of disappearing (forever).
Now, in deleteItem
callback an error can be returned but the file remains deleted. Is there a way to return an error such that file would be returned back?
For example, invoking a completion handler like
completionHandler(NSFileProviderError(.deletionRejected))
might hint a Finder that it should restore the deleted item, however that doesn't happen.