Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions cli/ops.rs
Expand Up @@ -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 || {
Expand All @@ -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 || {
Expand Down
15 changes: 13 additions & 2 deletions 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();
Expand Down Expand Up @@ -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 {
nayeemrmn marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand Down
15 changes: 14 additions & 1 deletion js/rename_test.ts
Expand Up @@ -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";
Expand Down