aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/Path.java
diff options
context:
space:
mode:
authorGravatar aehlig <aehlig@google.com>2017-12-19 07:12:25 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-19 07:13:52 -0800
commitc801c393bcfabbe6e5058fd77ef2d67660c75da3 (patch)
tree1711325efe0f0e0fa9adb6d2aef8310a666e587b /src/main/java/com/google/devtools/build/lib/vfs/Path.java
parent2918e78a2b3144d5cacc1ab20ab4626a72df797a (diff)
Automated rollback of commit 82e68b75304438c96ff878a0c2b8d18b42002486.
Fixes #4322, #4306. *** Reason for rollback *** Introduces a deadlock (see https://github.com/bazelbuild/bazel/issues/4322) *** Original change description *** Make FileSystem operate on LocalPath instead of Path. PiperOrigin-RevId: 179549866
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/Path.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/Path.java98
1 files changed, 45 insertions, 53 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index b09b713cd1..1d3947dcdc 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -39,11 +39,7 @@ import java.util.IdentityHashMap;
import java.util.Objects;
/**
- * NOTE: This class is superseded by {@link LocalPath}. You should prefer storing simple strings /
- * path fragments, then converting to a {@link LocalPath} only when you need to do local file system
- * access. A migration is underway.
- *
- * <p>Instances of this class represent pathnames, forming a tree structure to implement sharing of
+ * Instances of this class represent pathnames, forming a tree structure to implement sharing of
* common prefixes (parent directory names). A node in these trees is something like foo, bar, ..,
* ., or /. If the instance is not a root path, it will have a parent path. A path can also have
* children, which are indexed by name in a map.
@@ -427,10 +423,6 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
return builder.toString();
}
- public LocalPath getLocalPath() {
- return LocalPath.create(getPathString());
- }
-
@Override
public void repr(SkylarkPrinter printer) {
printer.append(getPathString());
@@ -508,7 +500,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public boolean exists(FileSystem fileSystem) {
- return fileSystem.exists(this.getLocalPath(), true);
+ return fileSystem.exists(this, true);
}
/** Prefer to use {@link #exists(FileSystem, Symlinks)}. */
@@ -527,7 +519,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* link is dereferenced until a file other than a symbolic link is found
*/
public boolean exists(FileSystem fileSystem, Symlinks followSymlinks) {
- return fileSystem.exists(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.exists(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #getDirectoryEntries(FileSystem)}. */
@@ -548,7 +540,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public Collection<Path> getDirectoryEntries(FileSystem fileSystem)
throws IOException, FileNotFoundException {
- Collection<String> entries = fileSystem.getDirectoryEntries(this.getLocalPath());
+ Collection<String> entries = fileSystem.getDirectoryEntries(this);
Collection<Path> result = new ArrayList<>(entries.size());
for (String entry : entries) {
result.add(getChild(entry));
@@ -576,7 +568,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public Collection<Dirent> readdir(FileSystem fileSystem, Symlinks followSymlinks)
throws IOException {
- return fileSystem.readdir(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.readdir(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #stat(FileSystem)}. */
@@ -596,7 +588,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* {@code FileStatus} are called.
*/
public FileStatus stat(FileSystem fileSystem) throws IOException {
- return fileSystem.stat(this.getLocalPath(), true);
+ return fileSystem.stat(this, true);
}
/** Prefer to use {@link #statNullable(FileSystem)}. */
@@ -628,7 +620,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public FileStatus statNullable(FileSystem fileSystem, Symlinks symlinks) {
- return fileSystem.statNullable(this.getLocalPath(), symlinks.toBoolean());
+ return fileSystem.statNullable(this, symlinks.toBoolean());
}
/** Prefer to use {@link #stat(FileSystem, Symlinks)}. */
@@ -650,7 +642,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* {@code FileStatus} are called
*/
public FileStatus stat(FileSystem fileSystem, Symlinks followSymlinks) throws IOException {
- return fileSystem.stat(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.stat(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #statIfFound(FileSystem)}. */
@@ -668,7 +660,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public FileStatus statIfFound(FileSystem fileSystem) throws IOException {
- return fileSystem.statIfFound(this.getLocalPath(), true);
+ return fileSystem.statIfFound(this, true);
}
/** Prefer to use {@link #statIfFound(FileSystem, Symlinks)}. */
@@ -688,7 +680,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* link is dereferenced until a file other than a symbolic link is found
*/
public FileStatus statIfFound(FileSystem fileSystem, Symlinks followSymlinks) throws IOException {
- return fileSystem.statIfFound(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.statIfFound(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #isDirectory()} (FileSystem)}. */
@@ -704,7 +696,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public boolean isDirectory(FileSystem fileSystem) {
- return fileSystem.isDirectory(this.getLocalPath(), true);
+ return fileSystem.isDirectory(this, true);
}
/** Prefer to use {@link #isDirectory(FileSystem, Symlinks)}. */
@@ -723,7 +715,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* link is dereferenced until a file other than a symbolic link is found
*/
public boolean isDirectory(FileSystem fileSystem, Symlinks followSymlinks) {
- return fileSystem.isDirectory(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.isDirectory(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #isFile(FileSystem)}. */
@@ -742,7 +734,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* it excludes symbolic links and directories.
*/
public boolean isFile(FileSystem fileSystem) {
- return fileSystem.isFile(this.getLocalPath(), true);
+ return fileSystem.isFile(this, true);
}
/** Prefer to use {@link #isFile(FileSystem, Symlinks)}. */
@@ -764,7 +756,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* link is dereferenced until a file other than a symbolic link is found.
*/
public boolean isFile(FileSystem fileSystem, Symlinks followSymlinks) {
- return fileSystem.isFile(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.isFile(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #isSpecialFile(FileSystem)}. */
@@ -781,7 +773,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public boolean isSpecialFile(FileSystem fileSystem) {
- return fileSystem.isSpecialFile(this.getLocalPath(), true);
+ return fileSystem.isSpecialFile(this, true);
}
/** Prefer to use {@link #isSpecialFile(FileSystem, Symlinks)}. */
@@ -800,7 +792,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* link is dereferenced until a path other than a symbolic link is found.
*/
public boolean isSpecialFile(FileSystem fileSystem, Symlinks followSymlinks) {
- return fileSystem.isSpecialFile(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.isSpecialFile(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #isSymbolicLink(FileSystem)}. */
@@ -816,7 +808,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public boolean isSymbolicLink(FileSystem fileSystem) {
- return fileSystem.isSymbolicLink(this.getLocalPath());
+ return fileSystem.isSymbolicLink(this);
}
/**
@@ -1010,7 +1002,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public OutputStream getOutputStream(FileSystem fileSystem, boolean append)
throws IOException, FileNotFoundException {
- return fileSystem.getOutputStream(this.getLocalPath(), append);
+ return fileSystem.getOutputStream(this, append);
}
/** Prefer to use {@link #createDirectory(FileSystem)}. */
@@ -1031,7 +1023,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the directory creation failed for any reason
*/
public boolean createDirectory(FileSystem fileSystem) throws IOException {
- return fileSystem.createDirectory(this.getLocalPath());
+ return fileSystem.createDirectory(this);
}
/** Prefer to use {@link #createSymbolicLink(FileSystem, Path)}. */
@@ -1052,7 +1044,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public void createSymbolicLink(FileSystem fileSystem, Path target) throws IOException {
checkSameFilesystem(target);
- fileSystem.createSymbolicLink(this.getLocalPath(), target.asFragment().getPathString());
+ fileSystem.createSymbolicLink(this, target.asFragment());
}
/** Prefer to use {@link #createSymbolicLink(FileSystem, PathFragment)}. */
@@ -1072,7 +1064,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the creation of the symbolic link was unsuccessful for any reason
*/
public void createSymbolicLink(FileSystem fileSystem, PathFragment target) throws IOException {
- fileSystem.createSymbolicLink(this.getLocalPath(), target.getPathString());
+ fileSystem.createSymbolicLink(this, target);
}
/** Prefer to use {@link #readSymbolicLink(FileSystem)}. */
@@ -1097,7 +1089,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* could not be read for any reason
*/
public PathFragment readSymbolicLink(FileSystem fileSystem) throws IOException {
- return PathFragment.create(fileSystem.readSymbolicLink(this.getLocalPath()));
+ return fileSystem.readSymbolicLink(this);
}
/** Prefer to use {@link #readSymbolicLinkUnchecked(FileSystem)}. */
@@ -1118,7 +1110,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* could not be read for any reason
*/
public PathFragment readSymbolicLinkUnchecked(FileSystem fileSystem) throws IOException {
- return PathFragment.create(fileSystem.readSymbolicLinkUnchecked(this.getLocalPath()));
+ return fileSystem.readSymbolicLinkUnchecked(this);
}
/** Prefer to use {@link #createHardLink(FileSystem, Path)}. */
@@ -1137,7 +1129,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if there was an error executing {@link FileSystem#createHardLink}
*/
public void createHardLink(FileSystem fileSystem, Path link) throws IOException {
- fileSystem.createHardLink(link.getLocalPath(), this.getLocalPath());
+ fileSystem.createHardLink(link, this);
}
/** Prefer to use {@link #resolveSymbolicLinks(FileSystem)}. */
@@ -1158,7 +1150,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* example, the path does not exist)
*/
public Path resolveSymbolicLinks(FileSystem fileSystem) throws IOException {
- return fileSystem.getPath(fileSystem.resolveSymbolicLinks(this.getLocalPath()).getPathString());
+ return fileSystem.resolveSymbolicLinks(this);
}
/** Prefer to use {@link #renameTo(FileSystem, Path)}. */
@@ -1181,7 +1173,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public void renameTo(FileSystem fileSystem, Path target) throws IOException {
checkSameFilesystem(target);
- fileSystem.renameTo(this.getLocalPath(), target.getLocalPath());
+ fileSystem.renameTo(this, target);
}
/** Prefer to use {@link #getFileSize(FileSystem)}. */
@@ -1202,7 +1194,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the file's metadata could not be read, or some other error occurred
*/
public long getFileSize(FileSystem fileSystem) throws IOException, FileNotFoundException {
- return fileSystem.getFileSize(this.getLocalPath(), true);
+ return fileSystem.getFileSize(this, true);
}
/** Prefer to use {@link #getFileSize(FileSystem, Symlinks)}. */
@@ -1227,7 +1219,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public long getFileSize(FileSystem fileSystem, Symlinks followSymlinks)
throws IOException, FileNotFoundException {
- return fileSystem.getFileSize(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.getFileSize(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #delete(FileSystem)}. */
@@ -1248,7 +1240,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the deletion failed but the file was present prior to the call
*/
public boolean delete(FileSystem fileSystem) throws IOException {
- return fileSystem.delete(this.getLocalPath());
+ return fileSystem.delete(this);
}
/** Prefer to use {@link #getLastModifiedTime(FileSystem)}. */
@@ -1270,7 +1262,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the operation failed for any reason
*/
public long getLastModifiedTime(FileSystem fileSystem) throws IOException {
- return fileSystem.getLastModifiedTime(this.getLocalPath(), true);
+ return fileSystem.getLastModifiedTime(this, true);
}
/** Prefer to use {@link #getLastModifiedTime(FileSystem, Symlinks)}. */
@@ -1295,7 +1287,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public long getLastModifiedTime(FileSystem fileSystem, Symlinks followSymlinks)
throws IOException {
- return fileSystem.getLastModifiedTime(this.getLocalPath(), followSymlinks.toBoolean());
+ return fileSystem.getLastModifiedTime(this, followSymlinks.toBoolean());
}
/** Prefer to use {@link #setLastModifiedTime(FileSystem, long)}. */
@@ -1320,7 +1312,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the modification time for the file could not be set for any reason
*/
public void setLastModifiedTime(FileSystem fileSystem, long newTime) throws IOException {
- fileSystem.setLastModifiedTime(this.getLocalPath(), newTime);
+ fileSystem.setLastModifiedTime(this, newTime);
}
/** Prefer to use {@link #getxattr(FileSystem, String)}. */
@@ -1337,7 +1329,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public byte[] getxattr(FileSystem fileSystem, String name) throws IOException {
- return fileSystem.getxattr(this.getLocalPath(), name);
+ return fileSystem.getxattr(this, name);
}
/** Prefer to use {@link #getFastDigest(FileSystem)}. */
@@ -1354,7 +1346,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* Path.
*/
public byte[] getFastDigest(FileSystem fileSystem) throws IOException {
- return fileSystem.getFastDigest(this.getLocalPath());
+ return fileSystem.getFastDigest(this);
}
/** Prefer to use {@link #isValidDigest(FileSystem, byte[])}. */
@@ -1389,7 +1381,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the digest could not be computed for any reason
*/
public byte[] getDigest(FileSystem fileSystem) throws IOException {
- return fileSystem.getDigest(this.getLocalPath());
+ return fileSystem.getDigest(this);
}
/** Prefer to use {@link #getDigest(FileSystem, HashFunction)}. */
@@ -1409,7 +1401,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the digest could not be computed for any reason
*/
public byte[] getDigest(FileSystem fileSystem, HashFunction hashFunction) throws IOException {
- return fileSystem.getDigest(this.getLocalPath(), hashFunction);
+ return fileSystem.getDigest(this, hashFunction);
}
/** Prefer to use {@link #getInputStream(FileSystem)}. */
@@ -1428,7 +1420,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the file was not found or could not be opened for reading
*/
public InputStream getInputStream(FileSystem fileSystem) throws IOException {
- return fileSystem.getInputStream(this.getLocalPath());
+ return fileSystem.getInputStream(this);
}
/**
@@ -1458,7 +1450,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* encountered, or the file's metadata could not be read
*/
public boolean isWritable(FileSystem fileSystem) throws IOException, FileNotFoundException {
- return fileSystem.isWritable(this.getLocalPath());
+ return fileSystem.isWritable(this);
}
/** Prefer to use {@link #setReadable(FileSystem, boolean)}. */
@@ -1480,7 +1472,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public void setReadable(FileSystem fileSystem, boolean readable)
throws IOException, FileNotFoundException {
- fileSystem.setReadable(this.getLocalPath(), readable);
+ fileSystem.setReadable(this, readable);
}
/** Prefer to use {@link #setWritable(FileSystem, boolean)}. */
@@ -1504,7 +1496,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public void setWritable(FileSystem fileSystem, boolean writable)
throws IOException, FileNotFoundException {
- fileSystem.setWritable(this.getLocalPath(), writable);
+ fileSystem.setWritable(this, writable);
}
/** Prefer to use {@link #isExecutable(FileSystem)}. */
@@ -1525,7 +1517,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if some other I/O error occurred
*/
public boolean isExecutable(FileSystem fileSystem) throws IOException, FileNotFoundException {
- return fileSystem.isExecutable(this.getLocalPath());
+ return fileSystem.isExecutable(this);
}
/** Prefer to use {@link #isReadable(FileSystem)}. */
@@ -1546,7 +1538,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if some other I/O error occurred
*/
public boolean isReadable(FileSystem fileSystem) throws IOException, FileNotFoundException {
- return fileSystem.isReadable(this.getLocalPath());
+ return fileSystem.isReadable(this);
}
/** Prefer to use {@link #setExecutable(FileSystem, boolean)}. */
@@ -1568,7 +1560,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
*/
public void setExecutable(FileSystem fileSystem, boolean executable)
throws IOException, FileNotFoundException {
- fileSystem.setExecutable(this.getLocalPath(), executable);
+ fileSystem.setExecutable(this, executable);
}
/** Prefer to use {@link #chmod(FileSystem, int)}. */
@@ -1591,7 +1583,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
* @throws IOException if the metadata change failed, for example because of permissions
*/
public void chmod(FileSystem fileSystem, int mode) throws IOException {
- fileSystem.chmod(this.getLocalPath(), mode);
+ fileSystem.chmod(this, mode);
}
/** Prefer to use {@link #prefetchPackageAsync(FileSystem, int)}. */
@@ -1601,7 +1593,7 @@ public class Path implements Comparable<Path>, Serializable, SkylarkPrintable {
}
public void prefetchPackageAsync(FileSystem fileSystem, int maxDirs) {
- fileSystem.prefetchPackageAsync(this.getLocalPath(), maxDirs);
+ fileSystem.prefetchPackageAsync(this, maxDirs);
}
/**