diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/deno.ts | 1 | ||||
-rw-r--r-- | js/os.ts | 19 | ||||
-rw-r--r-- | js/os_test.ts | 21 |
3 files changed, 41 insertions, 0 deletions
diff --git a/js/deno.ts b/js/deno.ts index 21766401b..d121b3183 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -6,6 +6,7 @@ export { exit, FileInfo, makeTempDirSync, + mkdirSync, readFileSync, statSync, lStatSync, @@ -104,6 +104,25 @@ export function makeTempDirSync({ return path!; } +// mkdir creates a new directory with the specified name +// and permission bits (before umask). +export function mkdirSync(path: string, mode = 0o777): void { + /* Ideally we could write: + const res = send({ + command: fbs.Command.MKDIR_SYNC, + mkdirSyncPath: path, + mkdirSyncMode: mode, + }); + */ + const builder = new flatbuffers.Builder(); + const path_ = builder.createString(path); + fbs.MkdirSync.startMkdirSync(builder); + fbs.MkdirSync.addPath(builder, path_); + fbs.MkdirSync.addMode(builder, mode); + const msg = fbs.MkdirSync.endMkdirSync(builder); + send(builder, fbs.Any.MkdirSync, msg); +} + export function readFileSync(filename: string): Uint8Array { /* Ideally we could write const res = send({ diff --git a/js/os_test.ts b/js/os_test.ts index cd5ede221..8142956eb 100644 --- a/js/os_test.ts +++ b/js/os_test.ts @@ -183,3 +183,24 @@ test(function makeTempDirSyncPerm() { assert(err); assertEqual(err.name, "deno.PermissionDenied"); }); + +testPerm({ write: true }, function mkdirSync() { + const path = deno.makeTempDirSync() + "/dir/subdir"; + deno.mkdirSync(path); + const pathInfo = deno.statSync(path); + assert(pathInfo.isDirectory()); +}); + +testPerm({ write: false }, function mkdDirSyncPerm() { + let err; + try { + const path = "/baddir"; + deno.mkdirSync(path); + } catch (err_) { + err = err_; + } + // TODO assert(err instanceof deno.PermissionDenied). + assert(err); + assertEqual(err.name, "deno.PermissionDenied"); +}); + |