use of com.facebook.buck.util.DirectoryCleaner in project buck by facebook.
the class LogFileHandler method newCleaner.
public static DirectoryCleaner newCleaner(long maxLogsSizeBytes, int maxLogsDirectories, int minAmountOfLogsToKeep) {
DirectoryCleanerArgs cleanerArgs = DirectoryCleanerArgs.builder().setPathSelector(new DirectoryCleaner.PathSelector() {
@Override
public Iterable<Path> getCandidatesToDelete(Path rootPath) throws IOException {
List<Path> dirPaths = Lists.newArrayList();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(rootPath)) {
for (Path path : directoryStream) {
Matcher matcher = DIR_PATTERN.matcher(path.getFileName().toString());
if (matcher.matches()) {
dirPaths.add(path);
}
}
}
return dirPaths;
}
@Override
public int comparePaths(DirectoryCleaner.PathStats path1, DirectoryCleaner.PathStats path2) {
return Long.compare(path1.getCreationMillis(), path2.getCreationMillis());
}
}).setMaxTotalSizeBytes(maxLogsSizeBytes).setMaxPathCount(maxLogsDirectories).setMinAmountOfEntriesToKeep(minAmountOfLogsToKeep).build();
DirectoryCleaner cleaner = new DirectoryCleaner(cleanerArgs);
return cleaner;
}
Aggregations