2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-06 20:48:46 -05:00
|
|
|
import { testPerm, assert, assertEquals } from "./test_util.ts";
|
2018-09-12 11:44:58 -04:00
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, function renameSyncSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2018-09-12 11:44:58 -04:00
|
|
|
const oldpath = testDir + "/oldpath";
|
|
|
|
const newpath = testDir + "/newpath";
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.mkdirSync(oldpath);
|
|
|
|
Deno.renameSync(oldpath, newpath);
|
|
|
|
const newPathInfo = Deno.statSync(newpath);
|
2018-09-12 11:44:58 -04:00
|
|
|
assert(newPathInfo.isDirectory());
|
|
|
|
|
|
|
|
let caughtErr = false;
|
|
|
|
let oldPathInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
oldPathInfo = Deno.statSync(oldpath);
|
2018-09-12 11:44:58 -04:00
|
|
|
} catch (e) {
|
|
|
|
caughtErr = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
2018-09-12 11:44:58 -04:00
|
|
|
}
|
|
|
|
assert(caughtErr);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(oldPathInfo, undefined);
|
2018-09-12 11:44:58 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: false }, function renameSyncPerm() {
|
2018-09-12 11:44:58 -04:00
|
|
|
let err;
|
|
|
|
try {
|
|
|
|
const oldpath = "/oldbaddir";
|
|
|
|
const newpath = "/newbaddir";
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.renameSync(oldpath, newpath);
|
2018-09-12 11:44:58 -04:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEquals(err.name, "PermissionDenied");
|
2018-09-12 11:44:58 -04:00
|
|
|
});
|
|
|
|
|
2019-02-08 15:59:38 -05:00
|
|
|
testPerm({ read: true, write: true }, async function renameSuccess() {
|
2019-02-12 10:08:56 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2018-09-12 11:44:58 -04:00
|
|
|
const oldpath = testDir + "/oldpath";
|
|
|
|
const newpath = testDir + "/newpath";
|
2019-02-12 10:08:56 -05:00
|
|
|
Deno.mkdirSync(oldpath);
|
|
|
|
await Deno.rename(oldpath, newpath);
|
|
|
|
const newPathInfo = Deno.statSync(newpath);
|
2018-09-12 11:44:58 -04:00
|
|
|
assert(newPathInfo.isDirectory());
|
|
|
|
|
|
|
|
let caughtErr = false;
|
|
|
|
let oldPathInfo;
|
|
|
|
|
|
|
|
try {
|
2019-02-12 10:08:56 -05:00
|
|
|
oldPathInfo = Deno.statSync(oldpath);
|
2018-09-12 11:44:58 -04:00
|
|
|
} catch (e) {
|
|
|
|
caughtErr = true;
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(e.kind, Deno.ErrorKind.NotFound);
|
2018-09-12 11:44:58 -04:00
|
|
|
}
|
|
|
|
assert(caughtErr);
|
2019-03-06 20:48:46 -05:00
|
|
|
assertEquals(oldPathInfo, undefined);
|
2018-09-12 11:44:58 -04:00
|
|
|
});
|