Let's say user renames a file/folder in FileProvider extension. modifyItem
callback is invoked where we issue a rename request to the server. Server responds with an error (ie user doesn't have permission to rename the relevant file/folder). We invoke the completionHandler
with error code, but the renamed file/folder will remain in the file system.
What is the best way to revert file/folder name to the original one (before the rename attempt)?
Simplified code would ideally be something like:
func modifyItem(_ item: NSFileProviderItem, baseVersion version: NSFileProviderItemVersion,
changedFields: NSFileProviderItemFields, contents newContents: URL?,
options: NSFileProviderModifyItemOptions = [], request: NSFileProviderRequest,
completionHandler: @escaping (NSFileProviderItem?,
NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress {
let node = localDatabase.getNode(item.id)
let originalFilename = node.filename
node.filename = item.filename
let result = server.performRename(item.filename)
if result == false {
// TODO: revert item to original filename
node.filename = originalFilename
let retItem = node.item()
completionHandler(retItem, [], false, NSError(domain: NSFileProviderErrorDomain, code: NSFileProviderError.Code.cannotSynchronize.rawValue, userInfo: [:]))
}else{
let retItem = node.item()
completionHandler(retItem, [], false, nil)
}
}
But this doesn't revert the file/folder filename value, it just shows file/folder in Finder with cloud-error icon that upsync failed. But I would also like to revert the renamed file/folder to the original value.
I suppose you will have to signal about the change in the working set and then subsequently provide the deleted and added item when requested.