diff options
author | dubiousjim <dubiousjim@gmail.com> | 2020-03-10 15:11:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 15:11:27 -0400 |
commit | 8078d976d29aa12819e3f5a781c846d67868b0d6 (patch) | |
tree | 3ec7786dd9b7e787c27f58e2041110e6fca86e2b /cli/js | |
parent | 6443e4aed16868c17111a56634aa733211430f46 (diff) |
Add Deno.umask (#4290)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/deno.ts | 1 | ||||
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 8 | ||||
-rw-r--r-- | cli/js/ops/fs/umask.ts | 12 | ||||
-rw-r--r-- | cli/js/tests/umask_test.ts | 16 | ||||
-rw-r--r-- | cli/js/tests/unit_tests.ts | 1 |
5 files changed, 38 insertions, 0 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts index 23fcfda5d..f0115f261 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -113,6 +113,7 @@ export { symlinkSync, symlink } from "./ops/fs/symlink.ts"; export { connectTLS, listenTLS } from "./tls.ts"; export { truncateSync, truncate } from "./ops/fs/truncate.ts"; export { isatty, setRaw } from "./ops/tty.ts"; +export { umask } from "./ops/fs/umask.ts"; export { utimeSync, utime } from "./ops/fs/utime.ts"; export { version } from "./version.ts"; export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts"; diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 8eb2e1f4d..6950d9050 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -287,6 +287,14 @@ declare namespace Deno { */ export function chdir(directory: string): void; + /** + * **UNSTABLE**: New API. Maybe needs permissions. + * + * If `mask` is provided, sets the process umask. Always returns what the umask + * was before the call. + */ + export function umask(mask?: number): number; + /** **UNSTABLE**: might move to `Deno.symbols`. */ export const EOF: unique symbol; export type EOF = typeof EOF; diff --git a/cli/js/ops/fs/umask.ts b/cli/js/ops/fs/umask.ts new file mode 100644 index 000000000..ee56fecb5 --- /dev/null +++ b/cli/js/ops/fs/umask.ts @@ -0,0 +1,12 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { sendSync } from "../dispatch_json.ts"; + +/** + * **UNSTABLE**: maybe needs `allow-env` permissions. + * + * If `mask` is provided, sets the process umask. Always returns what the umask + * was before the call. + */ +export function umask(mask?: number): number { + return sendSync("op_umask", { mask }); +} diff --git a/cli/js/tests/umask_test.ts b/cli/js/tests/umask_test.ts new file mode 100644 index 000000000..543372a46 --- /dev/null +++ b/cli/js/tests/umask_test.ts @@ -0,0 +1,16 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { unitTest, assertEquals } from "./test_util.ts"; + +unitTest( + { + skip: Deno.build.os === "win" + }, + function umaskSuccess(): void { + const prevMask = Deno.umask(0o020); + const newMask = Deno.umask(prevMask); + const finalMask = Deno.umask(); + assertEquals(newMask, 0o020); + assertEquals(finalMask, prevMask); + assertEquals(prevMask, 0o022); + } +); diff --git a/cli/js/tests/unit_tests.ts b/cli/js/tests/unit_tests.ts index cc51e6ade..9ae724d53 100644 --- a/cli/js/tests/unit_tests.ts +++ b/cli/js/tests/unit_tests.ts @@ -57,6 +57,7 @@ import "./timers_test.ts"; import "./tls_test.ts"; import "./truncate_test.ts"; import "./tty_test.ts"; +import "./umask_test.ts"; import "./url_test.ts"; import "./url_search_params_test.ts"; import "./utime_test.ts"; |