Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download copy error logging #2556

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions podcasts/DownloadManager+URLSessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,26 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
}

func processEpisode(_ episode: BaseEpisode, downloadedFile location: URL, reportedContentType: String?) {
do {
var contentType = reportedContentType
var contentType = reportedContentType

if FeatureFlag.useMimetypePackage.enabled {
contentType = MimetypeHelper.contetType(for: location)
if let contentType, contentType != episode.contentType {
DataManager.sharedManager.saveEpisode(contentType: contentType, episode: episode)
}
if FeatureFlag.useMimetypePackage.enabled {
contentType = MimetypeHelper.contetType(for: location)
if let contentType, contentType != episode.contentType {
DataManager.sharedManager.saveEpisode(contentType: contentType, episode: episode)
}
}

let fileSize = FileManager.default.fileSize(of: location) ?? 0
guard isEpisodeFileValid(contentType: contentType, fileSize: fileSize) else {
markEpisode(episode, asFailedWithMessage: L10n.downloadErrorContactAuthorVersion2, reason: .suspiciousContent(fileSize))
return
}
let fileSize = FileManager.default.fileSize(of: location) ?? 0
guard isEpisodeFileValid(contentType: contentType, fileSize: fileSize) else {
markEpisode(episode, asFailedWithMessage: L10n.downloadErrorContactAuthorVersion2, reason: .suspiciousContent(fileSize))
return
}

let autoDownloadStatus = AutoDownloadStatus(rawValue: episode.autoDownloadStatus)!
let destinationPath = autoDownloadStatus == .playerDownloadedForStreaming ? streamingBufferPathForEpisode(episode) : pathForEpisode(episode)
let destinationUrl = URL(fileURLWithPath: destinationPath)
let autoDownloadStatus = AutoDownloadStatus(rawValue: episode.autoDownloadStatus)!
let destinationPath = autoDownloadStatus == .playerDownloadedForStreaming ? streamingBufferPathForEpisode(episode) : pathForEpisode(episode)
let destinationUrl = URL(fileURLWithPath: destinationPath)

do {
try StorageManager.copyItem(at: location, to: destinationUrl)

let newDownloadStatus: DownloadStatus = autoDownloadStatus == .playerDownloadedForStreaming ? .downloadedForStreaming : .downloaded
Expand All @@ -169,6 +169,7 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
EpisodeFileSizeUpdater.updateEpisodeDuration(episode: episode)
NotificationCenter.postOnMainThread(notification: Constants.Notifications.episodeDownloaded, object: episode.uuid)
} catch {
FileLog.shared.addMessage("DownloadManager: Failed to copy downloaded file from location: \(location.absoluteString) to destination: \(destinationPath) error: \(error)")
markEpisode(episode, asFailedWithMessage: L10n.downloadErrorNotEnoughSpace, reason: .badResponse)
}
}
Expand Down