Skip to content

Commit

Permalink
support for ubuntu and nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Oct 28, 2021
1 parent ad1c093 commit 94e034f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions okio-nodefilesystem/src/main/kotlin/okio/NodeJsFileSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ object NodeJsFileSystem : FileSystem() {
}
}

override fun createDirectory(dir: Path) {
override fun createDirectory(dir: Path, mustCreate: Boolean) {
try {
mkdirSync(dir.toString())
} catch (e: Throwable) {
val alreadyExist = metadataOrNull(dir)?.isDirectory == true
if (alreadyExist) {
if (mustCreate) throw IOException("$dir already exist.")
else return
}

throw e.toIOException()
}
}
Expand All @@ -189,7 +195,7 @@ object NodeJsFileSystem : FileSystem() {
*
* TODO(jwilson): switch to fs.rmSync() when our minimum requirements are Node 14.14.0.
*/
override fun delete(path: Path) {
override fun delete(path: Path, mustExist: Boolean) {
try {
unlinkSync(path.toString())
return
Expand All @@ -198,6 +204,10 @@ object NodeJsFileSystem : FileSystem() {
try {
rmdirSync(path.toString())
} catch (e: Throwable) {
if (e.errorCode == "ENOENT") {
if (mustExist) throw FileNotFoundException("no such file: $path")
else return
}
throw e.toIOException()
}
}
Expand Down
2 changes: 1 addition & 1 deletion okio/src/mingwX64Main/kotlin/okio/-WindowsPosixVariant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal actual fun PosixFileSystem.variantDelete(path: Path, mustExist: Boolean
if (rmdir(pathString) == 0) return
}
if (errno == ENOENT) {
if (mustExist) throw FileNotFoundException("$path doesn't exist.")
if (mustExist) throw FileNotFoundException("no such file: $path")
else return
}

Expand Down
2 changes: 1 addition & 1 deletion okio/src/unixMain/kotlin/okio/-UnixPosixVariant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal actual fun PosixFileSystem.variantDelete(path: Path, mustExist: Boolean
val result = remove(path.toString())
if (result != 0) {
if (errno == ENOENT) {
if (mustExist) throw FileNotFoundException("$path doesn't exist.")
if (mustExist) throw FileNotFoundException("no such file: $path")
else return
}
throw errnoToIOException(errno)
Expand Down

0 comments on commit 94e034f

Please sign in to comment.