summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayeem Rahman <muhammed.9939@gmail.com>2019-08-13 14:39:01 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-08-13 09:39:01 -0400
commit1947f572d735096c1ccd7de2c386b8289c287701 (patch)
tree71df928d77e790cb2cd37a7c835917030c1d7721
parentc3afa557515c64610b23ee460f8c6251de421f1a (diff)
Fix permission requirements for Deno.rename() and Deno.link() (#2737)
-rw-r--r--cli/ops.rs9
-rw-r--r--js/link_test.ts15
-rw-r--r--js/rename_test.ts15
3 files changed, 34 insertions, 5 deletions
diff --git a/cli/ops.rs b/cli/ops.rs
index d5da90567..166610bac 100644
--- a/cli/ops.rs
+++ b/cli/ops.rs
@@ -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 || {
diff --git a/js/link_test.ts b/js/link_test.ts
index 86e466abf..9425e6eab 100644
--- a/js/link_test.ts
+++ b/js/link_test.ts
@@ -1,5 +1,5 @@
// 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");
diff --git a/js/rename_test.ts b/js/rename_test.ts
index ce87a3dfe..43d02d419 100644
--- a/js/rename_test.ts
+++ b/js/rename_test.ts
@@ -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";