|
@@ -39,11 +39,12 @@ extension NCNetworking {
|
|
var uploadErrorDescription: String = ""
|
|
var uploadErrorDescription: String = ""
|
|
var filesNames = NCManageDatabase.shared.getChunks(account: metadata.account, ocId: metadata.ocId)
|
|
var filesNames = NCManageDatabase.shared.getChunks(account: metadata.account, ocId: metadata.ocId)
|
|
if filesNames.count == 0 {
|
|
if filesNames.count == 0 {
|
|
-
|
|
|
|
- do {
|
|
|
|
- try filesNames = chunkedFile(inputDirectory: directoryProviderStorageOcId, outputDirectory: directoryProviderStorageOcId, fileName: metadata.fileName, chunkSizeMB: chunkSize)
|
|
|
|
|
|
+
|
|
|
|
+ filesNames = NCCommunicationCommon.shared.chunkedFile(inputDirectory: directoryProviderStorageOcId, outputDirectory: directoryProviderStorageOcId, fileName: metadata.fileName, chunkSizeMB: chunkSize)
|
|
|
|
+
|
|
|
|
+ if filesNames.count > 0 {
|
|
NCManageDatabase.shared.addChunks(account: metadata.account, ocId: metadata.ocId, chunkFolder: chunkFolder, fileNames: filesNames)
|
|
NCManageDatabase.shared.addChunks(account: metadata.account, ocId: metadata.ocId, chunkFolder: chunkFolder, fileNames: filesNames)
|
|
- } catch {
|
|
|
|
|
|
+ } else {
|
|
NCContentPresenter.shared.messageNotification("_error_", description: "_err_file_not_found_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode:NCGlobal.shared.errorReadFile, forced: true)
|
|
NCContentPresenter.shared.messageNotification("_error_", description: "_err_file_not_found_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode:NCGlobal.shared.errorReadFile, forced: true)
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
|
|
return completion(uploadErrorCode, uploadErrorDescription)
|
|
return completion(uploadErrorCode, uploadErrorDescription)
|
|
@@ -223,53 +224,79 @@ extension NCNetworking {
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl":metadata.serverUrl])
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl":metadata.serverUrl])
|
|
}
|
|
}
|
|
|
|
|
|
- @objc func chunkedFile(inputDirectory: String, outputDirectory: String, fileName: String, chunkSizeMB:Int, bufferSize: Int = 1000000) throws-> [String] {
|
|
|
|
|
|
+ /*
|
|
|
|
+ @objc func chunkedFile(inputDirectory: String, outputDirectory: String, fileName: String, chunkSizeMB:Int, bufferSize: Int = 1000000) -> [String] {
|
|
|
|
|
|
let fileManager: FileManager = .default
|
|
let fileManager: FileManager = .default
|
|
var isDirectory: ObjCBool = false
|
|
var isDirectory: ObjCBool = false
|
|
let chunkSize = chunkSizeMB * 1000000
|
|
let chunkSize = chunkSizeMB * 1000000
|
|
var outputFilesName: [String] = []
|
|
var outputFilesName: [String] = []
|
|
- let reader: FileHandle = try .init(forReadingFrom: URL(fileURLWithPath: inputDirectory + "/" + fileName))
|
|
|
|
|
|
+ var reader: FileHandle?
|
|
var writer: FileHandle?
|
|
var writer: FileHandle?
|
|
- var buffer: Data?
|
|
|
|
var chunk: Int = 0
|
|
var chunk: Int = 0
|
|
var counter: Int = 0
|
|
var counter: Int = 0
|
|
|
|
|
|
if !fileManager.fileExists(atPath:outputDirectory, isDirectory:&isDirectory) {
|
|
if !fileManager.fileExists(atPath:outputDirectory, isDirectory:&isDirectory) {
|
|
- try fileManager.createDirectory(atPath: outputDirectory, withIntermediateDirectories: true, attributes: nil)
|
|
|
|
|
|
+ do {
|
|
|
|
+ try fileManager.createDirectory(atPath: outputDirectory, withIntermediateDirectories: true, attributes: nil)
|
|
|
|
+ } catch {
|
|
|
|
+ return []
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ do {
|
|
|
|
+ reader = try .init(forReadingFrom: URL(fileURLWithPath: inputDirectory + "/" + fileName))
|
|
|
|
+ } catch {
|
|
|
|
+ return []
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
repeat {
|
|
repeat {
|
|
|
|
|
|
- if chunk >= chunkSize {
|
|
|
|
- writer?.closeFile()
|
|
|
|
- writer = nil
|
|
|
|
- chunk = 0
|
|
|
|
- counter += 1
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let chunkRemaining: Int = chunkSize - chunk
|
|
|
|
- buffer = reader.readData(ofLength: min(bufferSize, chunkRemaining))
|
|
|
|
-
|
|
|
|
- if let buffer = buffer {
|
|
|
|
|
|
+ let bufferCounter = autoreleasepool { () -> Int in
|
|
|
|
+
|
|
|
|
+ if chunk >= chunkSize {
|
|
|
|
+ writer?.closeFile()
|
|
|
|
+ writer = nil
|
|
|
|
+ chunk = 0
|
|
|
|
+ counter += 1
|
|
|
|
+ print("Counter: \(counter)")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let chunkRemaining: Int = chunkSize - chunk
|
|
|
|
+ let buffer = reader?.readData(ofLength: min(bufferSize, chunkRemaining))
|
|
|
|
|
|
if writer == nil {
|
|
if writer == nil {
|
|
|
|
|
|
let fileNameChunk = fileName + String(format: "%010d", counter)
|
|
let fileNameChunk = fileName + String(format: "%010d", counter)
|
|
let outputFileName = outputDirectory + "/" + fileNameChunk
|
|
let outputFileName = outputDirectory + "/" + fileNameChunk
|
|
fileManager.createFile(atPath: outputFileName, contents: nil, attributes: nil)
|
|
fileManager.createFile(atPath: outputFileName, contents: nil, attributes: nil)
|
|
- writer = try .init(forWritingTo: URL(fileURLWithPath: outputFileName))
|
|
|
|
|
|
+
|
|
|
|
+ do {
|
|
|
|
+ writer = try .init(forWritingTo: URL(fileURLWithPath: outputFileName))
|
|
|
|
+ } catch { }
|
|
|
|
+
|
|
outputFilesName.append(fileNameChunk)
|
|
outputFilesName.append(fileNameChunk)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if let buffer = buffer {
|
|
|
|
+ writer?.write(buffer)
|
|
|
|
+ chunk = chunk + buffer.count
|
|
|
|
+
|
|
|
|
+ return buffer.count
|
|
|
|
+ }
|
|
|
|
|
|
- writer?.write(buffer)
|
|
|
|
- chunk = chunk + buffer.count
|
|
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if bufferCounter == 0 {
|
|
|
|
+ break
|
|
}
|
|
}
|
|
|
|
|
|
- } while buffer?.count ?? 0 > 0
|
|
|
|
|
|
+ } while true
|
|
|
|
|
|
writer?.closeFile()
|
|
writer?.closeFile()
|
|
- reader.closeFile()
|
|
|
|
|
|
+ reader?.closeFile()
|
|
return outputFilesName
|
|
return outputFilesName
|
|
}
|
|
}
|
|
|
|
+ */
|
|
}
|
|
}
|