@@ -9,6 +9,7 @@ object FileTypes:
99 private [FileTypes ] val underlying : Path
1010 ):
1111 override def toString = underlying.toString
12+ def toPath : Path = underlying
1213
1314 given Conversion [Directory , Path ] = _.underlying
1415 object Directory :
@@ -30,25 +31,17 @@ object FileTypes:
3031 def fromPathUnsafe (path : Path ): Directory = Directory (path)
3132
3233 extension (dir : Directory )
33- def createDirIfDoesntExist : IO [Directory ] =
34- Files [IO ]
35- .exists(dir)
36- .ifM(
37- ifTrue = IO .pure(dir),
38- ifFalse = Files [IO ].createDirectories(dir).as(dir),
39- )
40-
4134 def clean : IO [Directory ] =
4235 for
43- _ <- Files [IO ].deleteRecursively(dir)
44- _ <- Files [IO ].createDirectory(dir)
36+ _ <- Files [IO ].deleteRecursively(dir.toPath )
37+ _ <- Files [IO ].createDirectory(dir.toPath )
4538 yield dir
4639
4740 class File private [FileTypes ] (private [FileTypes ] val underlying : Path ):
4841 override def toString (): String = underlying.toString
42+ def toPath = underlying
4943
5044 given Conversion [File , Path ] = _.underlying
51-
5245 object File :
5346 def fromPath (path : Path ): IO [Option [File ]] =
5447 Files [IO ]
@@ -68,15 +61,8 @@ object FileTypes:
6861 def fromPathUnsafe (path : Path ): File = File (path)
6962
7063 extension (file : File )
71- def createFileIfDoesntExist : IO [File ] =
72- file.parent match
73- case Some (parent) =>
74- (Files [IO ].createDirectories(parent) *> Files [IO ].createFile(file))
75- .as(file)
76- case None => Files [IO ].createFile(file).as(file)
77-
7864 def filenameNoExt : String =
79- val fileName = file.fileName.toString
65+ val fileName = file.toPath. fileName.toString
8066 fileName.splitAt(fileName.indexOf(" ." ))._1
8167
8268 def replaceExt (newExt : String ): File =
@@ -90,5 +76,6 @@ object FileTypes:
9076
9177 def mount (to : Directory , relativelyTo : Directory ): File =
9278 val relativePath =
93- relativelyTo.absolute.normalize.relativize(file.absolute.normalize)
94- File .fromPathUnsafe(to.normalize / relativePath)
79+ relativelyTo.toPath.absolute.normalize
80+ .relativize(file.toPath.absolute.normalize)
81+ File .fromPathUnsafe(to.toPath.normalize / relativePath)
0 commit comments