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,16 +38,26 @@ 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()) {
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) { fileName = file.getName();
if (!file.delete()) { //if file is not a log file
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?"); if (!fileName.endsWith(".log") && !fileName.endsWith(".log.gz")) {
} else { continue;
Bukkit.getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + file.getName()); }
}
//if file is older than configured time
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
continue;
}
if (!file.delete()) {
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
} else {
Bukkit.getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + file.getName());
} }
} }
} }