mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-09-10 03:42:00 +02:00
Add try catch around scan download item
This commit is contained in:
@@ -563,28 +563,36 @@ 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 {
|
||||||
val scanLock = scanLocks.computeIfAbsent(scanDestinationKey(item)) { Any() }
|
try {
|
||||||
synchronized(scanLock) {
|
val scanLock = scanLocks.computeIfAbsent(scanDestinationKey(item)) { Any() }
|
||||||
folderScanner.scanDownloadItem(item) { scanResult ->
|
synchronized(scanLock) {
|
||||||
val event =
|
folderScanner.scanDownloadItem(item) { scanResult ->
|
||||||
JSObject().apply {
|
val event =
|
||||||
put("libraryItemId", item.id)
|
JSObject().apply {
|
||||||
put("localFolderId", item.localFolder.id)
|
put("libraryItemId", item.id)
|
||||||
scanResult?.localLibraryItem?.let {
|
put("localFolderId", item.localFolder.id)
|
||||||
put("localLibraryItem", JSObject(jacksonMapper.writeValueAsString(it)))
|
scanResult?.localLibraryItem?.let {
|
||||||
|
put("localLibraryItem", JSObject(jacksonMapper.writeValueAsString(it)))
|
||||||
|
}
|
||||||
|
scanResult?.localMediaProgress?.let {
|
||||||
|
put("localMediaProgress", JSObject(jacksonMapper.writeValueAsString(it)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scanResult?.localMediaProgress?.let {
|
clientEventEmitter.onDownloadItemComplete(event)
|
||||||
put("localMediaProgress", JSObject(jacksonMapper.writeValueAsString(it)))
|
synchronized(this@DownloadItemManager) {
|
||||||
}
|
downloadItemQueue.remove(item)
|
||||||
}
|
DeviceManager.dbManager.removeDownloadItem(item.id)
|
||||||
clientEventEmitter.onDownloadItemComplete(event)
|
}
|
||||||
synchronized(this@DownloadItemManager) {
|
|
||||||
finalizingItems.remove(item.id)
|
|
||||||
downloadItemQueue.remove(item)
|
|
||||||
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user