aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/unix
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-01-05 09:19:27 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-05 09:22:10 -0800
commit80c8ff1819a889814cbe2dae477d7fedce6aa181 (patch)
tree063fa71759e4174891ccf2db3107e412ec96f2d7 /src/main/java/com/google/devtools/build/lib/unix
parent3ed01597a938c4b762606d02af1c793196961da0 (diff)
Automated rollback of commit d50cbbeef115f28c0cea1ac17572e0f12c0cf312.
*** Reason for rollback *** b/71442447 *** Original change description *** Remove synchronization from file system. After the path refactor we will no longer have path instances to synchronize on. The underlying OS file systems are already naturally thread safe, that is, their internal data structures cannot be damaged. Any further synchronization (eg. races between directory creation and deletion) has to be managed at the client level. The last attempt to do this failed because of races in FileUtils#createDirectoryAndParents on Windows. This method is now gone, rep... *** ROLLBACK_OF=180290901 PiperOrigin-RevId: 180936132
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/unix')
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java66
1 files changed, 40 insertions, 26 deletions
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 033a6a692d..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
@@ -257,9 +257,11 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
*/
private void modifyPermissionBits(Path path, int permissionBits, boolean add)
throws IOException {
- int oldMode = statInternal(path, true).getPermissions();
- int newMode = add ? (oldMode | permissionBits) : (oldMode & ~permissionBits);
- NativePosixFiles.chmod(path.toString(), newMode);
+ synchronized (path) {
+ int oldMode = statInternal(path, true).getPermissions();
+ int newMode = add ? (oldMode | permissionBits) : (oldMode & ~permissionBits);
+ NativePosixFiles.chmod(path.toString(), newMode);
+ }
}
@Override
@@ -279,7 +281,9 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
@Override
protected void chmod(Path path, int mode) throws IOException {
- NativePosixFiles.chmod(path.toString(), mode);
+ synchronized (path) {
+ NativePosixFiles.chmod(path.toString(), mode);
+ }
}
@Override
@@ -304,17 +308,19 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
@Override
public boolean createDirectory(Path path) throws IOException {
- // Note: UNIX mkdir(2), FilesystemUtils.mkdir() and createDirectory all
- // have different ways of representing failure!
- if (NativePosixFiles.mkdir(path.toString(), 0777)) {
- return true; // successfully created
- }
+ synchronized (path) {
+ // Note: UNIX mkdir(2), FilesystemUtils.mkdir() and createDirectory all
+ // have different ways of representing failure!
+ if (NativePosixFiles.mkdir(path.toString(), 0777)) {
+ return true; // successfully created
+ }
- // false => EEXIST: something is already in the way (file/dir/symlink)
- if (isDirectory(path, false)) {
- return false; // directory already existed
- } else {
- throw new IOException(path + " (File exists)");
+ // false => EEXIST: something is already in the way (file/dir/symlink)
+ if (isDirectory(path, false)) {
+ return false; // directory already existed
+ } else {
+ throw new IOException(path + " (File exists)");
+ }
}
}
@@ -326,7 +332,9 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
@Override
protected void createSymbolicLink(Path linkPath, PathFragment targetFragment)
throws IOException {
- NativePosixFiles.symlink(targetFragment.toString(), linkPath.toString());
+ synchronized (linkPath) {
+ NativePosixFiles.symlink(targetFragment.toString(), linkPath.toString());
+ }
}
@Override
@@ -347,7 +355,9 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
@Override
public void renameTo(Path sourcePath, Path targetPath) throws IOException {
- NativePosixFiles.rename(sourcePath.toString(), targetPath.toString());
+ synchronized (sourcePath) {
+ NativePosixFiles.rename(sourcePath.toString(), targetPath.toString());
+ }
}
@Override
@@ -359,10 +369,12 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
public boolean delete(Path path) throws IOException {
String name = path.toString();
long startTime = Profiler.nanoTimeMaybe();
- try {
- return NativePosixFiles.remove(name);
- } finally {
- profiler.logSimpleTask(startTime, ProfilerTask.VFS_DELETE, name);
+ synchronized (path) {
+ try {
+ return NativePosixFiles.remove(name);
+ } finally {
+ profiler.logSimpleTask(startTime, ProfilerTask.VFS_DELETE, name);
+ }
}
}
@@ -373,12 +385,14 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
@Override
public void setLastModifiedTime(Path path, long newTime) throws IOException {
- if (newTime == -1L) { // "now"
- NativePosixFiles.utime(path.toString(), true, 0);
- } else {
- // newTime > MAX_INT => -ve unixTime
- int unixTime = (int) (newTime / 1000);
- NativePosixFiles.utime(path.toString(), false, unixTime);
+ synchronized (path) {
+ if (newTime == -1L) { // "now"
+ NativePosixFiles.utime(path.toString(), true, 0);
+ } else {
+ // newTime > MAX_INT => -ve unixTime
+ int unixTime = (int) (newTime / 1000);
+ NativePosixFiles.utime(path.toString(), false, unixTime);
+ }
}
}