Start a reading instance after downloading (Related #1581)

This commit is contained in:
games647 2018-06-03 13:34:51 +02:00
parent 135e323358
commit 0a3b66bc7d
No known key found for this signature in database
GPG Key ID: BFC68C8708713A88

View File

@ -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.
*