2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-01-12 09:16:18 -05:00
|
|
|
import { testPerm, assert, assertEqual } from "./test_util.ts";
|
2018-09-10 05:48:36 -04:00
|
|
|
import * as deno from "deno";
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function mkdirSyncSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const path = deno.makeTempDirSync() + "/dir";
|
2018-09-10 05:48:36 -04:00
|
|
|
deno.mkdirSync(path);
|
|
|
|
const pathInfo = deno.statSync(path);
|
|
|
|
assert(pathInfo.isDirectory());
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function mkdirSyncMode() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const path = deno.makeTempDirSync() + "/dir";
|
|
|
|
deno.mkdirSync(path, false, 0o755); // no perm for x
|
2018-09-14 15:30:43 -04:00
|
|
|
const pathInfo = deno.statSync(path);
|
2018-09-16 16:35:16 -04:00
|
|
|
if (pathInfo.mode !== null) {
|
|
|
|
// Skip windows
|
2018-09-14 15:30:43 -04:00
|
|
|
assertEqual(pathInfo.mode & 0o777, 0o755);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-10 05:48:36 -04:00
|
|
|
testPerm({ write: false }, function mkdirSyncPerm() {
|
|
|
|
let err;
|
|
|
|
try {
|
|
|
|
deno.mkdirSync("/baddir");
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEqual(err.name, "PermissionDenied");
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function mkdirSuccess() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const path = deno.makeTempDirSync() + "/dir";
|
2018-09-10 05:48:36 -04:00
|
|
|
await deno.mkdir(path);
|
|
|
|
const pathInfo = deno.statSync(path);
|
|
|
|
assert(pathInfo.isDirectory());
|
|
|
|
});
|
2019-01-17 23:39:06 -05:00
|
|
|
|
|
|
|
testPerm({ write: true }, function mkdirErrIfExists() {
|
|
|
|
let err;
|
|
|
|
try {
|
|
|
|
deno.mkdirSync(".");
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
assertEqual(err.kind, deno.ErrorKind.AlreadyExists);
|
|
|
|
assertEqual(err.name, "AlreadyExists");
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function mkdirSyncRecursive() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const path = deno.makeTempDirSync() + "/nested/directory";
|
|
|
|
deno.mkdirSync(path, true);
|
|
|
|
const pathInfo = deno.statSync(path);
|
|
|
|
assert(pathInfo.isDirectory());
|
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function mkdirRecursive() {
|
2019-01-17 23:39:06 -05:00
|
|
|
const path = deno.makeTempDirSync() + "/nested/directory";
|
|
|
|
await deno.mkdir(path, true);
|
|
|
|
const pathInfo = deno.statSync(path);
|
|
|
|
assert(pathInfo.isDirectory());
|
|
|
|
});
|