Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 95f1b0e

Browse files
jtorkkolafacebook-github-bot
authored andcommitted
Fix DirectoryCleaner sometimes deleting buck-out/log/ subdirectories for the current run
Summary: After it decides it needs to delete stuff, `DirectoryCleaner` doesn't respect `LogFileHandler`'s minimum number of logs to keep setting. When log subdirectories become relatively large, e.g. 10MB when outputting verbose rulekey logs, even the log subdirectories for the current run can get deleted, leaving behind dangling `last_XXXcommand` symlinks. The fix is to consolidate the deletion check logic in one place. Reviewed By: styurin fbshipit-source-id: 8660a1b5f2
1 parent 856b782 commit 95f1b0e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/com/facebook/buck/util/DirectoryCleaner.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void clean(Path pathToClean) throws IOException {
5555
pathStats.add(stats);
5656
}
5757

58-
if (shouldDeleteOldestLog(pathStats.size(), totalSizeBytes)) {
58+
if (shouldDeleteOldestLog(pathStats.size(), totalSizeBytes, args.getMaxTotalSizeBytes())) {
5959
Collections.sort(
6060
pathStats, (stats1, stats2) -> args.getPathSelector().comparePaths(stats1, stats2));
6161

@@ -66,8 +66,7 @@ public void clean(Path pathToClean) throws IOException {
6666
}
6767

6868
for (int i = 0; i < pathStats.size(); ++i) {
69-
if (totalSizeBytes <= finalMaxSizeBytes
70-
&& remainingLogDirectories <= args.getMaxPathCount()) {
69+
if (!shouldDeleteOldestLog(remainingLogDirectories, totalSizeBytes, finalMaxSizeBytes)) {
7170
break;
7271
}
7372

@@ -82,13 +81,13 @@ public void clean(Path pathToClean) throws IOException {
8281
}
8382
}
8483

85-
private boolean shouldDeleteOldestLog(int currentNumberOfLogs, long totalSizeBytes) {
84+
private boolean shouldDeleteOldestLog(
85+
int currentNumberOfLogs, long totalSizeBytes, long maxTotalSizeBytes) {
8686
if (currentNumberOfLogs <= args.getMinAmountOfEntriesToKeep()) {
8787
return false;
8888
}
8989

90-
return totalSizeBytes > args.getMaxTotalSizeBytes()
91-
|| currentNumberOfLogs > args.getMaxPathCount();
90+
return totalSizeBytes > maxTotalSizeBytes || currentNumberOfLogs > args.getMaxPathCount();
9291
}
9392

9493
private PathStats computePathStats(Path path) throws IOException {

0 commit comments

Comments
 (0)