mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
support permission mode in mkdir (#4286)
This commit is contained in:
parent
72c408ea9d
commit
a28fa2415f
5 changed files with 28 additions and 14 deletions
2
cli/js/lib.deno.ns.d.ts
vendored
2
cli/js/lib.deno.ns.d.ts
vendored
|
@ -740,7 +740,7 @@ declare namespace Deno {
|
|||
recursive?: boolean;
|
||||
/** Permissions to use when creating the directory (defaults to `0o777`,
|
||||
* before the process's umask).
|
||||
* Does nothing/raises on Windows. */
|
||||
* Ignored on Windows. */
|
||||
mode?: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
||||
|
||||
type MkdirArgs = { path: string; recursive: boolean; mode?: number };
|
||||
|
||||
// TODO(ry) The complexity in argument parsing is to support deprecated forms of
|
||||
// mkdir and mkdirSync.
|
||||
function mkdirArgs(
|
||||
path: string,
|
||||
optionsOrRecursive?: MkdirOptions | boolean,
|
||||
mode?: number
|
||||
): { path: string; recursive: boolean; mode: number } {
|
||||
const args = { path, recursive: false, mode: 0o777 };
|
||||
): MkdirArgs {
|
||||
const args: MkdirArgs = { path, recursive: false };
|
||||
if (typeof optionsOrRecursive == "boolean") {
|
||||
args.recursive = optionsOrRecursive;
|
||||
if (mode) {
|
||||
|
@ -34,7 +36,7 @@ export interface MkdirOptions {
|
|||
recursive?: boolean;
|
||||
/** Permissions to use when creating the directory (defaults to `0o777`,
|
||||
* before the process's umask).
|
||||
* Does nothing/raises on Windows. */
|
||||
* Ignored on Windows. */
|
||||
mode?: number;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,10 @@ unitTest(
|
|||
{ perms: { read: true, write: true } },
|
||||
function mkdirSyncMode(): void {
|
||||
const path = Deno.makeTempDirSync() + "/dir";
|
||||
Deno.mkdirSync(path, { mode: 0o755 }); // no perm for x
|
||||
Deno.mkdirSync(path, { mode: 0o737 });
|
||||
const pathInfo = Deno.statSync(path);
|
||||
if (pathInfo.mode !== null) {
|
||||
// Skip windows
|
||||
assertEquals(pathInfo.mode & 0o777, 0o755);
|
||||
if (Deno.build.os !== "win") {
|
||||
assertEquals(pathInfo.mode! & 0o777, 0o737 & ~Deno.umask());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -45,6 +44,18 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true } },
|
||||
async function mkdirMode(): Promise<void> {
|
||||
const path = Deno.makeTempDirSync() + "/dir";
|
||||
await Deno.mkdir(path, { mode: 0o737 });
|
||||
const pathInfo = Deno.statSync(path);
|
||||
if (Deno.build.os !== "win") {
|
||||
assertEquals(pathInfo.mode! & 0o777, 0o737 & ~Deno.umask());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
unitTest({ perms: { write: true } }, function mkdirErrIfExists(): void {
|
||||
let err;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue