1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

Deno.chdir should require allow-read not allow-write (#5033)

This commit is contained in:
Ryan Dahl 2020-05-02 18:33:43 -04:00 committed by GitHub
parent 2872b362ff
commit bbbf9f299c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 25 deletions

View file

@ -140,7 +140,7 @@ declare namespace Deno {
* Throws `Deno.errors.PermissionDenied` if the user does not have access
* rights
*
* Requires --allow-write.
* Requires --allow-read.
*/
export function chdir(directory: string): void;

View file

@ -5,7 +5,9 @@ unitTest(function dirCwdNotNull(): void {
assert(Deno.cwd() != null);
});
unitTest({ perms: { write: true } }, function dirCwdChdirSuccess(): void {
unitTest(
{ perms: { read: true, write: true } },
function dirCwdChdirSuccess(): void {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
@ -16,9 +18,10 @@ unitTest({ perms: { write: true } }, function dirCwdChdirSuccess(): void {
assertEquals(current, path);
}
Deno.chdir(initialdir);
});
}
);
unitTest({ perms: { write: true } }, function dirCwdError(): void {
unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void {
// excluding windows since it throws resource busy, while removeSync
if (["linux", "darwin"].includes(Deno.build.os)) {
const initialdir = Deno.cwd();
@ -39,7 +42,9 @@ unitTest({ perms: { write: true } }, function dirCwdError(): void {
}
});
unitTest({ perms: { write: true } }, function dirChdirError(): void {
unitTest(
{ perms: { read: true, write: true } },
function dirChdirError(): void {
const path = Deno.makeTempDirSync() + "test";
try {
Deno.chdir(path);
@ -51,4 +56,5 @@ unitTest({ perms: { write: true } }, function dirChdirError(): void {
throw Error("raised different exception");
}
}
});
}
);

View file

@ -254,7 +254,7 @@ fn op_chdir(
) -> Result<JsonOp, OpError> {
let args: ChdirArgs = serde_json::from_value(args)?;
let d = PathBuf::from(&args.directory);
state.check_write(&d)?;
state.check_read(&d)?;
set_current_dir(&d)?;
Ok(JsonOp::Sync(json!({})))
}