Don't wrongly take into account previously downloaded chunks in bitrate calculations

This commit is contained in:
Alexandre Archambault 2016-03-06 15:00:15 +01:00
parent b0f437e99b
commit aa836864a3
3 changed files with 16 additions and 5 deletions

View File

@ -230,6 +230,8 @@ lazy val cache = project
// New methdos in Cache.Logger
ProblemFilters.exclude[MissingMethodProblem]("coursier.Cache#Logger.checkingUpdates"),
ProblemFilters.exclude[MissingMethodProblem]("coursier.Cache#Logger.checkingUpdatesResult"),
// Better overload of Cache.Logger.downloadLength, deprecate previous one
ProblemFilters.exclude[MissingMethodProblem]("coursier.Cache#Logger.downloadLength"),
// Changes to private class TermDisplay#Info
ProblemFilters.exclude[MissingClassProblem]("coursier.TermDisplay$Info$"),
ProblemFilters.exclude[AbstractClassProblem]("coursier.TermDisplay$Info"),

View File

@ -409,7 +409,7 @@ object Cache {
for (len0 <- Option(conn.getContentLengthLong) if len0 >= 0L) {
val len = len0 + (if (partialDownload) alreadyDownloaded else 0L)
logger.foreach(_.downloadLength(url, len))
logger.foreach(_.downloadLength(url, len, alreadyDownloaded))
}
val in = new BufferedInputStream(conn.getInputStream, bufferSize)
@ -747,9 +747,17 @@ object Cache {
trait Logger {
def foundLocally(url: String, f: File): Unit = {}
def downloadingArtifact(url: String, file: File): Unit = {}
@deprecated("Use / override the variant with 3 arguments instead")
def downloadLength(url: String, length: Long): Unit = {}
def downloadLength(url: String, totalLength: Long, alreadyDownloaded: Long): Unit = {
downloadLength(url, totalLength)
}
def downloadProgress(url: String, downloaded: Long): Unit = {}
def downloadedArtifact(url: String, success: Boolean): Unit = {}
def checkingUpdates(url: String, currentTimeOpt: Option[Long]): Unit = {}
def checkingUpdatesResult(url: String, currentTimeOpt: Option[Long], remoteTimeOpt: Option[Long]): Unit = {}

View File

@ -248,6 +248,7 @@ class TermDisplay(
private case class DownloadInfo(
downloaded: Long,
previouslyDownloaded: Long,
length: Option[Long],
startTime: Long,
updateCheck: Boolean
@ -258,7 +259,7 @@ class TermDisplay(
def rate(): Option[Double] = {
val currentTime = System.currentTimeMillis()
if (currentTime > startTime)
Some(downloaded.toDouble / (System.currentTimeMillis() - startTime) * 1000.0)
Some((downloaded - previouslyDownloaded).toDouble / (System.currentTimeMillis() - startTime) * 1000.0)
else
None
}
@ -387,16 +388,16 @@ class TermDisplay(
override def downloadingArtifact(url: String, file: File): Unit =
newEntry(
url,
DownloadInfo(0L, None, System.currentTimeMillis(), updateCheck = false),
DownloadInfo(0L, 0L, None, System.currentTimeMillis(), updateCheck = false),
s"Downloading $url\n"
)
override def downloadLength(url: String, length: Long): Unit = {
override def downloadLength(url: String, totalLength: Long, alreadyDownloaded: Long): Unit = {
val info = infos.get(url)
assert(info != null)
val newInfo = info match {
case info0: DownloadInfo =>
info0.copy(length = Some(length))
info0.copy(length = Some(totalLength), previouslyDownloaded = alreadyDownloaded)
case _ =>
throw new Exception(s"Incoherent display state for $url")
}