@@ -19,6 +19,8 @@ import scala.collection.mutable
19
19
20
20
import dev .dirs .ProjectDirectories
21
21
22
+ import java .time .temporal .ChronoUnit
23
+
22
24
object Paths {
23
25
private val projectDirectories = ProjectDirectories .from(" " , " " , " bloop" )
24
26
private def createDirFor (filepath : String ): AbsolutePath =
@@ -80,7 +82,24 @@ object Paths {
80
82
out.toList
81
83
}
82
84
83
- case class AttributedPath (path : AbsolutePath , lastModifiedTime : FileTime , size : Long )
85
+ // sealed abstract is an abomination for scala 2.12 to get private which actually works
86
+ sealed abstract case class AttributedPath (
87
+ path : AbsolutePath ,
88
+ lastModifiedTime : FileTime ,
89
+ size : Long
90
+ ) {
91
+ def withPath (newPath : AbsolutePath ): AttributedPath =
92
+ new AttributedPath (newPath, lastModifiedTime, size) {}
93
+ }
94
+
95
+ object AttributedPath {
96
+ def of (path : AbsolutePath , lastModifiedTime : FileTime , size : Long ): AttributedPath = {
97
+ // this logic exists to maintain consistency between old and new JVMs. Older JVMs does not provide more than millisecond precision for `Instant`s by default
98
+ val truncatedFileTime =
99
+ FileTime .from(lastModifiedTime.toInstant.truncatedTo(ChronoUnit .MILLIS ))
100
+ new AttributedPath (path, truncatedFileTime, size) {}
101
+ }
102
+ }
84
103
85
104
/**
86
105
* Get all files under `base` that match the pattern `pattern` up to depth `maxDepth`.
@@ -108,7 +127,7 @@ object Paths {
108
127
val visitor = new FileVisitor [Path ] {
109
128
def visitFile (file : Path , attributes : BasicFileAttributes ): FileVisitResult = {
110
129
if (matcher.matches(file)) {
111
- out += AttributedPath (
130
+ out += AttributedPath .of (
112
131
AbsolutePath (file),
113
132
attributes.lastModifiedTime(),
114
133
attributes.size()
0 commit comments