Fix addMasterIndex()

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 3 years ago
parent f4ae5540d7
commit 334424e57a
  1. 23
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt

@ -461,20 +461,30 @@ public class CacheImporter @Inject constructor(
connection.prepareStatement( connection.prepareStatement(
""" """
INSERT INTO master_indexes (container_id, format) INSERT INTO caches (id)
VALUES (?, ?::master_index_format) VALUES (DEFAULT)
RETURNING id RETURNING id
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setLong(1, containerId)
stmt.setString(2, masterIndex.index.format.name.lowercase())
stmt.executeQuery().use { rows -> stmt.executeQuery().use { rows ->
check(rows.next()) check(rows.next())
masterIndexId = rows.getInt(1) 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( connection.prepareStatement(
""" """
INSERT INTO master_index_archives ( INSERT INTO master_index_archives (
@ -1250,6 +1260,9 @@ public class CacheImporter @Inject constructor(
try { try {
store.read(index, file).use { buf -> store.read(index, file).use { buf ->
val version = VersionTrailer.strip(buf) ?: return null val version = VersionTrailer.strip(buf) ?: return null
// TODO(gpe): try ungzipping here?
return File(index, file, buf.retain(), version) return File(index, file, buf.retain(), version)
} }
} catch (ex: IOException) { } catch (ex: IOException) {

Loading…
Cancel
Save