Skip to content

Commit b7d95df

Browse files
Merge commit '9e4671e84' into merge-upstream
2 parents da5813d + 9e4671e commit b7d95df

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

frontend/src/main/scala/bloop/data/Origin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import bloop.util.CacheHashCode
88

99
case class Origin(path: AbsolutePath, lastModifiedtime: FileTime, size: Long, hash: Int)
1010
extends CacheHashCode {
11-
def toAttributedPath: AttributedPath = AttributedPath(path, lastModifiedtime, size)
11+
def toAttributedPath: AttributedPath = AttributedPath.of(path, lastModifiedtime, size)
1212
}
1313

1414
object Origin {

frontend/src/test/scala/bloop/testing/BaseSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ abstract class BaseSuite extends TestSuite with BloopHelpers {
140140
val osInsensitivePath = ap.path.syntax.replace(prefixPath, "").replace(File.separator, "/")
141141
val maskedRelativePath = AbsolutePath(osInsensitivePath)
142142
if (!maskedRelativePath.syntax.startsWith("/classes-")) {
143-
ap.copy(path = maskedRelativePath)
143+
ap.withPath(maskedRelativePath)
144144
} else {
145145
// Remove '/classes-*' from path
146146
val newPath = maskedRelativePath.syntax.split(File.separatorChar).tail.tail.mkString("/")
147-
ap.copy(path = AbsolutePath("/" + newPath))
147+
ap.withPath(AbsolutePath("/" + newPath))
148148
}
149149
}
150150

shared/src/main/scala/bloop/io/Paths.scala

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import java.util
1919
import scala.collection.mutable
2020
import scala.util.Properties
2121

22+
import java.time.temporal.ChronoUnit
23+
2224
object Paths {
2325
private def createDirFor(filepath: String): AbsolutePath =
2426
AbsolutePath(Files.createDirectories(NioPaths.get(filepath)))
@@ -103,7 +105,24 @@ object Paths {
103105
out.toList
104106
}
105107

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+
}
107126

108127
/**
109128
* Get all files under `base` that match the pattern `pattern` up to depth `maxDepth`.
@@ -131,7 +150,7 @@ object Paths {
131150
val visitor = new FileVisitor[Path] {
132151
def visitFile(file: Path, attributes: BasicFileAttributes): FileVisitResult = {
133152
if (matcher.matches(file)) {
134-
out += AttributedPath(
153+
out += AttributedPath.of(
135154
AbsolutePath(file),
136155
// Truncate to milliseconds, to workaround precision discrepancy issues in the tests
137156
FileTime.fromMillis(attributes.lastModifiedTime().toMillis),

0 commit comments

Comments
 (0)