aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-10-12 03:30:43 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-10-12 10:17:03 +0200
commit5cca89f970bcaddb98972055f2d9539e9d225e67 (patch)
tree2cbb9d34b91663d63b88a2166d45095244b873af /src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
parent59984b5bb795f6067117be47c44ddb21ccc376de (diff)
Remove synchronization from FileSystem implementations.
PiperOrigin-RevId: 171905267
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java57
1 files changed, 17 insertions, 40 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
index a42f5f5845..777b089ea7 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
@@ -200,43 +200,24 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
@Override
protected boolean createDirectory(Path path) throws IOException {
+ File file = getIoFile(path);
+ if (file.mkdir()) {
+ return true;
+ }
- // We always synchronize on the current path before doing it on the parent path and file system
- // path structure ensures that this locking order will never be reversed.
- // When refactoring, check that subclasses still work as expected and there can be no
- // deadlocks.
- synchronized (path) {
- File file = getIoFile(path);
- if (file.mkdir()) {
- return true;
- }
-
- // We will be checking the state of the parent path as well. Synchronize on it before
- // attempting anything.
- Path parentDirectory = path.getParentDirectory();
- synchronized (parentDirectory) {
- if (fileIsSymbolicLink(file)) {
- throw new IOException(path + ERR_FILE_EXISTS);
- }
- if (file.isDirectory()) {
- return false; // directory already existed
- } else if (file.exists()) {
- throw new IOException(path + ERR_FILE_EXISTS);
- } else if (!file.getParentFile().exists()) {
- throw new FileNotFoundException(path.getParentDirectory() + ERR_NO_SUCH_FILE_OR_DIR);
- }
- // Parent directory apparently exists - try to create our directory again - protecting
- // against the case where parent directory would be created right before us obtaining
- // synchronization lock.
- if (file.mkdir()) {
- return true; // Everything is fine finally.
- } else if (!file.getParentFile().canWrite()) {
- throw new FileAccessException(path + ERR_PERMISSION_DENIED);
- } else {
- // Parent exists, is writable, yet we can't create our directory.
- throw new FileNotFoundException(path.getParentDirectory() + ERR_NOT_A_DIRECTORY);
- }
- }
+ if (fileIsSymbolicLink(file)) {
+ throw new IOException(path + ERR_FILE_EXISTS);
+ } else if (file.isDirectory()) {
+ return false; // directory already existed
+ } else if (file.exists()) {
+ throw new IOException(path + ERR_FILE_EXISTS);
+ } else if (!file.getParentFile().exists()) {
+ throw new FileNotFoundException(path.getParentDirectory() + ERR_NO_SUCH_FILE_OR_DIR);
+ } else if (!file.getParentFile().canWrite()) {
+ throw new FileAccessException(path + ERR_PERMISSION_DENIED);
+ } else {
+ // Parent exists, is writable, yet we can't create our directory.
+ throw new FileNotFoundException(path.getParentDirectory() + ERR_NOT_A_DIRECTORY);
}
}
@@ -291,7 +272,6 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
@Override
protected void renameTo(Path sourcePath, Path targetPath) throws IOException {
- synchronized (sourcePath) {
File sourceFile = getIoFile(sourcePath);
File targetFile = getIoFile(targetPath);
if (!sourceFile.renameTo(targetFile)) {
@@ -312,7 +292,6 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
throw new FileAccessException(sourcePath + " -> " + targetPath + ERR_PERMISSION_DENIED);
}
}
- }
}
@Override
@@ -329,7 +308,6 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
protected boolean delete(Path path) throws IOException {
File file = getIoFile(path);
long startTime = Profiler.nanoTimeMaybe();
- synchronized (path) {
try {
if (file.delete()) {
return true;
@@ -345,7 +323,6 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
} finally {
profiler.logSimpleTask(startTime, ProfilerTask.VFS_DELETE, file.getPath());
}
- }
}
@Override