Skip to content

Fix #3450: Partial revert of 7ff1cb6fbc6261a364481be597b20a17423f4d72 #3458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/io/Directory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class Directory(jpath: JPath) extends Path(jpath) {
/** An iterator over the contents of this directory.
*/
def list: Iterator[Path] =
if (isDirectory) Files.list(jpath).iterator.asScala.map(Path.apply)
else Iterator.empty
jpath.toFile.listFiles match {
case null => Iterator.empty
case xs => xs.iterator.map(x => Path(x.toPath))
}

def dirs: Iterator[Directory] = list collect { case x: Directory => x }
def files: Iterator[File] = list collect { case x: File => x }
Expand Down
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/io/PlainFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ class PlainFile(val givenPath: Path) extends AbstractFile {

/** Returns all abstract subfiles of this abstract directory. */
def iterator: Iterator[AbstractFile] = {
try {
import scala.collection.JavaConverters._
val it = Files.newDirectoryStream(jpath).iterator()
it.asScala.map(p => new PlainFile(Path(p)))
} catch {
case _: NotDirectoryException => Iterator.empty
// Optimization: Assume that the file was not deleted and did not have permissions changed
// between the call to `list` and the iteration. This saves a call to `exists`.
def existsFast(path: Path) = path match {
case (_: Directory | _: io.File) => true
case _ => path.exists
}
if (!isDirectory) Iterator.empty
else givenPath.toDirectory.list filter existsFast map (new PlainFile(_))
}

/**
Expand Down