2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-09 19:22:15 -04:00
|
|
|
import { sendSync, sendAsync } from "../dispatch_json.ts";
|
2019-03-09 12:30:38 -05:00
|
|
|
|
2020-03-11 16:14:23 -04:00
|
|
|
type MkdirArgs = { path: string; recursive: boolean; mode?: number };
|
|
|
|
|
2020-01-07 14:14:33 -05:00
|
|
|
// TODO(ry) The complexity in argument parsing is to support deprecated forms of
|
|
|
|
// mkdir and mkdirSync.
|
|
|
|
function mkdirArgs(
|
|
|
|
path: string,
|
2020-03-02 15:24:42 -05:00
|
|
|
optionsOrRecursive?: MkdirOptions | boolean,
|
2020-01-07 14:14:33 -05:00
|
|
|
mode?: number
|
2020-03-11 16:14:23 -04:00
|
|
|
): MkdirArgs {
|
|
|
|
const args: MkdirArgs = { path, recursive: false };
|
2020-01-07 14:14:33 -05:00
|
|
|
if (typeof optionsOrRecursive == "boolean") {
|
|
|
|
args.recursive = optionsOrRecursive;
|
|
|
|
if (mode) {
|
|
|
|
args.mode = mode;
|
|
|
|
}
|
|
|
|
} else if (optionsOrRecursive) {
|
|
|
|
if (typeof optionsOrRecursive.recursive == "boolean") {
|
|
|
|
args.recursive = optionsOrRecursive.recursive;
|
|
|
|
}
|
|
|
|
if (optionsOrRecursive.mode) {
|
|
|
|
args.mode = optionsOrRecursive.mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2020-03-02 15:24:42 -05:00
|
|
|
export interface MkdirOptions {
|
2020-01-07 14:14:33 -05:00
|
|
|
recursive?: boolean;
|
|
|
|
mode?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function mkdirSync(
|
|
|
|
path: string,
|
2020-03-02 15:24:42 -05:00
|
|
|
optionsOrRecursive?: MkdirOptions | boolean,
|
2020-01-07 14:14:33 -05:00
|
|
|
mode?: number
|
|
|
|
): void {
|
2020-02-25 09:14:27 -05:00
|
|
|
sendSync("op_mkdir", mkdirArgs(path, optionsOrRecursive, mode));
|
2018-09-10 05:48:36 -04:00
|
|
|
}
|
|
|
|
|
2019-01-17 23:39:06 -05:00
|
|
|
export async function mkdir(
|
|
|
|
path: string,
|
2020-03-02 15:24:42 -05:00
|
|
|
optionsOrRecursive?: MkdirOptions | boolean,
|
2020-01-07 14:14:33 -05:00
|
|
|
mode?: number
|
2019-01-17 23:39:06 -05:00
|
|
|
): Promise<void> {
|
2020-02-25 09:14:27 -05:00
|
|
|
await sendAsync("op_mkdir", mkdirArgs(path, optionsOrRecursive, mode));
|
2018-09-10 05:48:36 -04:00
|
|
|
}
|