diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/mill/eval/PathRef.scala | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/core/src/main/scala/mill/eval/PathRef.scala b/core/src/main/scala/mill/eval/PathRef.scala index fa373b5a..5d96d8df 100644 --- a/core/src/main/scala/mill/eval/PathRef.scala +++ b/core/src/main/scala/mill/eval/PathRef.scala @@ -15,8 +15,8 @@ import mill.util.JsonFormatters * on the contents of the filesystem underneath it. Used to ensure filesystem * changes can bust caches which are keyed off hashcodes. */ -case class PathRef(path: ammonite.ops.Path){ - val md5Hash = { +case class PathRef(path: ammonite.ops.Path, quick: Boolean = false){ + val sig = { val digest = MessageDigest.getInstance("MD5") val buffer = new Array[Byte](16 * 1024) @@ -30,15 +30,25 @@ case class PathRef(path: ammonite.ops.Path){ def visitFile(file: jnio.Path, attrs: BasicFileAttributes) = { digest.update(file.toAbsolutePath.toString.getBytes) - val is = jnio.Files.newInputStream(file) - def rec(): Unit = { - val length = is.read(buffer) - if (length != -1){ - digest.update(buffer, 0, length) - rec() + if (quick){ + val value = (path.mtime.toMillis, path.size).hashCode() + digest.update((value >>> 24).toByte) + digest.update((value >>> 16).toByte) + digest.update((value >>> 8).toByte) + digest.update(value.toByte) + }else { + println("Hashing " + file) + val is = jnio.Files.newInputStream(file) + + def rec(): Unit = { + val length = is.read(buffer) + if (length != -1) { + digest.update(buffer, 0, length) + rec() + } } + rec() } - rec() FileVisitResult.CONTINUE } @@ -50,7 +60,7 @@ case class PathRef(path: ammonite.ops.Path){ java.util.Arrays.hashCode(digest.digest()) } - override def hashCode() = md5Hash + override def hashCode() = sig } object PathRef{ |