aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@yahooinc.com>2021-10-07 10:59:49 +0200
committerHåkon Hallingstad <hakon@yahooinc.com>2021-10-07 10:59:49 +0200
commitdccefb4ed734f5c936bd208d02648f9f9fc48772 (patch)
tree0db14449e64aca4b980a349dff0307e2052619aa /node-admin
parentf8c0e427338db20700c28d4ad1755458be13b519 (diff)
Add UnixPath::isDirectoryEmpty
Diffstat (limited to 'node-admin')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java
index f41d0e8e3bc..acf7fee2880 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java
@@ -7,6 +7,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
+import java.nio.file.NotDirectoryException;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -253,6 +254,17 @@ public class UnixPath {
return this;
}
+ /** @return false path does not exist, is not a directory, or has at least one entry. */
+ public boolean isEmptyDirectory() {
+ try (var entryStream = Files.list(path)) {
+ return entryStream.findAny().isEmpty();
+ } catch (NotDirectoryException | NoSuchFileException e) {
+ return false;
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
/** Lists the contents of this as a stream. Callers should use try-with to ensure that the stream is closed */
public Stream<UnixPath> listContentsOfDirectory() {
try {