diff options
author | 2017-11-30 11:09:35 -0800 | |
---|---|---|
committer | 2017-11-30 11:11:06 -0800 | |
commit | 559a07d2dd88a53d6dac8bf2d77a28db44fd7659 (patch) | |
tree | 1d2d6bc6317d6a8fca6d776510f6cb0cceb6e172 /src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java | |
parent | 1c9b698ede5527ff658b70ee15ef8eed01beb034 (diff) |
Refactor the FileSystem API to allow for different hash functions.
Refactor the FileSystem class to include the hash function as an
instance field. This allows us to have a different hash function
per FileSystem and removes technical debt, as currently that's
somewhat accomplished by a horrible hack that has a static method
to set the hash function for all FileSystem instances.
The FileSystem's default hash function remains MD5.
RELNOTES: None
PiperOrigin-RevId: 177479772
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java | 23 |
1 files changed, 8 insertions, 15 deletions
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; } |