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-04-21 16:40:10 -04:00
|
|
|
testPerm({ read: true, write: true }, function renameSyncSuccess(): void {
|
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-04-21 16:40:10 -04:00
|
|
|
testPerm({ read: true, write: false }, function renameSyncPerm(): void {
|
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-04-21 16:40:10 -04:00
|
|
|
testPerm({ read: true, write: true }, async function renameSuccess(): Promise<
|
|
|
|
void
|
|
|
|
> {
|
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
|
|
|
});
|