diff options
author | 2015-07-28 22:07:17 +0000 | |
---|---|---|
committer | 2015-07-29 16:01:33 +0000 | |
commit | 205a3d67fe5986890270ad99c87ded997a1d5cca (patch) | |
tree | 3a94f62cf0276900467a3fa55ad9b2e8746227c9 /src | |
parent | 6ddbb6e48bf1fb389634934dcce1e251a77e50e5 (diff) |
Download from remote http repository only if zip file with correct hash doesn't already exist.
This addresses #251, but similar functionality needs to be implemented for all flavors of remote repository.
--
MOS_MIGRATED_REVID=99319885
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloader.java | 9 | ||||
-rwxr-xr-x | src/test/shell/bazel/external_integration_test.sh | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloader.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloader.java index 9dd29aeba5..56f7d33bcc 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloader.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/HttpDownloader.java @@ -73,6 +73,15 @@ public class HttpDownloader { } Path destination = outputDirectory.getRelative(filename); + try { + String currentSha256 = getHash(Hashing.sha256().newHasher(), destination); + if (currentSha256.equals(sha256)) { + // No need to download. + return destination; + } + } catch (IOException e) { + // Ignore error trying to hash. We'll just download again. + } int currentBytes; final AtomicInteger totalBytes = new AtomicInteger(0); final ScheduledFuture<?> loggerHandle = getLoggerHandle(totalBytes); diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index e799302e9b..bdccbd06af 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -333,6 +333,15 @@ function test_changed_zip() { [[ -s $repo_zip ]] || fail "File size was 0" } +function test_cached_across_server_restart() { + http_archive_helper zip_up + bazel shutdown >& $TEST_log || fail "Couldn't shut down" + bazel run //zoo:breeding-program >& $TEST_log --show_progress_rate_limit=0 \ + || echo "Expected build/run to succeed" + expect_log $what_does_the_fox_say + expect_not_log "Downloading from" +} + # Tests downloading a jar and using it as a Java dependency. function test_jar_download() { serve_jar |