Skip to content

Commit f2bc0dc

Browse files
committed
Revert "Do not use Files.{exists, isRegularFile, isDirectory}"
This reverts commit ff0ed64.
1 parent ff0ed64 commit f2bc0dc

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

compiler/src/dotty/tools/io/AbstractFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
121121

122122
/** Does this abstract file denote an existing file? */
123123
def exists: Boolean = {
124-
(jpath eq null) || jpath.toFile.exists
124+
(jpath eq null) || Files.exists(jpath)
125125
}
126126

127127
/** Does this abstract file represent something which can contain classfiles? */

compiler/src/dotty/tools/io/Path.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ object Path {
5454

5555
def apply(path: String): Path = apply(Paths.get(path))
5656
def apply(jpath: JPath): Path = try {
57-
val jfile = jpath.toFile
58-
if (jfile.isFile) new File(jpath)
59-
else if (jfile.isDirectory) new Directory(jpath)
57+
if (Files.isRegularFile(jpath)) new File(jpath)
58+
else if (Files.isDirectory(jpath)) new Directory(jpath)
6059
else new Path(jpath)
6160
} catch { case ex: SecurityException => new Path(jpath) }
6261

@@ -161,10 +160,10 @@ class Path private[io] (val jpath: JPath) {
161160
// Boolean tests
162161
def canRead: Boolean = Files.isReadable(jpath)
163162
def canWrite: Boolean = Files.isWritable(jpath)
164-
def exists: Boolean = try jpath.toFile.exists catch { case ex: SecurityException => false }
165-
def isFile: Boolean = try jpath.toFile.isFile catch { case ex: SecurityException => false }
163+
def exists: Boolean = try Files.exists(jpath) catch { case ex: SecurityException => false }
164+
def isFile: Boolean = try Files.isRegularFile(jpath) catch { case ex: SecurityException => false }
166165
def isDirectory: Boolean =
167-
try jpath.toFile.isDirectory
166+
try Files.isDirectory(jpath)
168167
catch { case ex: SecurityException => jpath.toString == "." }
169168
def isAbsolute: Boolean = jpath.isAbsolute()
170169
def isEmpty: Boolean = path.length == 0

0 commit comments

Comments
 (0)