mirror of https://github.com/sbt/sbt.git
Resets the connection (and sets partial download to false) if the range is not satisfiable by the server (#795)
This commit is contained in:
parent
a7605ff900
commit
cf365ea27a
|
|
@ -198,6 +198,7 @@ object Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val partialContentResponseCode = 206
|
private val partialContentResponseCode = 206
|
||||||
|
private val invalidPartialContentResponseCode = 416
|
||||||
|
|
||||||
private val handlerClsCache = new ConcurrentHashMap[String, Option[URLStreamHandler]]
|
private val handlerClsCache = new ConcurrentHashMap[String, Option[URLStreamHandler]]
|
||||||
|
|
||||||
|
|
@ -561,7 +562,8 @@ object Cache {
|
||||||
case conn0: HttpURLConnection if alreadyDownloaded > 0L =>
|
case conn0: HttpURLConnection if alreadyDownloaded > 0L =>
|
||||||
conn0.setRequestProperty("Range", s"bytes=$alreadyDownloaded-")
|
conn0.setRequestProperty("Range", s"bytes=$alreadyDownloaded-")
|
||||||
|
|
||||||
(conn0.getResponseCode == partialContentResponseCode) && {
|
((conn0.getResponseCode == partialContentResponseCode)
|
||||||
|
|| (conn0.getResponseCode == invalidPartialContentResponseCode)) && {
|
||||||
val ackRange = Option(conn0.getHeaderField("Content-Range")).getOrElse("")
|
val ackRange = Option(conn0.getHeaderField("Content-Range")).getOrElse("")
|
||||||
|
|
||||||
ackRange.startsWith(s"bytes $alreadyDownloaded-") || {
|
ackRange.startsWith(s"bytes $alreadyDownloaded-") || {
|
||||||
|
|
|
||||||
|
|
@ -867,4 +867,30 @@ class CliFetchIntegrationTest extends FlatSpec with CliTestLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"Wrong range partial artifact resolve" should "succeed with retry" in withTempDir("tmp_dir") {
|
||||||
|
dir => {
|
||||||
|
def runFetchJunit = {
|
||||||
|
val fetchOpt = FetchOptions(common = CommonOptions(mode = "force", cacheOptions = CacheOptions(cache = dir.getAbsolutePath)))
|
||||||
|
val fetch = Fetch(fetchOpt, RemainingArgs(Seq("junit:junit:4.6"), Seq()))
|
||||||
|
assert(fetch.files0.map(_.getName).toSet
|
||||||
|
.equals(Set("junit-4.6.jar")))
|
||||||
|
val junitJarPath = fetch.files0.map(_.getAbsolutePath()).filter(_.contains("junit-4.6.jar"))
|
||||||
|
.head
|
||||||
|
val junitJarFile = new File(junitJarPath)
|
||||||
|
junitJarFile
|
||||||
|
}
|
||||||
|
|
||||||
|
val originalJunitJar: File = runFetchJunit
|
||||||
|
|
||||||
|
val originalJunitJarContent = FileUtil.readAllBytes(originalJunitJar)
|
||||||
|
|
||||||
|
// Move the jar to partial (but complete) download
|
||||||
|
val newJunitJar: File = new File(originalJunitJar.getAbsolutePath + ".part")
|
||||||
|
originalJunitJar.renameTo(newJunitJar)
|
||||||
|
|
||||||
|
// Run fetch again and it should pass because of retrying on the partial jar.
|
||||||
|
val jar = runFetchJunit
|
||||||
|
assert(FileUtil.readAllBytes(jar).sameElements(originalJunitJarContent))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue