in ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/FileDownloader.scala [77:111]
private def downloadOptionallyReusingPartFile(
url: URL,
optional: Boolean,
reuseExistingPartFile: Boolean = true
): Try[Option[Path]] = Try {
val partFile = downloadNativeWithConnectionRetry(url, reuseExistingPartFile)(printProgressToConsoleCallback)
partFile match {
case DownloadedPath.PartPath(partPath) =>
val targetFile = fromFilePartPath(partPath)
if (targetFile.toFile.exists()) {
log.warn(s"$targetFile already exists, recovering failed install...")
Files.delete(targetFile)
}
Files.move(partPath, targetFile)
Some(targetFile)
case DownloadedPath.ZipPath(path) =>
Some(path)
}
}.recoverWith {
case e: Exception =>
val canNotDownloadFilePart = isRangeNotSatisfiableHttpResponseException(e)
if (canNotDownloadFilePart && reuseExistingPartFile) {
log.warn(s"Can't download file part $url: $e")
log.warn(s"Retrying with a fresh download...")
downloadOptionallyReusingPartFile(url, optional, reuseExistingPartFile = false)
}
else if (optional) {
log.warn(s"Can't download optional file $url: $e")
Success(None)
}
else {
log.warn(s"Can't download file $url: $e")
Failure(e)
}
}