Only delete log files and nothing else

This commit is contained in:
Govindas 2021-06-13 12:12:06 +03:00
parent 4a37ac3691
commit 59d45b6ede

View File

@ -38,10 +38,21 @@ public class AutomaticLogDeleter extends JavaPlugin {
//maximum file age allowed //maximum file age allowed
long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000; long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
String fileName;
for (File file : files) { for (File file : files) {
if (file.isFile()) { if (file.isFile()) {
fileName = file.getName();
//if file is not a log file
if (!fileName.endsWith(".log") && !fileName.endsWith(".log.gz")) {
continue;
}
//if file is older than configured time
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) { if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
continue;
}
if (!file.delete()) { if (!file.delete()) {
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?"); Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
@ -52,4 +63,3 @@ public class AutomaticLogDeleter extends JavaPlugin {
} }
} }
} }
}