diff --git a/Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift b/Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift index a4df3e3d..2c125186 100644 --- a/Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift +++ b/Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift @@ -173,7 +173,7 @@ public final class MuxUpload : Hashable, Equatable { MuxUploadSDK.logger?.warning("start() called but upload is already in progress") fileWorker?.addDelegate( withToken: id, - InternalUploaderDelegate { [weak self] state in self?.handleStateUpdate(state) } + InternalUploaderDelegate { [self] state in handleStateUpdate(state) } ) fileWorker?.start() return diff --git a/Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift b/Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift index 4e0b79fa..48230a2f 100644 --- a/Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift +++ b/Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift @@ -22,7 +22,6 @@ class ChunkedFileUploader { private var currentWorkTask: Task<(), Never>? = nil private var _currentState: InternalUploadState = .ready private var overallProgress: Progress = Progress() - private var lastSeenUpdate: InternalUploadState? = nil private var lastReadCount: UInt64 = 0 private let reporter = Reporter() @@ -121,20 +120,17 @@ class ChunkedFileUploader { notifyStateFromWorker(.success(success)) } catch { file.close() - if let lastUpdate = lastSeenUpdate { - switch lastUpdate { - case .uploading(let update): do { - if lastReadCount > 0 { - lastReadCount = UInt64(update.progress.completedUnitCount) - } - } - default: break + if error is CancellationError { + MuxUploadSDK.logger?.debug("Task finished due to cancellation in state \(String(describing: self.currentState))") + if case let .uploading(update) = self.currentState { + self._currentState = .paused(update) } + } else { + MuxUploadSDK.logger?.debug("Task finished due to error in state \(String(describing: self.currentState))") + let uploadError = InternalUploaderError(reason: error, lastByte: lastReadCount) + notifyStateFromWorker(.failure(uploadError)) } - let uploadError = InternalUploaderError(reason: error, lastByte: lastReadCount) - notifyStateFromWorker(.failure(uploadError)) } - } currentWorkTask = task } diff --git a/Sources/MuxUploadSDK/Upload/UploadPersistence.swift b/Sources/MuxUploadSDK/Upload/UploadPersistence.swift index 71f5ed72..8114a95a 100644 --- a/Sources/MuxUploadSDK/Upload/UploadPersistence.swift +++ b/Sources/MuxUploadSDK/Upload/UploadPersistence.swift @@ -27,7 +27,8 @@ class UploadPersistence { try remove(entryAtAbsUrl: upload.uploadURL) } } catch { - MuxUploadSDK.logger?.critical("Swallowed error writing to UploadPersistence! Error below:\n\(error.localizedDescription)") + // This makes a lot of noise on the emulator, but might be worth logging if you're having issues around here + //MuxUploadSDK.logger?.critical("Swallowed error writing to UploadPersistence! Error below:\n\(error.localizedDescription)") } } @@ -81,8 +82,6 @@ class UploadPersistence { func maybeOpenCache() throws { if cache == nil { - MuxUploadSDK.logger?.info("Had to populate write-through cache") - try self.uploadsFile.maybeOpenCache() self.cache = try uploadsFile.readContents().asDictionary() try cleanUpOldEntries() // Obligatory @@ -207,7 +206,6 @@ fileprivate struct UploadsFileImpl : UploadsFile { func maybeOpenCache() throws { let dir = fileURL.deletingLastPathComponent() if !FileManager.default.fileExists(atPath: dir.path) { - MuxUploadSDK.logger?.info("Had to create temp dir") try FileManager.default.createDirectory(atPath: dir.path, withIntermediateDirectories: true) }