From 2b24f05435e149b5a04904e17a6057b6dc55c4b8 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Thu, 12 Dec 2019 22:39:05 -0500 Subject: [PATCH] Fixes update task not invalidating Fixes https://github.com/sbt/sbt/issues/5292 Ref https://github.com/sbt/sbt/issues/5142 `update` task checks if the timestamp is still the same from the previous resolution. This no longer works since lm-coursier does not populate the timestamps in `UpdateReport`. See https://github.com/coursier/sbt-coursier/blob/2e5c8aed5e20a14c5d439ef5ec35dd6ac00f30f5/modules/lm-coursier/src/main/scala/lmcoursier/internal/SbtUpdateReport.scala#L346-L351 Since the stamps are empty, this caused `update` not to invalidate when the cache is completely missing. This works around the issue by checking if the file still exists. It also adds a warning that the file is missing. --- .../sbt/internal/LibraryManagement.scala | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/main/src/main/scala/sbt/internal/LibraryManagement.scala b/main/src/main/scala/sbt/internal/LibraryManagement.scala index ae839c8f4..b0aa9a521 100644 --- a/main/src/main/scala/sbt/internal/LibraryManagement.scala +++ b/main/src/main/scala/sbt/internal/LibraryManagement.scala @@ -73,8 +73,8 @@ private[sbt] object LibraryManagement { !force && !depsUpdated && !inChanged && - out.allFiles.forall(f => fileUptodate(f, out.stamps)) && - fileUptodate(out.cachedDescriptor, out.stamps) + out.allFiles.forall(f => fileUptodate(f, out.stamps, log)) && + fileUptodate(out.cachedDescriptor, out.stamps, log) } /* Skip resolve if last output exists, otherwise error. */ @@ -129,8 +129,19 @@ private[sbt] object LibraryManagement { handler((extraInputHash, settings, withoutClock)) } - private[this] def fileUptodate(file: File, stamps: Map[File, Long]): Boolean = - stamps.get(file).forall(_ == IO.getModifiedTimeOrZero(file)) + private[this] def fileUptodate(file: File, stamps: Map[File, Long], log: Logger): Boolean = { + val exists = file.exists + // https://github.com/sbt/sbt/issues/5292 warn the user that the file is missing since this indicates + // that UpdateReport was persisted but Coursier cache was not. + if (!exists) { + log.warn(s"${file.getName} no longer exists at $file") + } + // coursier doesn't populate stamps + val timeStampIsSame = stamps + .get(file) + .forall(_ == IO.getModifiedTimeOrZero(file)) + exists && timeStampIsSame + } private[sbt] def transitiveScratch( lm: DependencyResolution,