mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 14:36:01 +03:00
Only try upload of modified item in FileProviderExtension if that had its contents changed and we have a valid content url
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
0f2fbf7518
commit
020c5d5104
1 changed files with 50 additions and 37 deletions
|
@ -396,54 +396,67 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
|
||||||
completionHandler(fpItem, [], false, nil)
|
completionHandler(fpItem, [], false, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Progress()
|
if itemTemplateIsFolder {
|
||||||
} else if itemTemplateIsFolder {
|
NSLog("Only handling renaming for folders. ocId: %@", item.itemIdentifier.rawValue)
|
||||||
|
return Progress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard !itemTemplateIsFolder else {
|
||||||
NSLog("System requested modification for folder with ocID %@ (%@) of something other than folder name.", item.itemIdentifier.rawValue, newServerUrlFileName)
|
NSLog("System requested modification for folder with ocID %@ (%@) of something other than folder name.", item.itemIdentifier.rawValue, newServerUrlFileName)
|
||||||
completionHandler(item, [], false, nil)
|
completionHandler(item, [], false, nil)
|
||||||
return Progress()
|
return Progress()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ncKit.upload(serverUrlFileName: newServerUrlFileName,
|
if changedFields.contains(.contents) {
|
||||||
fileNameLocalPath: fileNameLocalPath,
|
guard newContents != nil else {
|
||||||
requestHandler: { _ in
|
NSLog("WARNING. Could not upload modified contents as was provided nil contents url. ocId: %@", item.itemIdentifier.rawValue)
|
||||||
}, taskHandler: { task in
|
completionHandler(item, [], false, NSFileProviderError(.noSuchItem))
|
||||||
self.outstandingSessionTasks[newServerUrlFileName] = task
|
return Progress()
|
||||||
NSFileProviderManager(for: self.domain)?.register(task, forItemWithIdentifier: item.itemIdentifier, completionHandler: { _ in })
|
|
||||||
}, progressHandler: { _ in
|
|
||||||
|
|
||||||
}) { account, ocId, etag, date, size, _, _, error in
|
|
||||||
self.outstandingSessionTasks.removeValue(forKey: newServerUrlFileName)
|
|
||||||
|
|
||||||
guard error == .success, let ocId = ocId/*, size == itemTemplate.documentSize as! Int64*/ else {
|
|
||||||
NSLog("Could not upload item with filename: %@, received error: %@", item.filename, error.errorDescription)
|
|
||||||
completionHandler(nil, [], false, NSFileProviderError(.cannotSynchronize))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog("Successfully uploaded item with identifier: %@ and filename: %@", ocId, item.filename)
|
self.ncKit.upload(serverUrlFileName: newServerUrlFileName,
|
||||||
|
fileNameLocalPath: fileNameLocalPath,
|
||||||
|
requestHandler: { _ in
|
||||||
|
}, taskHandler: { task in
|
||||||
|
self.outstandingSessionTasks[newServerUrlFileName] = task
|
||||||
|
NSFileProviderManager(for: self.domain)?.register(task, forItemWithIdentifier: item.itemIdentifier, completionHandler: { _ in })
|
||||||
|
}, progressHandler: { _ in
|
||||||
|
|
||||||
let newMetadata = NextcloudItemMetadataTable()
|
}) { account, ocId, etag, date, size, _, _, error in
|
||||||
newMetadata.date = (date ?? NSDate()) as Date
|
self.outstandingSessionTasks.removeValue(forKey: newServerUrlFileName)
|
||||||
newMetadata.etag = etag ?? ""
|
|
||||||
newMetadata.account = account
|
|
||||||
newMetadata.fileName = item.filename
|
|
||||||
newMetadata.fileNameView = item.filename
|
|
||||||
newMetadata.ocId = ocId
|
|
||||||
newMetadata.size = size
|
|
||||||
newMetadata.contentType = item.contentType?.preferredMIMEType ?? ""
|
|
||||||
newMetadata.directory = itemTemplateIsFolder
|
|
||||||
newMetadata.serverUrl = parentItemMetadata.serverUrl
|
|
||||||
newMetadata.session = ""
|
|
||||||
newMetadata.sessionError = ""
|
|
||||||
newMetadata.sessionTaskIdentifier = 0
|
|
||||||
newMetadata.status = NextcloudItemMetadataTable.Status.normal.rawValue
|
|
||||||
|
|
||||||
dbManager.addLocalFileMetadataFromItemMetadata(newMetadata)
|
guard error == .success, let ocId = ocId/*, size == itemTemplate.documentSize as! Int64*/ else {
|
||||||
dbManager.addItemMetadata(newMetadata)
|
NSLog("Could not upload item with filename: %@, received error: %@", item.filename, error.errorDescription)
|
||||||
|
completionHandler(nil, [], false, NSFileProviderError(.cannotSynchronize))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let fpItem = FileProviderItem(metadata: newMetadata, parentItemIdentifier: parentItemIdentifier, ncKit: self.ncKit)
|
NSLog("Successfully uploaded item with identifier: %@ and filename: %@", ocId, item.filename)
|
||||||
|
|
||||||
completionHandler(fpItem, [], false, nil)
|
let newMetadata = NextcloudItemMetadataTable()
|
||||||
|
newMetadata.date = (date ?? NSDate()) as Date
|
||||||
|
newMetadata.etag = etag ?? ""
|
||||||
|
newMetadata.account = account
|
||||||
|
newMetadata.fileName = item.filename
|
||||||
|
newMetadata.fileNameView = item.filename
|
||||||
|
newMetadata.ocId = ocId
|
||||||
|
newMetadata.size = size
|
||||||
|
newMetadata.contentType = item.contentType?.preferredMIMEType ?? ""
|
||||||
|
newMetadata.directory = itemTemplateIsFolder
|
||||||
|
newMetadata.serverUrl = parentItemMetadata.serverUrl
|
||||||
|
newMetadata.session = ""
|
||||||
|
newMetadata.sessionError = ""
|
||||||
|
newMetadata.sessionTaskIdentifier = 0
|
||||||
|
newMetadata.status = NextcloudItemMetadataTable.Status.normal.rawValue
|
||||||
|
|
||||||
|
dbManager.addLocalFileMetadataFromItemMetadata(newMetadata)
|
||||||
|
dbManager.addItemMetadata(newMetadata)
|
||||||
|
|
||||||
|
let fpItem = FileProviderItem(metadata: newMetadata, parentItemIdentifier: parentItemIdentifier, ncKit: self.ncKit)
|
||||||
|
|
||||||
|
completionHandler(fpItem, [], false, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Progress()
|
return Progress()
|
||||||
|
|
Loading…
Reference in a new issue