@@ -2,6 +2,7 @@ package os
2
2
3
3
import java .net .URI
4
4
import java .nio .file .Paths
5
+ import java .nio .file .Files
5
6
6
7
import collection .JavaConverters ._
7
8
import scala .language .implicitConversions
@@ -281,7 +282,7 @@ class RelPath private[os] (segments0: Array[String], val ups: Int)
281
282
case _ => false
282
283
}
283
284
284
- def toNIO = java.nio.file. Paths .get(toString)
285
+ def toNIO = Paths .get(toString)
285
286
286
287
def asSubPath = {
287
288
require(ups == 0 )
@@ -342,7 +343,7 @@ class SubPath private[os] (val segments0: Array[String])
342
343
case _ => false
343
344
}
344
345
345
- def toNIO = java.nio.file. Paths .get(toString)
346
+ def toNIO = Paths .get(toString)
346
347
347
348
def resolveFrom (base : os.Path ) = base / this
348
349
}
@@ -448,7 +449,7 @@ trait ReadablePath {
448
449
class Path private [os] (val wrapped : java.nio.file.Path )
449
450
extends FilePath with ReadablePath with BasePathImpl {
450
451
def toSource : SeekableSource =
451
- new SeekableSource .ChannelSource (java.nio.file. Files .newByteChannel(wrapped))
452
+ new SeekableSource .ChannelSource (Files .newByteChannel(wrapped))
452
453
453
454
require(wrapped.isAbsolute, s " $wrapped is not an absolute path " )
454
455
def segments : Iterator [String ] = wrapped.iterator().asScala.map(_.toString)
@@ -495,12 +496,23 @@ class Path private[os] (val wrapped: java.nio.file.Path)
495
496
496
497
def resolveFrom (base : os.Path ) = this
497
498
498
- def getInputStream = java.nio.file. Files .newInputStream(wrapped)
499
+ def getInputStream = Files .newInputStream(wrapped)
499
500
}
500
501
501
502
class TempPath private [os] (wrapped : java.nio.file.Path )
502
503
extends Path (wrapped) with AutoCloseable {
503
- override def close (): Unit = os.remove.all(this )
504
+
505
+ override def close (): Unit = deleteRecursively(wrapped)
506
+
507
+ /** Wouldn't it be nice if we could just call `os.remove.all(this)`?
508
+ * For some reason, Scala 2 throws a rather obscure `[error] Unwanted cyclic dependency`
509
+ */
510
+ private def deleteRecursively (ioPath : java.nio.file.Path ): Unit = {
511
+ if (Files .isDirectory(ioPath)) {
512
+ Files .list(ioPath).forEach(deleteRecursively)
513
+ }
514
+ Files .deleteIfExists(ioPath)
515
+ }
504
516
}
505
517
506
518
sealed trait PathConvertible [T ] {
0 commit comments