From 0a3b66bc7d1110d74ddb07a1873d1ea647198e5e Mon Sep 17 00:00:00 2001 From: games647 Date: Sun, 3 Jun 2018 13:34:51 +0200 Subject: [PATCH] Start a reading instance after downloading (Related #1581) --- .../fr/xephi/authme/service/GeoIpService.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index 363264bc2..be2746878 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -106,8 +106,7 @@ public class GeoIpService { try { FileTime lastModifiedTime = Files.getLastModifiedTime(dataFile); if (Duration.between(lastModifiedTime.toInstant(), Instant.now()).toDays() <= UPDATE_INTERVAL_DAYS) { - databaseReader = new Reader(dataFile.toFile(), FileMode.MEMORY, new CHMCache()); - ConsoleLogger.info(LICENSE); + startReading(); // don't fire the update task - we are up to date return true; @@ -142,7 +141,7 @@ public class GeoIpService { tempFile = Files.createTempFile(ARCHIVE_FILE, null); if (!downloadDatabaseArchive(tempFile)) { ConsoleLogger.info("There is no newer GEO IP database uploaded to MaxMind. Using the old one for now."); - downloading = false; + startReading(); return; } @@ -155,7 +154,7 @@ public class GeoIpService { //only set this value to false on success otherwise errors could lead to endless download triggers ConsoleLogger.info("Successfully downloaded new GEO IP database to " + dataFile); - downloading = false; + startReading(); } catch (IOException ioEx) { ConsoleLogger.logException("Could not download GeoLiteAPI database", ioEx); } finally { @@ -166,6 +165,14 @@ public class GeoIpService { } } + private void startReading() throws IOException { + databaseReader = new Reader(dataFile.toFile(), FileMode.MEMORY, new CHMCache()); + ConsoleLogger.info(LICENSE); + + // clear downloading flag, because we now have working reader instance + downloading = false; + } + /** * Downloads the archive to the destination file if it's newer than the locally version. *