From 8b1ea480950f4548f318c3aaf00cdf2d593d6897 Mon Sep 17 00:00:00 2001 From: Alberto Sendra Date: Wed, 16 Oct 2024 16:52:53 +0200 Subject: [PATCH] Fix OfflineEntry deletion when the file was not fully downloaded --- .../Player/OfflineEngine/OfflineEngine.swift | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Sources/Player/OfflineEngine/OfflineEngine.swift b/Sources/Player/OfflineEngine/OfflineEngine.swift index 4e096089..2ee5f68e 100644 --- a/Sources/Player/OfflineEngine/OfflineEngine.swift +++ b/Sources/Player/OfflineEngine/OfflineEngine.swift @@ -93,22 +93,16 @@ extension OfflineEngine: DownloadObserver { private extension OfflineEngine { func delete(offlineEntry: OfflineEntry) { - let mediaProduct = MediaProduct( - productType: offlineEntry.productType, - productId: offlineEntry.productId - ) - guard - let mediaUrl = offlineEntry.mediaURL, - let licenseUrl = offlineEntry.licenseURL - else { - return - } - do { let fileManager = PlayerWorld.fileManagerClient - try fileManager.removeItem(at: mediaUrl) - try fileManager.removeItem(at: licenseUrl) - try offlineStorage.delete(key: mediaProduct.productId) + if let mediaURL = offlineEntry.mediaURL { + try? fileManager.removeItem(at: mediaURL) + } + if let licenseURL = offlineEntry.licenseURL { + try? fileManager.removeItem(at: licenseURL) + } + try offlineStorage.delete(key: offlineEntry.productId) + let mediaProduct = MediaProduct(productType: offlineEntry.productType, productId: offlineEntry.productId) offlinerDelegate?.offlinedDeleted(for: mediaProduct) } catch { PlayerWorld.logger?.log(loggable: PlayerLoggable.deleteOfflinedItemFailed(error: error))