implement U.ensureDirectory() for Path

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2d3d5eb2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2d3d5eb2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2d3d5eb2

Branch: refs/heads/ignite-gg-8.0.3.ea6-clients-test
Commit: 2d3d5eb229728ef984ead430b00720e423c50102
Parents: 0693a9a
Author: Alexandr Kuramshin <[email protected]>
Authored: Sun Mar 19 19:13:21 2017 +0700
Committer: Alexandr Kuramshin <[email protected]>
Committed: Sun Mar 19 19:13:21 2017 +0700

----------------------------------------------------------------------
 .../ignite/internal/util/IgniteUtils.java       | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2d3d5eb2/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java 
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
old mode 100644
new mode 100755
index 4892917..e8cb32b
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -9167,6 +9167,32 @@ public abstract class IgniteUtils {
     }
 
     /**
+     * Checks if the given directory exists and attempts to create one if not.
+     *
+     * @param dir Directory to check.
+     * @param msg Directory name for the messages.
+     * @param log Optional logger to log a message that the directory has been 
resolved.
+     * @throws IgniteCheckedException If directory does not exist and failed 
to create it, or if a file with
+     *      the same name already exists.
+     */
+    public static void ensureDirectory(Path dir, String msg, IgniteLogger log) 
throws IgniteCheckedException {
+        if (!Files.exists(dir)) {
+            try {
+                Files.createDirectories(dir);
+            }
+            catch (IOException e) {
+                throw new IgniteCheckedException("Failed to create " + msg + 
": " + dir.toAbsolutePath(), e);
+            }
+        }
+        else if (!Files.isDirectory(dir))
+            throw new IgniteCheckedException("Failed to initialize " + msg +
+                " (a file with the same name already exists): " + 
dir.toAbsolutePath());
+
+        if (log != null && log.isInfoEnabled())
+            log.info("Resolved " + msg + ": " + dir.toAbsolutePath());
+    }
+
+    /**
      * Creates {@code IgniteCheckedException} with the collection of 
suppressed exceptions.
      *
      * @param msg Message.

Reply via email to