1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

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

This commit is contained in:
Nayeem Rahman 2019-08-13 14:39:01 +01:00 committed by Ryan Dahl
parent c3afa55751
commit 1947f572d7
3 changed files with 34 additions and 5 deletions

View file

@ -1404,10 +1404,13 @@ fn op_rename(
) -> CliOpResult { ) -> CliOpResult {
assert!(data.is_none()); assert!(data.is_none());
let inner = base.inner_as_rename().unwrap(); 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_) = let (newpath, newpath_) =
deno_fs::resolve_from_cwd(inner.newpath().unwrap())?; deno_fs::resolve_from_cwd(inner.newpath().unwrap())?;
state.check_read(&oldpath_)?;
state.check_write(&oldpath_)?;
state.check_write(&newpath_)?; state.check_write(&newpath_)?;
blocking(base.sync(), move || { blocking(base.sync(), move || {
@ -1424,10 +1427,12 @@ fn op_link(
) -> CliOpResult { ) -> CliOpResult {
assert!(data.is_none()); assert!(data.is_none());
let inner = base.inner_as_link().unwrap(); 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_) = let (newname, newname_) =
deno_fs::resolve_from_cwd(inner.newname().unwrap())?; deno_fs::resolve_from_cwd(inner.newname().unwrap())?;
state.check_read(&oldpath_)?;
state.check_write(&newname_)?; state.check_write(&newname_)?;
blocking(base.sync(), move || { blocking(base.sync(), move || {

View file

@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // 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 { testPerm({ read: true, write: true }, function linkSyncSuccess(): void {
const testDir = Deno.makeTempDirSync(); const testDir = Deno.makeTempDirSync();
@ -63,7 +63,18 @@ testPerm({ read: true, write: true }, function linkSyncNotFound(): void {
assertEquals(err.name, "NotFound"); 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; let err;
try { try {
Deno.linkSync("oldbaddir", "newbaddir"); Deno.linkSync("oldbaddir", "newbaddir");

View file

@ -23,7 +23,20 @@ testPerm({ read: true, write: true }, function renameSyncSuccess(): void {
assertEquals(oldPathInfo, undefined); 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; let err;
try { try {
const oldpath = "/oldbaddir"; const oldpath = "/oldbaddir";