diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
5 files changed, 44 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java index a03ec02fc5..ef1946bb8e 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java @@ -30,6 +30,12 @@ abstract class AbstractFileSystem extends FileSystem { protected static final String ERR_PERMISSION_DENIED = " (Permission denied)"; protected static final Profiler profiler = Profiler.instance(); + public AbstractFileSystem() {} + + public AbstractFileSystem(HashFunction digestFunction) { + super(digestFunction); + } + @Override protected InputStream getInputStream(Path path) throws IOException { // This loop is a workaround for an apparent bug in FileInputStream.open, which delegates diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java index db4fca94d5..875df98bab 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java @@ -21,6 +21,13 @@ import java.io.IOException; * {@link FileSystem} does). */ public abstract class AbstractFileSystemWithCustomStat extends AbstractFileSystem { + + public AbstractFileSystemWithCustomStat() {} + + public AbstractFileSystemWithCustomStat(HashFunction hashFunction) { + super(hashFunction); + } + @Override protected boolean isFile(Path path, boolean followSymlinks) { FileStatus stat = statNullable(path, followSymlinks); diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java index fe707ea6c3..6386b738b1 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.vfs; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.hash.Hashing; import com.google.common.io.ByteSource; @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.vfs.Dirent.Type; import com.google.devtools.build.lib.vfs.Path.PathFactory; import com.google.devtools.common.options.EnumConverter; -import com.google.devtools.common.options.OptionsParsingException; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -71,23 +70,17 @@ public abstract class FileSystem { } } - // This is effectively final, should be changed only in unit-tests! - private static HashFunction digestFunction; - static { - try { - digestFunction = new HashFunction.Converter().convert( - System.getProperty("bazel.DigestFunction", "MD5")); - } catch (OptionsParsingException e) { - throw new IllegalStateException(e); - } + private final HashFunction digestFunction; + + public FileSystem() { + this(HashFunction.MD5); } - @VisibleForTesting - public static void setDigestFunctionForTesting(HashFunction value) { - digestFunction = value; + public FileSystem(HashFunction digestFunction) { + this.digestFunction = Preconditions.checkNotNull(digestFunction); } - public static HashFunction getDigestFunction() { + public HashFunction getDigestFunction() { return digestFunction; } 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 73074b2b90..e5ca35d3f4 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 @@ -56,6 +56,11 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat { this(new JavaClock()); } + public JavaIoFileSystem(HashFunction hashFunction) { + super(hashFunction); + this.clock = new JavaClock(); + } + @VisibleForTesting JavaIoFileSystem(Clock clock) { this.clock = clock; diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java index d7b0960429..7e4d6601bc 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java @@ -70,7 +70,18 @@ public class InMemoryFileSystem extends FileSystem { * paths are considered to be within scope). */ public InMemoryFileSystem(Clock clock) { - this(clock, null); + this(clock, (PathFragment) null); + } + + /** + * Creates a new InMemoryFileSystem with scope checking disabled (all paths are considered to be + * within scope). + */ + public InMemoryFileSystem(Clock clock, HashFunction hashFunction) { + super(hashFunction); + this.clock = clock; + this.rootInode = newRootInode(clock); + this.scopeRoot = null; } /** @@ -80,9 +91,14 @@ public class InMemoryFileSystem extends FileSystem { public InMemoryFileSystem(Clock clock, PathFragment scopeRoot) { this.scopeRoot = scopeRoot; this.clock = clock; - this.rootInode = new InMemoryDirectoryInfo(clock); + this.rootInode = newRootInode(clock); + } + + private static InMemoryDirectoryInfo newRootInode(Clock clock) { + InMemoryDirectoryInfo rootInode = new InMemoryDirectoryInfo(clock); rootInode.addChild(".", rootInode); rootInode.addChild("..", rootInode); + return rootInode; } /** |