Remove data file if older than 30 days

This commit is contained in:
DNx5 2016-02-16 09:30:22 +07:00
parent 7b8e5f8e4f
commit 64688c7ae6

View File

@ -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();