提交 1947f572 编写于 作者: N Nayeem Rahman 提交者: Ryan Dahl

Fix permission requirements for Deno.rename() and Deno.link() (#2737)

上级 c3afa557
......@@ -1404,10 +1404,13 @@ fn op_rename(
) -> CliOpResult {
assert!(data.is_none());
let inner = base.inner_as_rename().unwrap();
let (oldpath, _) = deno_fs::resolve_from_cwd(inner.oldpath().unwrap())?;
let (oldpath, oldpath_) =
deno_fs::resolve_from_cwd(inner.oldpath().unwrap())?;
let (newpath, newpath_) =
deno_fs::resolve_from_cwd(inner.newpath().unwrap())?;
state.check_read(&oldpath_)?;
state.check_write(&oldpath_)?;
state.check_write(&newpath_)?;
blocking(base.sync(), move || {
......@@ -1424,10 +1427,12 @@ fn op_link(
) -> CliOpResult {
assert!(data.is_none());
let inner = base.inner_as_link().unwrap();
let (oldname, _) = deno_fs::resolve_from_cwd(inner.oldname().unwrap())?;
let (oldname, oldpath_) =
deno_fs::resolve_from_cwd(inner.oldname().unwrap())?;
let (newname, newname_) =
deno_fs::resolve_from_cwd(inner.newname().unwrap())?;
state.check_read(&oldpath_)?;
state.check_write(&newname_)?;
blocking(base.sync(), move || {
......
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
import { testPerm, assert, assertEquals } from "./test_util.ts";
testPerm({ read: true, write: true }, function linkSyncSuccess(): void {
const testDir = Deno.makeTempDirSync();
......@@ -63,7 +63,18 @@ testPerm({ read: true, write: true }, function linkSyncNotFound(): void {
assertEquals(err.name, "NotFound");
});
test(function linkSyncPerm(): void {
testPerm({ read: false, write: true }, function linkSyncReadPerm(): void {
let err;
try {
Deno.linkSync("oldbaddir", "newbaddir");
} catch (e) {
err = e;
}
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
assertEquals(err.name, "PermissionDenied");
});
testPerm({ read: true, write: false }, function linkSyncWritePerm(): void {
let err;
try {
Deno.linkSync("oldbaddir", "newbaddir");
......
......@@ -23,7 +23,20 @@ testPerm({ read: true, write: true }, function renameSyncSuccess(): void {
assertEquals(oldPathInfo, undefined);
});
testPerm({ read: true, write: false }, function renameSyncPerm(): void {
testPerm({ read: false, write: true }, function renameSyncReadPerm(): void {
let err;
try {
const oldpath = "/oldbaddir";
const newpath = "/newbaddir";
Deno.renameSync(oldpath, newpath);
} catch (e) {
err = e;
}
assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
assertEquals(err.name, "PermissionDenied");
});
testPerm({ read: true, write: false }, function renameSyncWritePerm(): void {
let err;
try {
const oldpath = "/oldbaddir";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册