aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2019-10-10 17:00:04 +0200
committerHåkon Hallingstad <hakon@verizonmedia.com>2019-10-10 17:00:04 +0200
commitd301e736011dd8146a0675e7603ebbbd33ab5499 (patch)
tree10a797bcf0a7a97b1d3a56ae46094ec215c55a03 /node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java
parent607c054896d7034175ee2958ebabbfe79038c5a3 (diff)
Log deletion of files in FileFinder
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java34
1 files changed, 30 insertions, 4 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java
index b5c6b6ab91d..851289eccc4 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java
@@ -1,6 +1,8 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.file;
+import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
+
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.FileVisitResult;
@@ -11,13 +13,17 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Duration;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.function.Consumer;
import java.util.function.Predicate;
+import java.util.logging.Logger;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -27,6 +33,7 @@ import java.util.stream.Stream;
* @author freva
*/
public class FileFinder {
+ private static final Logger logger = Logger.getLogger(FileFinder.class.getName());
private final Path basePath;
private Predicate<FileAttributes> matcher;
@@ -79,10 +86,29 @@ public class FileFinder {
*
* @return true iff anything was matched and deleted
*/
- public boolean deleteRecursively() {
- boolean[] deletedAnything = { false }; // :(
- forEach(attributes -> deletedAnything[0] |= attributes.unixPath().deleteRecursively());
- return deletedAnything[0];
+ public boolean deleteRecursively(TaskContext context) {
+ List<UnixPath> pathsToDelete = new ArrayList<>();
+ forEach(attributes -> {
+ if (Files.exists(attributes.path())) {
+ pathsToDelete.add(attributes.unixPath());
+ }
+ });
+
+ if (pathsToDelete.isEmpty()) return false;
+
+ if (pathsToDelete.size() < 20) {
+ List<Path> paths = pathsToDelete.stream()
+ .map(x -> basePath.relativize(x.toPath()))
+ .sorted()
+ .collect(Collectors.toList());
+ context.log(logger, "Deleting these files in " + basePath + ": " + paths);
+ } else {
+ context.log(logger, "Deleting " + pathsToDelete.size() + " paths under " + basePath);
+ }
+
+ pathsToDelete.sort(Comparator.comparing(UnixPath::toPath));
+ pathsToDelete.forEach(UnixPath::deleteRecursively);
+ return true;
}
public List<FileAttributes> list() {