aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs
diff options
context:
space:
mode:
authorGravatar Ola Rozenfeld <olaola@google.com>2016-09-09 16:58:11 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-09-12 08:55:00 +0000
commit564cea75d54d85027e3d8ff5040b95ded3a41c4a (patch)
treebcfb96b3869e6db5eee91cd4933cffb7a7fb5f76 /src/main/java/com/google/devtools/build/lib/vfs
parent9d774203ecc2cce5630d0f71088bfb4ae469cc03 (diff)
Exporting functions to compute SHA1 digests of files.
TODO: need to stich them all the way through various ActionInputFileCache implementations! -- MOS_MIGRATED_REVID=132685408
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/Path.java14
2 files changed, 28 insertions, 0 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 3e3b94da63..e7f1fa2513 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
@@ -279,6 +279,20 @@ public abstract class FileSystem {
}
/**
+ * Returns the MD5 digest of the file denoted by {@code path}. See
+ * {@link Path#getMD5Digest} for specification.
+ */
+ protected byte[] getSHA1Digest(final Path path) throws IOException {
+ // Naive I/O implementation. TODO(olaola): optimize!
+ return new ByteSource() {
+ @Override
+ public InputStream openStream() throws IOException {
+ return getInputStream(path);
+ }
+ }.hash(Hashing.sha1()).asBytes();
+ }
+
+ /**
* Returns true if "path" denotes an existing symbolic link. See
* {@link Path#isSymbolicLink} for specification.
*/
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 657bb03c41..dbec227a22 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
@@ -995,6 +995,20 @@ public class Path implements Comparable<Path>, Serializable {
}
/**
+ * Returns the SHA1 digest of the file denoted by the current path, following
+ * symbolic links.
+ *
+ * <p>This method runs in O(n) time where n is the length of the file, but
+ * certain implementations may be much faster than the worst case.
+ *
+ * @return a new 20-byte array containing the file's SHA1 digest
+ * @throws IOException if the SHA1 digest could not be computed for any reason
+ */
+ public byte[] getSHA1Digest() throws IOException {
+ return fileSystem.getSHA1Digest(this);
+ }
+
+ /**
* Opens the file denoted by this path, following symbolic links, for reading,
* and returns an input stream to it.
*