aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 {