From 35f54fd7537884148875ef3840f94b48c8c38f0d Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 26 Mar 2022 20:03:57 +0000 Subject: [PATCH] Skip corrupt archives when importing legacy caches Signed-off-by: Graham --- .../kotlin/org/openrs2/archive/cache/CacheImporter.kt | 9 +++++++-- cache/src/main/kotlin/org/openrs2/cache/ChecksumTable.kt | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index 2d4d09d2d7..3e73373999 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -1043,8 +1043,13 @@ public class CacheImporter @Inject constructor( // import archives and version list for (id in store.list(0)) { - readArchive(store, id).use { archive -> - addArchive(connection, sourceId, archive) + try { + readArchive(store, id).use { archive -> + addArchive(connection, sourceId, archive) + } + } catch (ex: StoreCorruptException) { + // see the comment in ChecksumTable::create + logger.warn(ex) { "Skipping corrupt archive ($id)" } } } diff --git a/cache/src/main/kotlin/org/openrs2/cache/ChecksumTable.kt b/cache/src/main/kotlin/org/openrs2/cache/ChecksumTable.kt index f28416282a..7160b3c27d 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/ChecksumTable.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/ChecksumTable.kt @@ -26,8 +26,13 @@ public class ChecksumTable( var nextArchive = 0 for (archive in store.list(0)) { - val entry = store.read(0, archive).use { buf -> - buf.crc32() + val entry = try { + store.read(0, archive).use { buf -> + buf.crc32() + } + } catch (ex: StoreCorruptException) { + // see the equivalent comment in Js5MasterIndex::create + continue } for (i in nextArchive until archive) {