diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-05-10 13:13:47 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-05-10 13:13:47 +0200 |
commit | a6d95bd2f46816a6e05a4aec1806ff5b16f727c5 (patch) | |
tree | 253d87cd429758eca4c5d2968829738b53bc9479 /node-admin/src | |
parent | 0e795977b2072d5504b1a45adffa7d2bdfed7fc2 (diff) |
Create the directory just before the file is written
Ignore the failure that comes if trying to create a directory that already
exists.
Diffstat (limited to 'node-admin/src')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/file/UnixPath.java | 9 |
1 files changed, 8 insertions, 1 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 cb7f1637410..f41d0e8e3bc 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 @@ -4,6 +4,7 @@ package com.yahoo.vespa.hosted.node.admin.task.util.file; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; +import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; @@ -203,8 +204,14 @@ public class UnixPath { return this; } + /** Create directory unless it already exists, and return this. */ public UnixPath createDirectory() { - uncheck(() -> Files.createDirectory(path)); + try { + Files.createDirectory(path); + } catch (FileAlreadyExistsException ignore) { + } catch (IOException e) { + throw new UncheckedIOException(e); + } return this; } |