diff --git a/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala index 195e1695c..926138101 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/fs/package.scala @@ -108,15 +108,27 @@ package object fs { promiseWithError0[FileIOError](instance.mkdir(path, options, _)) } + @inline + def mkdtempFuture(prefix: String, options: FileEncodingOptions = ???): Future[String] = { + promiseWithError1[FileIOError, String](instance.mkdtemp(prefix, options, _)) + } + @inline def openFuture(path: Buffer | String, flags: Flags, mode: FileMode): Future[FileDescriptor] = { promiseWithError1[FileIOError, FileDescriptor](instance.open(path, flags, mode, _)) } + @inline def openFuture(path: Buffer | String, flags: Flags): Future[FileDescriptor] = { promiseWithError1[FileIOError, FileDescriptor](instance.open(path, flags, _)) } + @enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) + @inline + def openFuture(path: Buffer | String): Future[FileDescriptor] = { + promiseWithError1[FileIOError, FileDescriptor](instance.open(path, _)) + } + @inline def readFuture(fd: FileDescriptor, buffer: Buffer, diff --git a/app/current/src/main/scala/io/scalajs/nodejs/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/package.scala index 138aed496..f63f2e75d 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/package.scala @@ -32,7 +32,7 @@ package object nodejs { type FileIOError = SystemError - type FileMode = Int | Null + type FileMode = Int type FileType = Int diff --git a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala index 4366f920c..72cda86b8 100644 --- a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala @@ -4,6 +4,7 @@ import io.scalajs.nodejs.buffer.Buffer import org.scalatest.{AsyncFunSpec, BeforeAndAfterEach} import scala.concurrent.{ExecutionContext, Future} +import scala.util.{Failure, Success} class FsAsyncTest extends AsyncFunSpec with BeforeAndAfterEach { @@ -40,5 +41,49 @@ class FsAsyncTest extends AsyncFunSpec with BeforeAndAfterEach { } } } + + describe("accessFuture") { + it("should succeed") { + for { + _ <- Fs.accessFuture("package.json") + _ <- Fs.accessFuture("package.json", Fs.constants.R_OK) + } yield { + succeed + } + } + + it("should fail: no such file") { + Fs.accessFuture("package.json111").transformWith { + case Failure(_) => succeed + case Success(_) => fail("expected failure") + } + } + + it("should fail: invalid file mode") { + Fs.accessFuture("package.json", Fs.constants.X_OK).transformWith { + case Failure(_) => succeed + case Success(_) => fail("expected failure") + } + } + } + + describe("appendFileFuture") { + it("should support option") { + for { + _ <- Fs.appendFileFuture("x.AppendFile.txt", "yay") + _ <- Fs.appendFileFuture("x.AppendFile.sh", "echo 0", new FileAppendOptions(mode = Fs.constants.X_OK)) + defaultStat <- Fs.statFuture("x.AppendFile.txt") + executableStat <- Fs.statFuture("x.AppendFile.sh") + _ <- Fs.unlinkFuture("x.AppendFile.txt") + _ <- Fs.unlinkFuture("x.AppendFile.sh") + } yield { + assert((defaultStat.mode & Fs.constants.R_OK) > 0) + assert((defaultStat.mode & Fs.constants.X_OK) === 0) + assert((executableStat.mode & Fs.constants.R_OK) === 0) + assert((executableStat.mode & Fs.constants.X_OK) > 0) + succeed + } + } + } } }