From d437cfb87d0f4b5ddad4a46a8282dc3830557b18 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sat, 24 Jun 2017 15:21:59 +0200 Subject: [PATCH] Ensure a same artifact isn't downloaded twice in the same iteration coursier.Cache.Logger doesn't handle this well --- .../coursier/core/ResolutionProcess.scala | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/shared/src/main/scala/coursier/core/ResolutionProcess.scala b/core/shared/src/main/scala/coursier/core/ResolutionProcess.scala index e86949f74..a32047643 100644 --- a/core/shared/src/main/scala/coursier/core/ResolutionProcess.scala +++ b/core/shared/src/main/scala/coursier/core/ResolutionProcess.scala @@ -64,6 +64,22 @@ final case class Missing( cont: Resolution => ResolutionProcess ) extends ResolutionProcess { + def uniqueModules: Missing = { + + // only try to fetch a single version of a given module in a same iteration, so that resolutions for different + // versions don't try to download the same URL in the same iteration, which the coursier.Cache.Logger API doesn't + // allow + + val missing0 = missing.groupBy(_._1).toSeq.map(_._2).map { + case Seq(v) => v + case Seq() => sys.error("Cannot happen") + case v => + v.maxBy { case (_, v0) => Version(v0) } + } + + copy(missing = missing0) + } + def next(results: Fetch.MD): ResolutionProcess = { val errors = results.collect { @@ -120,7 +136,7 @@ final case class Missing( Continue(res0, cont) } else - Missing(depMgmtMissing.toSeq, res, cont0) + Missing(depMgmtMissing.toSeq, res, cont0).uniqueModules } val current0 = current.copyWithCache( @@ -158,7 +174,7 @@ object ResolutionProcess { if (resolution0.isDone) Done(resolution0) else - Missing(resolution0.missingFromCache.toSeq, resolution0, apply) + Missing(resolution0.missingFromCache.toSeq, resolution0, apply).uniqueModules } }