Add try catch around scan download item

This commit is contained in:
advplyr
2026-09-06 18:11:49 -05:00
parent 71bd354bc7
commit 30c4fa7e16
@@ -563,6 +563,7 @@ class DownloadItemManager(
if (!item.isDownloadFinished || !finalizingItems.add(item.id)) return if (!item.isDownloadFinished || !finalizingItems.add(item.id)) return
IncompleteDownloadCleanup.cancel(context, item.id) IncompleteDownloadCleanup.cancel(context, item.id)
scope.launch { scope.launch {
try {
val scanLock = scanLocks.computeIfAbsent(scanDestinationKey(item)) { Any() } val scanLock = scanLocks.computeIfAbsent(scanDestinationKey(item)) { Any() }
synchronized(scanLock) { synchronized(scanLock) {
folderScanner.scanDownloadItem(item) { scanResult -> folderScanner.scanDownloadItem(item) { scanResult ->
@@ -579,13 +580,20 @@ class DownloadItemManager(
} }
clientEventEmitter.onDownloadItemComplete(event) clientEventEmitter.onDownloadItemComplete(event)
synchronized(this@DownloadItemManager) { synchronized(this@DownloadItemManager) {
finalizingItems.remove(item.id)
downloadItemQueue.remove(item) downloadItemQueue.remove(item)
DeviceManager.dbManager.removeDownloadItem(item.id) DeviceManager.dbManager.removeDownloadItem(item.id)
notifyQueueChanged()
} }
} }
} }
} catch (e: Exception) {
// The files are already in place, so leave the item queued for restoreQueue to rescan.
AbsLogger.error(tag, "Could not finalize download item ${item.id}: ${e.message}")
} finally {
synchronized(this@DownloadItemManager) {
finalizingItems.remove(item.id)
notifyQueueChanged()
}
}
} }
} }