diff --git a/CHANGELOG.md b/CHANGELOG.md index e9137df..a258762 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security -## [1.0.0-RC20] - 2020-06-18 +## [1.0.0-RC21] - 2020-06-20 +### Changed +- [2020-06-20] Fixed logging for DiskLruCache [@carbotaniuman] +- [2020-06-20] Don't automatically delete on corruption [@carbotaniuman] + +## [1.0.0-RC20] - 2020-06-19 ### Added - [2020-06-19] Errored out on invalid settings.json tokens [@carbotaniuman] @@ -123,7 +128,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [2020-06-11] Tweaked logging configuration to reduce log file sizes by [@carbotaniuman]. -[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc20...HEAD +[Unreleased]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc21...HEAD +[1.0.0-rc20]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc20...1.0.0-rc21 [1.0.0-rc20]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc19...1.0.0-rc20 [1.0.0-rc19]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc18...1.0.0-rc19 [1.0.0-rc18]: https://gitlab.com/mangadex/mangadex_at_home/-/compare/1.0.0-rc17...1.0.0-rc18 diff --git a/src/main/java/mdnet/base/MangaDexClient.java b/src/main/java/mdnet/base/MangaDexClient.java index b9cd1d9..4c390f2 100644 --- a/src/main/java/mdnet/base/MangaDexClient.java +++ b/src/main/java/mdnet/base/MangaDexClient.java @@ -6,6 +6,7 @@ import mdnet.base.server.ApplicationKt; import mdnet.base.server.WebUiKt; import mdnet.base.settings.ServerSettings; import mdnet.cache.DiskLruCache; +import mdnet.cache.HeaderMismatchException; import org.http4k.server.Http4kServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +70,11 @@ public class MangaDexClient { } else { statistics.set(new Statistics()); } + } catch (HeaderMismatchException e) { + LOGGER.warn("Cache version may be outdated - remove if necessary"); + Main.dieWithError(e); } catch (IOException e) { + LOGGER.warn("Cache version may be corrupt - remove if necessary"); Main.dieWithError(e); } } diff --git a/src/main/java/mdnet/cache/DiskLruCache.java b/src/main/java/mdnet/cache/DiskLruCache.java index 72dd114..4cd4625 100644 --- a/src/main/java/mdnet/cache/DiskLruCache.java +++ b/src/main/java/mdnet/cache/DiskLruCache.java @@ -226,16 +226,9 @@ public final class DiskLruCache implements Closeable { // Prefer to pick up where we left off. DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize); if (cache.journalFile.exists()) { - try { - cache.readJournal(); - cache.processJournal(); - return cache; - } catch (IOException e) { - if (LOGGER.isWarnEnabled()) { - LOGGER.warn("DiskLruCache " + directory + " is corrupt/outdated - removing"); - } - cache.delete(); - } + cache.readJournal(); + cache.processJournal(); + return cache; } // Create a new empty cache. @@ -255,8 +248,10 @@ public final class DiskLruCache implements Closeable { if (!MAGIC.equals(magic) || !VERSION_1.equals(version) || !Integer.toString(appVersion).equals(appVersionString) || !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) { - throw new IOException("unexpected journal header: [" + magic + ", " + version + ", " + valueCountString - + ", " + blank + "]"); + throw new HeaderMismatchException( + new String[]{magic, version, appVersionString, valueCountString, blank}, + new String[]{MAGIC, VERSION_1, Integer.toString(appVersion), Integer.toString(valueCount), ""} + ); } int lineCount = 0; diff --git a/src/main/java/mdnet/cache/HeaderMismatchException.java b/src/main/java/mdnet/cache/HeaderMismatchException.java new file mode 100644 index 0000000..754e569 --- /dev/null +++ b/src/main/java/mdnet/cache/HeaderMismatchException.java @@ -0,0 +1,10 @@ +package mdnet.cache; + +import java.io.IOException; +import java.util.Arrays; + +public class HeaderMismatchException extends IOException { + public HeaderMismatchException(String[] actual, String[] expected) { + super("expected header " + Arrays.toString(expected) + ", found " + Arrays.toString(actual)); + } +} diff --git a/src/main/kotlin/mdnet/base/Constants.kt b/src/main/kotlin/mdnet/base/Constants.kt index e89d231..e4d8187 100644 --- a/src/main/kotlin/mdnet/base/Constants.kt +++ b/src/main/kotlin/mdnet/base/Constants.kt @@ -4,7 +4,7 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.time.Duration object Constants { - const val CLIENT_BUILD = 10 + const val CLIENT_BUILD = 11 const val CLIENT_VERSION = "1.0" const val WEBUI_VERSION = "0.1.1" val MAX_AGE_CACHE: Duration = Duration.ofDays(14) diff --git a/src/main/kotlin/mdnet/base/Main.kt b/src/main/kotlin/mdnet/base/Main.kt index 70573cb..8aa2fae 100644 --- a/src/main/kotlin/mdnet/base/Main.kt +++ b/src/main/kotlin/mdnet/base/Main.kt @@ -1,8 +1,7 @@ package mdnet.base -import com.fasterxml.jackson.core.JsonParseException +import ch.qos.logback.classic.LoggerContext import com.fasterxml.jackson.core.JsonProcessingException -import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException import com.fasterxml.jackson.module.kotlin.readValue import mdnet.base.Constants.JACKSON @@ -61,6 +60,7 @@ object Main { if (LOGGER.isErrorEnabled) { LOGGER.error("Critical Error", e) } + (LoggerFactory.getILoggerFactory() as LoggerContext).stop() exitProcess(1) } @@ -69,6 +69,7 @@ object Main { if (LOGGER.isErrorEnabled) { LOGGER.error("Critical Error: {}", error) } + (LoggerFactory.getILoggerFactory() as LoggerContext).stop() exitProcess(1) }