mirror of https://github.com/sbt/sbt.git
Merge pull request #134 from cunei/wip-milli
Convert lastModified() calls to the more precise getModifiedTime()
This commit is contained in:
commit
b3e217aa6e
|
|
@ -9,6 +9,7 @@ import java.io.File
|
|||
import sbt.io.{ IO, Path }
|
||||
import sbt.io.syntax._
|
||||
import Path._
|
||||
import sbt.io.IO
|
||||
|
||||
class FileCommands(baseDirectory: File) extends BasicStatementHandler {
|
||||
lazy val commands = commandMap
|
||||
|
|
@ -67,7 +68,8 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler {
|
|||
def newer(a: String, b: String): Unit = {
|
||||
val pathA = fromString(a)
|
||||
val pathB = fromString(b)
|
||||
val isNewer = pathA.exists && (!pathB.exists || pathA.lastModified > pathB.lastModified)
|
||||
val isNewer = pathA.exists &&
|
||||
(!pathB.exists || IO.getModifiedTime(pathA) > IO.getModifiedTime(pathB))
|
||||
if (!isNewer) {
|
||||
scriptError(s"$pathA is not newer than $pathB")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ object Dependencies {
|
|||
val scala211 = "2.11.12"
|
||||
val scala212 = "2.12.4"
|
||||
|
||||
private val ioVersion = "1.1.1"
|
||||
private val ioVersion = "1.1.2"
|
||||
|
||||
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
package sbt.util
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import scala.util.control.NonFatal
|
||||
import sbt.io.Hash
|
||||
import sbt.io.{ Hash, IO }
|
||||
import sjsonnew.{ Builder, JsonFormat, Unbuilder, deserializationError }
|
||||
import CacheImplicits._
|
||||
|
||||
|
|
@ -49,6 +50,12 @@ object FilesInfo {
|
|||
}
|
||||
|
||||
object FileInfo {
|
||||
|
||||
// returns 0L if file does not exist
|
||||
private def getModifiedTimeOrZero(file: File) =
|
||||
try IO.getModifiedTime(file)
|
||||
catch { case _: FileNotFoundException => 0L }
|
||||
|
||||
sealed trait Style {
|
||||
type F <: FileInfo
|
||||
|
||||
|
|
@ -88,7 +95,7 @@ object FileInfo {
|
|||
}
|
||||
|
||||
implicit def apply(file: File): HashModifiedFileInfo =
|
||||
FileHashModified(file.getAbsoluteFile, Hash(file).toList, file.lastModified)
|
||||
FileHashModified(file.getAbsoluteFile, Hash(file).toList, getModifiedTimeOrZero(file))
|
||||
}
|
||||
|
||||
object hash extends Style {
|
||||
|
|
@ -145,7 +152,7 @@ object FileInfo {
|
|||
}
|
||||
|
||||
implicit def apply(file: File): ModifiedFileInfo =
|
||||
FileModified(file.getAbsoluteFile, file.lastModified)
|
||||
FileModified(file.getAbsoluteFile, getModifiedTimeOrZero(file))
|
||||
}
|
||||
|
||||
object exists extends Style {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ package sbt.util
|
|||
import sjsonnew.shaded.scalajson.ast.unsafe._
|
||||
import sjsonnew._, support.scalajson.unsafe._
|
||||
import sbt.internal.util.UnitSpec
|
||||
import sbt.io.IO
|
||||
|
||||
class FileInfoSpec extends UnitSpec {
|
||||
val file = new java.io.File(".").getAbsoluteFile
|
||||
val fileInfo: ModifiedFileInfo = FileModified(file, file.lastModified())
|
||||
val fileInfo: ModifiedFileInfo = FileModified(file, IO.getModifiedTime(file))
|
||||
val filesInfo = FilesInfo(Set(fileInfo))
|
||||
|
||||
it should "round trip" in assertRoundTrip(filesInfo)
|
||||
|
|
|
|||
Loading…
Reference in New Issue