mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-08-03 07:01:56 +00:00
make backup listing resilient to corrupt archives
A corrupt or unreadable zip no longer aborts the whole loadBackups loop or leaks the zip handle - the entry check now sits inside the per-file try so one bad archive is skipped like any other invalid backup.
This commit is contained in:
parent
adcd1bae96
commit
4d7d7832ef
1 changed files with 13 additions and 14 deletions
|
|
@ -390,7 +390,7 @@ class BackupManager {
|
||||||
const fullFilePath = Path.join(this.backupPath, filename)
|
const fullFilePath = Path.join(this.backupPath, filename)
|
||||||
|
|
||||||
let zip = null
|
let zip = null
|
||||||
let data = null
|
let backup = null
|
||||||
try {
|
try {
|
||||||
zip = new StreamZip.async({ file: fullFilePath })
|
zip = new StreamZip.async({ file: fullFilePath })
|
||||||
const entries = await zip.entries()
|
const entries = await zip.entries()
|
||||||
|
|
@ -407,25 +407,24 @@ class BackupManager {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
data = await zip.entryData('details')
|
const data = await zip.entryData('details')
|
||||||
|
const details = data.toString('utf8').split('\n')
|
||||||
|
|
||||||
|
backup = new Backup({ details, fullPath: fullFilePath })
|
||||||
|
const backupDialect = this.getBackupDialect(backup)
|
||||||
|
const databaseEntryName = this.getBackupEntryName(backupDialect)
|
||||||
|
|
||||||
|
if (!backupDialect || !entries[databaseEntryName]) {
|
||||||
|
Logger.error(`[BackupManager] Unsupported database backup format found "${backup.filename}"`)
|
||||||
|
await zip.close().catch(() => {})
|
||||||
|
continue
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[BackupManager] Failed to unzip backup "${fullFilePath}"`, error)
|
Logger.error(`[BackupManager] Failed to unzip backup "${fullFilePath}"`, error)
|
||||||
if (zip) await zip.close().catch(() => {})
|
if (zip) await zip.close().catch(() => {})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const details = data.toString('utf8').split('\n')
|
|
||||||
|
|
||||||
const backup = new Backup({ details, fullPath: fullFilePath })
|
|
||||||
const backupDialect = this.getBackupDialect(backup)
|
|
||||||
const databaseEntryName = this.getBackupEntryName(backupDialect)
|
|
||||||
|
|
||||||
if (!backupDialect || !Object.keys(await zip.entries()).includes(databaseEntryName)) {
|
|
||||||
Logger.error(`[BackupManager] Unsupported database backup format found "${backup.filename}"`)
|
|
||||||
await zip.close()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!backup.serverVersion) {
|
if (!backup.serverVersion) {
|
||||||
// Backups before v2
|
// Backups before v2
|
||||||
Logger.error(`[BackupManager] Old unsupported backup was found "${backup.filename}"`)
|
Logger.error(`[BackupManager] Old unsupported backup was found "${backup.filename}"`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue