Rename legacyData to legacy and make it public

This will be useful for determining if a cache is 3xx or JS5 when
importing it in the archiving service.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 3 years ago
parent 64aa0049ef
commit ac9dc83031
  1. 16
      cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt
  2. 6
      cache/src/test/kotlin/org/openrs2/cache/DiskStoreTest.kt

@ -31,11 +31,11 @@ public class DiskStore private constructor(
private val musicData: BufferedFileChannel?, private val musicData: BufferedFileChannel?,
private val indexes: Array<BufferedFileChannel?>, private val indexes: Array<BufferedFileChannel?>,
private val alloc: ByteBufAllocator, private val alloc: ByteBufAllocator,
legacyData: Boolean public val legacy: Boolean
) : Store { ) : Store {
private data class IndexEntry(val size: Int, val block: Int) private data class IndexEntry(val size: Int, val block: Int)
private val archiveOffset = if (legacyData) 1 else 0 private val archiveOffset = if (legacy) 1 else 0
init { init {
require(indexes.size == Store.MAX_ARCHIVE + 1) require(indexes.size == Store.MAX_ARCHIVE + 1)
@ -505,9 +505,9 @@ public class DiskStore private constructor(
val legacyDataPath = legacyDataPath(root) val legacyDataPath = legacyDataPath(root)
// We check for js5DataPath first as it takes precedence. // We check for js5DataPath first as it takes precedence.
val legacyDataFile = !Files.exists(js5DataPath) val legacy = !Files.exists(js5DataPath)
val dataPath = if (legacyDataFile) { val dataPath = if (legacy) {
legacyDataPath legacyDataPath
} else { } else {
js5DataPath js5DataPath
@ -545,17 +545,17 @@ public class DiskStore private constructor(
} }
} }
return DiskStore(root, data, musicData, archives, alloc, legacyDataFile) return DiskStore(root, data, musicData, archives, alloc, legacy)
} }
public fun create( public fun create(
root: Path, root: Path,
alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT,
legacyDataFile: Boolean = false legacy: Boolean = false
): Store { ): Store {
Files.createDirectories(root) Files.createDirectories(root)
val dataPath = if (legacyDataFile) { val dataPath = if (legacy) {
legacyDataPath(root) legacyDataPath(root)
} else { } else {
dataPath(root) dataPath(root)
@ -569,7 +569,7 @@ public class DiskStore private constructor(
val archives = Array<BufferedFileChannel?>(Store.MAX_ARCHIVE + 1) { null } val archives = Array<BufferedFileChannel?>(Store.MAX_ARCHIVE + 1) { null }
return DiskStore(root, data, null, archives, alloc, legacyDataFile) return DiskStore(root, data, null, archives, alloc, legacy)
} }
} }
} }

@ -808,7 +808,7 @@ class DiskStoreTest {
@Test @Test
fun testCreateLegacyDataFile() { fun testCreateLegacyDataFile() {
writeTest("single-block-legacy", legacyDataFile = true) { store -> writeTest("single-block-legacy", legacy = true) { store ->
copiedBuffer("OpenRS2").use { buf -> copiedBuffer("OpenRS2").use { buf ->
store.write(0, 1, buf) store.write(0, 1, buf)
} }
@ -832,10 +832,10 @@ class DiskStoreTest {
} }
} }
private fun writeTest(name: String, legacyDataFile: Boolean = false, f: (Store) -> Unit) { private fun writeTest(name: String, legacy: Boolean = false, f: (Store) -> Unit) {
Jimfs.newFileSystem(Configuration.forCurrentPlatform()).use { fs -> Jimfs.newFileSystem(Configuration.forCurrentPlatform()).use { fs ->
val actual = fs.rootDirectories.first().resolve("cache") val actual = fs.rootDirectories.first().resolve("cache")
DiskStore.create(actual, legacyDataFile = legacyDataFile).use { store -> DiskStore.create(actual, legacy = legacy).use { store ->
f(store) f(store)
} }

Loading…
Cancel
Save