From c7843aa9c76f37b521a562565945a55373563c34 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 9 Aug 2017 11:43:43 +0700 Subject: [PATCH] dependencies: Detect unexpected stream end while downloading --- tools/helpers/src/main/kotlin/DependencyDownloader.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/helpers/src/main/kotlin/DependencyDownloader.kt b/tools/helpers/src/main/kotlin/DependencyDownloader.kt index 0a30d32733c..c1c93ea5ca3 100644 --- a/tools/helpers/src/main/kotlin/DependencyDownloader.kt +++ b/tools/helpers/src/main/kotlin/DependencyDownloader.kt @@ -163,6 +163,9 @@ class DependencyDownloader(dependenciesRoot: File, currentBytes += read read = from.read(buffer) } + if (currentBytes != totalBytes) { + throw EOFException("The stream closed before end of downloading.") + } } } } catch (e: Throwable) { @@ -179,7 +182,7 @@ class DependencyDownloader(dependenciesRoot: File, println("Done.") if (downloadError != null) { tmpFile.delete() - throw RuntimeException("Cannot download dependency: $url", downloadError) + throw IOException("Cannot download dependency: $url", downloadError) } Files.move( tmpFile.toPath(),