// yes, then find out out many log files need to be deleted
final long needToFree = minFreeDiscSpace - usableDiscSpace;
LogLog.debug("Need to free " + needToFree
+ " bytes to get the configured minimum of " + minFreeDiscSpace
+ " bytes free disc space");
final FileHelper fileHelper = FileHelper.getInstance();
long freeableDiscSpace = 0L;
// old ones are at start of list
int lastToBeDeleted = -1;
for (final Iterator iter = logFileList.iterator(); iter.hasNext();) {
final File logFile = (File) iter.next();
freeableDiscSpace += logFile.length();
lastToBeDeleted++;
if (freeableDiscSpace >= needToFree) {
break;
}
}
if (lastToBeDeleted == -1) {
LogLog.debug("Should free " + needToFree
+ " bytes, but not deletable logfiles found");
return;
}
if (lastToBeDeleted >= 0) {
LogLog.debug("About to delete " + (lastToBeDeleted + 1)
+ " log file(s) which will recover " + freeableDiscSpace
+ " bytes on disk.");
}
long freed = 0L;
for (int d = 0; d <= lastToBeDeleted; d++) {
final File logFile = (File) logFileList.get(d);
final long size = logFile.length();
if (fileHelper.deleteExisting(logFile)) {
LogLog.debug("Scavenged log file '" + logFile.getName()
+ "\', freed " + size + " bytes.");
freed += size;
}
}