diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-10-10 23:53:34 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-10-10 23:53:34 +0200 |
commit | b323abebdb702d864bbc2971451acfbdce4930d3 (patch) | |
tree | 55eca3559600033d62cb0ed753ced0969c43e584 /node-admin | |
parent | 648c7633a5f2248cd0372bb52314f91405a958c1 (diff) |
Improve correctness in log by logging in finally
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileFinder.java | 36 |
1 files changed, 18 insertions, 18 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 ed3de35d048..b78d155bdbf 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 @@ -86,27 +86,27 @@ public class FileFinder { * @return true iff anything was matched and deleted */ public boolean deleteRecursively(TaskContext context) { - List<UnixPath> pathsToDelete = new ArrayList<>(); - forEach(attributes -> { - if (Files.exists(attributes.path())) { - pathsToDelete.add(attributes.unixPath()); + List<Path> deletedPaths = new ArrayList<>(); + + try { + forEach(attributes -> { + if (attributes.unixPath().deleteRecursively()) { + deletedPaths.add(attributes.path()); + } + }); + } finally { + if (deletedPaths.size() > 20) { + context.log(logger, "Deleted " + deletedPaths.size() + " paths under " + basePath); + } else if (deletedPaths.size() > 0) { + List<Path> paths = deletedPaths.stream() + .map(basePath::relativize) + .sorted() + .collect(Collectors.toList()); + context.log(logger, "Deleted these paths in " + basePath + ": " + paths); } - }); - - 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.forEach(UnixPath::deleteRecursively); - return true; + return deletedPaths.size() > 0; } public List<FileAttributes> list() { |