aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/unix
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-12-21 08:59:51 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-21 09:01:56 -0800
commitdecca2bd97f6a7eb6b2ca0412ddc792d57f0f424 (patch)
tree759006fa2a07d44d7a30f25ff3e9fc89370a229c /src/main/java/com/google/devtools/build/lib/unix
parent8fb14d5871088e32078812f21ef24189729e38cc (diff)
Add FileSystem#createDirectoryAndParents.
A native implementation of this (instead of using FileSystemUtils, which can only use public interfaces) should be more efficient and more easy to make correct. In particular, it should allow removing FileSystemUtils#createDirectoriesAndParents, which has poor thread safety characteristics. The latter method has a lot of logic that forces certain unnatural atomicity guarantees on createDirectory, and it also has logic that is conditional on sub-string content of exception messages. PiperOrigin-RevId: 179819623
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/unix')
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/NativePosixFiles.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java5
2 files changed, 14 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/unix/NativePosixFiles.java b/src/main/java/com/google/devtools/build/lib/unix/NativePosixFiles.java
index 781467d366..238ef4d2e4 100644
--- a/src/main/java/com/google/devtools/build/lib/unix/NativePosixFiles.java
+++ b/src/main/java/com/google/devtools/build/lib/unix/NativePosixFiles.java
@@ -242,6 +242,15 @@ public final class NativePosixFiles {
throws IOException;
/**
+ * Implements (effectively) mkdir -p.
+ *
+ * @param path the directory to recursively create.
+ * @param mode the mode with which to create the directories.
+ * @throws IOException if the directory creation failed for any reason.
+ */
+ public static native void mkdirs(String path, int mode) throws IOException;
+
+ /**
* Native wrapper around POSIX opendir(2)/readdir(3)/closedir(3) syscall.
*
* @param path the directory to read.
diff --git a/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java b/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
index 7b82dcc06a..0af17cfb12 100644
--- a/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
@@ -325,6 +325,11 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
}
@Override
+ public void createDirectoryAndParents(Path path) throws IOException {
+ NativePosixFiles.mkdirs(path.toString(), 0777);
+ }
+
+ @Override
protected void createSymbolicLink(Path linkPath, PathFragment targetFragment)
throws IOException {
synchronized (linkPath) {