Skip to content

Commit

Permalink
Prevent log files from being pruned prematurely (acmerobotics#65, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevan-navudu authored Feb 19, 2020
1 parent fee96d2 commit 409aa04
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ private static void buildLogList(List<File> logFiles, File dir) {
}

private static void pruneLogsIfNecessary() {
long totalSpace = ROAD_RUNNER_FOLDER.getTotalSpace();
List<File> logFiles = null;
while (totalSpace > LOG_QUOTA) {
if (logFiles == null) {
logFiles = new ArrayList<>();
buildLogList(logFiles, ROAD_RUNNER_FOLDER);
Collections.sort(logFiles, (lhs, rhs) ->
Long.compare(lhs.lastModified(), rhs.lastModified()));
}
List<File> logFiles = new ArrayList<>();
buildLogList(logFiles, ROAD_RUNNER_FOLDER);
Collections.sort(logFiles, (lhs, rhs) ->
Long.compare(lhs.lastModified(), rhs.lastModified()));

long dirSize = 0;
for (File file: logFiles) {
dirSize += file.length();
}

while (dirSize > LOG_QUOTA) {
if (logFiles.size() == 0) break;
File fileToRemove = logFiles.remove(0);
totalSpace -= fileToRemove.getTotalSpace();
dirSize -= fileToRemove.length();
//noinspection ResultOfMethodCallIgnored
fileToRemove.delete();
}
Expand Down

0 comments on commit 409aa04

Please sign in to comment.