@@ -2,6 +2,7 @@ package os
22
33import java .net .URI
44import java .nio .file .Paths
5+ import java .nio .file .Files
56
67import collection .JavaConverters ._
78import scala .language .implicitConversions
@@ -281,7 +282,7 @@ class RelPath private[os] (segments0: Array[String], val ups: Int)
281282 case _ => false
282283 }
283284
284- def toNIO = java.nio.file. Paths .get(toString)
285+ def toNIO = Paths .get(toString)
285286
286287 def asSubPath = {
287288 require(ups == 0 )
@@ -342,7 +343,7 @@ class SubPath private[os] (val segments0: Array[String])
342343 case _ => false
343344 }
344345
345- def toNIO = java.nio.file. Paths .get(toString)
346+ def toNIO = Paths .get(toString)
346347
347348 def resolveFrom (base : os.Path ) = base / this
348349}
@@ -448,7 +449,7 @@ trait ReadablePath {
448449class Path private [os] (val wrapped : java.nio.file.Path )
449450 extends FilePath with ReadablePath with BasePathImpl {
450451 def toSource : SeekableSource =
451- new SeekableSource .ChannelSource (java.nio.file. Files .newByteChannel(wrapped))
452+ new SeekableSource .ChannelSource (Files .newByteChannel(wrapped))
452453
453454 require(wrapped.isAbsolute, s " $wrapped is not an absolute path " )
454455 def segments : Iterator [String ] = wrapped.iterator().asScala.map(_.toString)
@@ -495,12 +496,23 @@ class Path private[os] (val wrapped: java.nio.file.Path)
495496
496497 def resolveFrom (base : os.Path ) = this
497498
498- def getInputStream = java.nio.file. Files .newInputStream(wrapped)
499+ def getInputStream = Files .newInputStream(wrapped)
499500}
500501
501502class TempPath private [os] (wrapped : java.nio.file.Path )
502503 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+ }
504516}
505517
506518sealed trait PathConvertible [T ] {
0 commit comments