Skip to content

Commit

Permalink
coding
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Jul 11, 2024
1 parent 59e30a4 commit 0def0f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ extension FileProviderExtension: NCNetworkingDelegate {

func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: Date?, size: Int64, task: URLSessionTask, error: NKError) {
guard let url = task.currentRequest?.url,
let metadataTemp = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return }
let ocIdTemp = metadataTemp.ocId
let metadata = tableMetadata.init(value: metadataTemp)
outstandingOcIdTemp[ocIdTemp] = ocId
let metadata = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return }
let ocIdTemp = metadata.ocId

if error == .success, let ocId, size == metadata.size {
// New file
if ocId != ocIdTemp {
// Signal update
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, delete: true)
}

/// SIGNAL DELETE
fileProviderData.shared.signalEnumerator(ocId: ocIdTemp, delete: true)
metadata.fileName = fileName
metadata.serverUrl = serverUrl
metadata.uploadDate = (date as? NSDate) ?? NSDate()
Expand All @@ -61,15 +55,13 @@ extension FileProviderExtension: NCNetworkingDelegate {

NCManageDatabase.shared.addMetadata(metadata)
NCManageDatabase.shared.addLocalFile(metadata: metadata)
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))

// New file
if ocId != ocIdTemp {
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
// File system
let atPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocIdTemp)
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
}
// File system
let atPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocIdTemp)
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId)
utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
/// SIGNAL UPDATE
fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, update: true)
} else {
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
Expand Down
5 changes: 3 additions & 2 deletions File Provider Extension/FileProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import Alamofire
class FileProviderExtension: NSFileProviderExtension {
let providerUtility = fileProviderUtility()
let utilityFileSystem = NCUtilityFileSystem()
var outstandingOcIdTemp: [String: String] = [:]

override init() {
super.init()
Expand Down Expand Up @@ -219,14 +218,16 @@ class FileProviderExtension: NSFileProviderExtension {
assert(pathComponents.count > 2)
let itemIdentifier = NSFileProviderItemIdentifier(pathComponents[pathComponents.count - 2])
let fileName = pathComponents[pathComponents.count - 1]
var ocId = itemIdentifier.rawValue
let ocId = itemIdentifier.rawValue

/*
if outstandingOcIdTemp[ocId] != nil && outstandingOcIdTemp[ocId] != ocId {
ocId = outstandingOcIdTemp[ocId]!
let atPath = utilityFileSystem.getDirectoryProviderStorageOcId(itemIdentifier.rawValue, fileNameView: fileName)
let toPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)
utilityFileSystem.copyFile(atPath: atPath, toPath: toPath)
}
*/

guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return }

Expand Down

0 comments on commit 0def0f2

Please sign in to comment.