Skip to content

Commit 55b8c90

Browse files
committed
WIP
1 parent 2622fba commit 55b8c90

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/compiler/scala/tools/nsc/classpath/ZipAndJarFileLookupFactory.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sealed trait ZipAndJarFileLookupFactory {
4545
closeableRegistry.registerCloseable(result)
4646
result
4747
} else {
48-
cache.getOrCreate(zipSettings, Seq(jfile.toPath), () => createForZipFile(zipFile, zipSettings), closeableRegistry, checkStamps = true)
48+
cache.getOrCreate(zipSettings, Seq(jfile.toPath -> zipFile.basicFileAttributes), () => createForZipFile(zipFile, zipSettings), closeableRegistry, checkStamps = true)
4949
}
5050
}
5151

@@ -259,14 +259,18 @@ final class FileBasedCache[K, T] {
259259
}
260260
}
261261

262-
def getOrCreate(k: K, paths: Seq[Path], create: () => T, closeableRegistry: CloseableRegistry, checkStamps: Boolean): T = cache.synchronized {
263-
val stamps = if (!checkStamps) Nil else paths.map { path =>
262+
def getOrCreate(k: K, paths: Seq[Path], create: () => T,
263+
closeableRegistry: CloseableRegistry, checkStamps: Boolean): T = {
264+
val pathsAndAttrs = paths.map(x => (x, Files.readAttributes(x, classOf[BasicFileAttributes])))
265+
getOrCreate0(k, pathsAndAttrs, create, closeableRegistry, checkStamps)
266+
}
267+
def getOrCreate0(k: K, paths: Seq[(Path, BasicFileAttributes)], create: () => T, closeableRegistry: CloseableRegistry, checkStamps: Boolean): T = cache.synchronized {
268+
val stamps = if (!checkStamps) Nil else paths.map { case (path, attrs) =>
264269
try {
265-
val attrs = Files.readAttributes(path, classOf[BasicFileAttributes])
266-
val lastModified = attrs.lastModifiedTime()
267-
// only null on some platforms, but that's okay, we just use the last modified timestamp as our stamp
268-
val fileKey = attrs.fileKey()
269-
Stamp(lastModified, attrs.size(), if (fileKey == null) NoFileKey else fileKey)
270+
val lastModified = attrs.lastModifiedTime()
271+
// only null on some platforms, but that's okay, we just use the last modified timestamp as our stamp
272+
val fileKey = attrs.fileKey()
273+
Stamp(lastModified, attrs.size(), if (fileKey == null) NoFileKey else fileKey)
270274
} catch {
271275
case _: java.nio.file.NoSuchFileException =>
272276
// Dummy stamp for (currently) non-existent file.

src/compiler/scala/tools/nsc/settings/PathFactory.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
package scala.tools.nsc.settings
1414

15+
import java.io.File
1516
import scala.reflect.io.{AbstractFile, PlainFile}
1617

1718
/** Converts paths provided in compiler options (e.g elements of `-classpath` or the target directory of `-d`) to
@@ -37,6 +38,6 @@ trait PathFactory {
3738
}
3839

3940
object DefaultPathFactory extends PathFactory {
40-
override def getDirectory(path: String): AbstractFile = AbstractFile.getDirectory(path)
41+
override def getDirectory(path: String): AbstractFile = AbstractFile.getDirectory(new File(path))
4142
override def getFile(path: String): AbstractFile = new PlainFile(path)
4243
}

src/reflect/scala/reflect/io/AbstractFile.scala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.io.{File => JFile}
1919
import java.net.URL
2020
import java.nio.ByteBuffer
2121
import java.nio.file.attribute.BasicFileAttributes
22-
import java.nio.file.{Files, NoSuchFileException}
22+
import java.nio.file.Files
2323
import scala.collection.AbstractIterable
2424

2525
/**
@@ -56,7 +56,11 @@ object AbstractFile {
5656
}
5757

5858
if (attrs.isDirectory) new PlainFile(file)
59-
else if (attrs.isRegularFile && Path.isExtensionJarOrZip(file.jfile)) ZipArchive.fromFile(file)
59+
else if (attrs.isRegularFile && Path.isExtensionJarOrZip(file.jfile)) {
60+
val za = ZipArchive.fromFile(file)
61+
za.setBasicFileAttributesCached(attrs)
62+
za
63+
}
6064
else null
6165
}
6266

@@ -124,6 +128,18 @@ abstract class AbstractFile extends AbstractIterable[AbstractFile] {
124128

125129
/** Returns the underlying File if any and null otherwise. */
126130
def file: JFile
131+
def basicFileAttributes: BasicFileAttributes = {
132+
if (basicFileAttributesCached != null)
133+
basicFileAttributesCached
134+
else file match {
135+
case null => null
136+
case f => Files.readAttributes(f.toPath, classOf[BasicFileAttributes])
137+
}
138+
}
139+
private var basicFileAttributesCached: BasicFileAttributes = null
140+
final def setBasicFileAttributesCached(attrs: BasicFileAttributes): Unit = {
141+
basicFileAttributesCached = attrs
142+
}
127143

128144
/** An underlying source, if known. Mostly, a zip/jar file. */
129145
def underlyingSource: Option[AbstractFile] = None

0 commit comments

Comments
 (0)