Dispose temp file

This commit is contained in:
Ali 2021-02-26 19:40:41 +04:00
parent 4ee5f8487a
commit e24920ae88
2 changed files with 7 additions and 2 deletions

View File

@ -258,7 +258,7 @@ private final class ImportManager {
if !pathExtension.isEmpty, let value = TGMimeTypeMap.mimeType(forExtension: pathExtension) { if !pathExtension.isEmpty, let value = TGMimeTypeMap.mimeType(forExtension: pathExtension) {
mimeType = value mimeType = value
} }
return ChatHistoryImport.uploadMedia(account: account, session: session, file: tempFile, fileName: entry.0.path, mimeType: mimeType, type: entry.2) return ChatHistoryImport.uploadMedia(account: account, session: session, file: tempFile, disposeFileAfterDone: true, fileName: entry.0.path, mimeType: mimeType, type: entry.2)
|> mapError { error -> ImportError in |> mapError { error -> ImportError in
switch error { switch error {
case .chatAdminRequired: case .chatAdminRequired:

View File

@ -107,7 +107,7 @@ public enum ChatHistoryImport {
case chatAdminRequired case chatAdminRequired
} }
public static func uploadMedia(account: Account, session: Session, file: TempBoxFile, fileName: String, mimeType: String, type: MediaType) -> Signal<Float, UploadMediaError> { public static func uploadMedia(account: Account, session: Session, file: TempBoxFile, disposeFileAfterDone: Bool, fileName: String, mimeType: String, type: MediaType) -> Signal<Float, UploadMediaError> {
var forceNoBigParts = true var forceNoBigParts = true
guard let size = fileSize(file.path), size != 0 else { guard let size = fileSize(file.path), size != 0 else {
return .single(1.0) return .single(1.0)
@ -160,6 +160,11 @@ public enum ChatHistoryImport {
|> mapToSignal { result -> Signal<Float, UploadMediaError> in |> mapToSignal { result -> Signal<Float, UploadMediaError> in
return .single(1.0) return .single(1.0)
} }
|> afterDisposed {
if disposeFileAfterDone {
TempBox.shared.dispose(file)
}
}
} }
} }