aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-05-05 16:20:47 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2016-05-05 19:10:30 +0000
commit4420971b6c2a1c26966e8b18c7e6f3603cd05b58 (patch)
tree9e65a3bd58b8e85fbc55084f598764276e952b4d /src/main/java/com/google
parent0d42de6b21135c57e96b3c036a434806e8291acd (diff)
Notice interrupts while downloading
Fixes #1226. RELNOTES: Ctrl-C will now interrupt a download, instead of waiting for it to finish. -- MOS_MIGRATED_REVID=121585417
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java8
2 files changed, 10 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java
index 1cf9e80fef..5888b46952 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java
@@ -66,7 +66,7 @@ public class HttpDownloader {
@Nullable
public static Path download(Rule rule, Path outputDirectory, EventHandler eventHandler)
- throws RepositoryFunctionException {
+ throws RepositoryFunctionException, InterruptedException {
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
String url = mapper.get("url", Type.STRING);
String sha256 = mapper.get("sha256", Type.STRING);
@@ -84,7 +84,7 @@ public class HttpDownloader {
@Nullable
public static Path download(
String url, String sha256, String type, Path output, EventHandler eventHandler)
- throws RepositoryFunctionException {
+ throws RepositoryFunctionException, InterruptedException {
try {
return new HttpDownloader(eventHandler, url, sha256, output, type).download();
} catch (IOException e) {
@@ -98,7 +98,7 @@ public class HttpDownloader {
/**
* Attempt to download a file from the repository's URL. Returns the path to the file downloaded.
*/
- public Path download() throws IOException {
+ public Path download() throws IOException, InterruptedException {
URL url = new URL(urlString);
Path destination;
if (type == null) {
@@ -136,6 +136,9 @@ public class HttpDownloader {
while ((read = inputStream.read(buf)) > 0) {
totalBytes.addAndGet(read);
out.write(buf, 0, read);
+ if (Thread.interrupted()) {
+ throw new InterruptedException("Download interrupted");
+ }
}
if (connection.getContentLength() != -1
&& totalBytes.get() != connection.getContentLength()) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
index 5890996f37..0e181ed7de 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
@@ -358,7 +358,7 @@ public class SkylarkRepositoryContext {
+ "for downloaded file(default to False)."
)
public void download(String url, Object output, String sha256, Boolean executable)
- throws RepositoryFunctionException, EvalException {
+ throws RepositoryFunctionException, EvalException, InterruptedException {
SkylarkPath outputPath = getPath("download()", output);
try {
checkInOutputDirectory(outputPath);
@@ -374,19 +374,19 @@ public class SkylarkRepositoryContext {
@SkylarkCallable(name = "download", documented = false)
public void download(String url, Object output, String sha256)
- throws RepositoryFunctionException, EvalException {
+ throws RepositoryFunctionException, EvalException, InterruptedException {
download(url, output, sha256, false);
}
@SkylarkCallable(name = "download", documented = false)
public void download(String url, Object output, Boolean executable)
- throws RepositoryFunctionException, EvalException {
+ throws RepositoryFunctionException, EvalException, InterruptedException {
download(url, output, "", executable);
}
@SkylarkCallable(name = "download", documented = false)
public void download(String url, Object output)
- throws RepositoryFunctionException, EvalException {
+ throws RepositoryFunctionException, EvalException, InterruptedException {
download(url, output, "", false);
}