diff options
author | Klaus Aehlig <aehlig@google.com> | 2018-04-23 01:51:01 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-23 01:52:42 -0700 |
commit | c49f9d8b50a7fe8984b51bc01d68b6923d52cc82 (patch) | |
tree | c851269360363bc39b25842e165c67a9b3bed7c7 /src/main/java | |
parent | 84d3097537f045a78baaebc3c6f2ffef4d814cb5 (diff) |
Repository cache: add a put method determining the key itself
Add a new put method to the repository cache, that computes the cache key
itself. The key is returned, so it can be reused without having to recompute
it. This is a convenient interface for caching a file that was downloaded
without prior knowledge of its hash.
Change-Id: I6ac844f4166bf64498b87e483896d155df35475e
PiperOrigin-RevId: 193889444
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java index bd743b3532..651c0a4760 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/cache/RepositoryCache.java @@ -164,6 +164,20 @@ public class RepositoryCache { FileSystemUtils.copyFile(sourcePath, cacheValue); } + /** + * Copies a value from a specified path into the cache, computing the cache key itself. + * + * @param sourcePath The path of the value to be cached. + * @param keyType The type of key to be used. + * @throws IOException + * @return The key for the cached entry. + */ + public synchronized String put(Path sourcePath, KeyType keyType) throws IOException { + String cacheKey = getChecksum(keyType, sourcePath); + put(cacheKey, sourcePath, keyType); + return cacheKey; + } + private void ensureCacheDirectoryExists(KeyType keyType) throws IOException { Path directoryPath = keyType.getCachePath(contentAddressablePath); if (!directoryPath.exists()) { @@ -236,4 +250,4 @@ public class RepositoryCache { return contentAddressablePath; } -}
\ No newline at end of file +} |