@@ -19,6 +19,8 @@ import java.util
19
19
import scala .collection .mutable
20
20
import scala .util .Properties
21
21
22
+ import java .time .temporal .ChronoUnit
23
+
22
24
object Paths {
23
25
private def createDirFor (filepath : String ): AbsolutePath =
24
26
AbsolutePath (Files .createDirectories(NioPaths .get(filepath)))
@@ -103,7 +105,24 @@ object Paths {
103
105
out.toList
104
106
}
105
107
106
- case class AttributedPath (path : AbsolutePath , lastModifiedTime : FileTime , size : Long )
108
+ // sealed abstract is an abomination for scala 2.12 to get private which actually works
109
+ sealed abstract case class AttributedPath (
110
+ path : AbsolutePath ,
111
+ lastModifiedTime : FileTime ,
112
+ size : Long
113
+ ) {
114
+ def withPath (newPath : AbsolutePath ): AttributedPath =
115
+ new AttributedPath (newPath, lastModifiedTime, size) {}
116
+ }
117
+
118
+ object AttributedPath {
119
+ def of (path : AbsolutePath , lastModifiedTime : FileTime , size : Long ): AttributedPath = {
120
+ // 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
121
+ val truncatedFileTime =
122
+ FileTime .from(lastModifiedTime.toInstant.truncatedTo(ChronoUnit .MILLIS ))
123
+ new AttributedPath (path, truncatedFileTime, size) {}
124
+ }
125
+ }
107
126
108
127
/**
109
128
* Get all files under `base` that match the pattern `pattern` up to depth `maxDepth`.
@@ -131,7 +150,7 @@ object Paths {
131
150
val visitor = new FileVisitor [Path ] {
132
151
def visitFile (file : Path , attributes : BasicFileAttributes ): FileVisitResult = {
133
152
if (matcher.matches(file)) {
134
- out += AttributedPath (
153
+ out += AttributedPath .of (
135
154
AbsolutePath (file),
136
155
// Truncate to milliseconds, to workaround precision discrepancy issues in the tests
137
156
FileTime .fromMillis(attributes.lastModifiedTime().toMillis),
0 commit comments