From 1083839720e6a40147dcc743c6c8794074b32bcf Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 15 Oct 2023 19:24:16 +0100 Subject: [PATCH] Add --skip-errors flag to client import command Signed-off-by: Graham --- .../openrs2/archive/client/ClientImporter.kt | 33 ++++++++++++++----- .../openrs2/archive/client/ImportCommand.kt | 4 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt index 021cba43dc..3dfed7b569 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt @@ -61,7 +61,13 @@ public class ClientImporter @Inject constructor( private val packClassLibraryReader: PackClassLibraryReader, private val importer: CacheImporter ) { - public suspend fun import(paths: Iterable, name: String?, description: String?, url: String?) { + public suspend fun import( + paths: Iterable, + name: String?, + description: String?, + url: String?, + skipErrors: Boolean + ) { alloc.buffer().use { buf -> for (path in paths) { buf.clear() @@ -73,14 +79,23 @@ public class ClientImporter @Inject constructor( } logger.info { "Importing $path" } - import( - parse(buf), - name, - description, - url, - path.fileName.toString(), - path.getLastModifiedTime().toInstant() - ) + try { + import( + parse(buf), + name, + description, + url, + path.fileName.toString(), + path.getLastModifiedTime().toInstant() + ) + } catch (t: Throwable) { + if (skipErrors) { + logger.warn(t) { "Failed to import $path" } + continue + } + + throw t + } } } } diff --git a/archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt b/archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt index e765e111a8..c7bfa60235 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt @@ -3,6 +3,7 @@ package org.openrs2.archive.client import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.multiple +import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.path import com.google.inject.Guice @@ -14,6 +15,7 @@ public class ImportCommand : CliktCommand(name = "import") { private val name by option() private val description by option() private val url by option() + private val skipErrors by option().flag() private val input by argument().path( mustExist = true, @@ -24,7 +26,7 @@ public class ImportCommand : CliktCommand(name = "import") { override fun run(): Unit = runBlocking { CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector -> val importer = injector.getInstance(ClientImporter::class.java) - importer.import(input, name, description, url) + importer.import(input, name, description, url, skipErrors) } } }