Skip to content

Commit

Permalink
Merge pull request #115 from tidal-music/alberto/fix-incomplete-downl…
Browse files Browse the repository at this point in the history
…oad-deletion

[Player] Fix OfflineEntry deletion edge cases
  • Loading branch information
asendra authored Oct 17, 2024
2 parents 468657d + 8b1ea48 commit ff0457a
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions Sources/Player/OfflineEngine/OfflineEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ff0457a

Please sign in to comment.