From 334424e57a89f5f8ca865c2d45a56a1e63de4b5f Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 13 Dec 2021 17:21:41 +0000 Subject: [PATCH] Fix addMasterIndex() Signed-off-by: Graham --- .../openrs2/archive/cache/CacheImporter.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 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 717ab28c..83c537ce 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -461,20 +461,30 @@ public class CacheImporter @Inject constructor( connection.prepareStatement( """ - INSERT INTO master_indexes (container_id, format) - VALUES (?, ?::master_index_format) + INSERT INTO caches (id) + VALUES (DEFAULT) RETURNING id """.trimIndent() ).use { stmt -> - stmt.setLong(1, containerId) - stmt.setString(2, masterIndex.index.format.name.lowercase()) - stmt.executeQuery().use { rows -> check(rows.next()) masterIndexId = rows.getInt(1) } } + connection.prepareStatement( + """ + INSERT INTO master_indexes (id, container_id, format) + VALUES (?, ?, ?::master_index_format) + """.trimIndent() + ).use { stmt -> + stmt.setInt(1, masterIndexId) + stmt.setLong(2, containerId) + stmt.setString(3, masterIndex.index.format.name.lowercase()) + + stmt.execute() + } + connection.prepareStatement( """ INSERT INTO master_index_archives ( @@ -1250,6 +1260,9 @@ public class CacheImporter @Inject constructor( try { store.read(index, file).use { buf -> val version = VersionTrailer.strip(buf) ?: return null + + // TODO(gpe): try ungzipping here? + return File(index, file, buf.retain(), version) } } catch (ex: IOException) {