From 64688c7ae633e5b9190c6f4376f0ef3049ee1124 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 16 Feb 2016 09:30:22 +0700 Subject: [PATCH] Remove data file if older than 30 days --- src/main/java/fr/xephi/authme/util/GeoLiteAPI.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index 2c72a58e3..f49074967 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -12,6 +12,7 @@ import java.io.OutputStream; import java.net.InetAddress; import java.net.URL; import java.net.URLConnection; +import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; public class GeoLiteAPI { @@ -35,6 +36,10 @@ public class GeoLiteAPI { return true; } final File data = new File(Settings.PLUGIN_FOLDER, "GeoLite2-Country.mmdb"); + boolean dataIsOld = (System.currentTimeMillis() - data.lastModified()) > TimeUnit.DAYS.toMillis(30); + if (dataIsOld && !data.delete()) { + ConsoleLogger.showError("Failed to delete GeoLiteAPI database"); + } if (data.exists()) { try { databaseReader = new DatabaseReader.Builder(data).build();