mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix stuck file upload
This commit is contained in:
parent
72340244c6
commit
e66f240918
@ -138,12 +138,18 @@ final class MediaBoxFileContextV2Impl: MediaBoxFileContext {
|
|||||||
self.fullPath = fullPath
|
self.fullPath = fullPath
|
||||||
self.metaPath = metaPath
|
self.metaPath = metaPath
|
||||||
|
|
||||||
|
if !FileManager.default.fileExists(atPath: self.partialPath) {
|
||||||
|
let _ = try? FileManager.default.removeItem(atPath: self.metaPath)
|
||||||
|
self.fileMap = MediaBoxFileMap()
|
||||||
|
self.fileMap.serialize(manager: self.manager, to: self.metaPath)
|
||||||
|
} else {
|
||||||
do {
|
do {
|
||||||
self.fileMap = try MediaBoxFileMap.read(manager: self.manager, path: self.metaPath)
|
self.fileMap = try MediaBoxFileMap.read(manager: self.manager, path: self.metaPath)
|
||||||
} catch {
|
} catch {
|
||||||
let _ = try? FileManager.default.removeItem(atPath: self.metaPath)
|
let _ = try? FileManager.default.removeItem(atPath: self.metaPath)
|
||||||
self.fileMap = MediaBoxFileMap()
|
self.fileMap = MediaBoxFileMap()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.destinationFile = self.manager.open(path: self.partialPath, mode: .readwrite)
|
self.destinationFile = self.manager.open(path: self.partialPath, mode: .readwrite)
|
||||||
|
|
||||||
@ -172,6 +178,17 @@ final class MediaBoxFileContextV2Impl: MediaBoxFileContext {
|
|||||||
completed: completed
|
completed: completed
|
||||||
)
|
)
|
||||||
if self.updateRangeRequest(request: request) {
|
if self.updateRangeRequest(request: request) {
|
||||||
|
if !self.isComplete, let truncationSize = self.fileMap.truncationSize, truncationSize == self.fileMap.sum {
|
||||||
|
self.isComplete = true
|
||||||
|
|
||||||
|
let linkResult = link(self.partialPath, self.fullPath)
|
||||||
|
if linkResult != 0 {
|
||||||
|
postboxLog("MediaBoxFileContextV2Impl: error while linking \(self.partialPath): \(linkResult)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.updateRequests()
|
||||||
|
|
||||||
return EmptyDisposable
|
return EmptyDisposable
|
||||||
} else {
|
} else {
|
||||||
let index = self.rangeRequests.add(request)
|
let index = self.rangeRequests.add(request)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user