[tor-commits] [collector/master] Fix minor issue with cleaning up directories.
karsten at torproject.org
karsten at torproject.org
Sat Nov 28 10:17:38 UTC 2020
commit cd15f3446376847f359040016fb95791dabfce15
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Sat Nov 28 11:10:30 2020 +0100
Fix minor issue with cleaning up directories.
One of the previously made changes to cleaning up directories was that
empty directories were deleted. This was necessary, because otherwise
there would be a growing number of directories as files get deleted
after reaching an age of seven weeks.
However, this change should not have included deleting the cleaned up
directory itself. In practice, this will not happen. But in tests it's
certainly possible that a directory is empty and then gets deleted.
This leads to all sorts of problems in tests.
The fix is to limit deleting empty directories to subdirectories.
That's what this commit does.
---
.../org/torproject/metrics/collector/persist/PersistenceUtils.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java b/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
index e787c39..2b7621d 100644
--- a/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
+++ b/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
@@ -132,7 +132,8 @@ public class PersistenceUtils {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException {
- if (!Files.list(dir).findFirst().isPresent()) {
+ if (!pathToClean.equals(dir)
+ && !Files.list(dir).findFirst().isPresent()) {
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
More information about the tor-commits
mailing list