summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/js/lib.deno.ns.d.ts2
-rw-r--r--cli/js/tests/dir_test.ts52
-rw-r--r--cli/ops/fs.rs2
3 files changed, 31 insertions, 25 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index f2c9fa4bb..45730acbc 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -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;
diff --git a/cli/js/tests/dir_test.ts b/cli/js/tests/dir_test.ts
index 09236fa22..3686471f1 100644
--- a/cli/js/tests/dir_test.ts
+++ b/cli/js/tests/dir_test.ts
@@ -5,20 +5,23 @@ unitTest(function dirCwdNotNull(): void {
assert(Deno.cwd() != null);
});
-unitTest({ perms: { write: true } }, function dirCwdChdirSuccess(): void {
- const initialdir = Deno.cwd();
- const path = Deno.makeTempDirSync();
- Deno.chdir(path);
- const current = Deno.cwd();
- if (Deno.build.os === "darwin") {
- assertEquals(current, "/private" + path);
- } else {
- assertEquals(current, path);
+unitTest(
+ { perms: { read: true, write: true } },
+ function dirCwdChdirSuccess(): void {
+ const initialdir = Deno.cwd();
+ const path = Deno.makeTempDirSync();
+ Deno.chdir(path);
+ const current = Deno.cwd();
+ if (Deno.build.os === "darwin") {
+ assertEquals(current, "/private" + path);
+ } else {
+ assertEquals(current, path);
+ }
+ Deno.chdir(initialdir);
}
- 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,16 +42,19 @@ unitTest({ perms: { write: true } }, function dirCwdError(): void {
}
});
-unitTest({ perms: { write: true } }, function dirChdirError(): void {
- const path = Deno.makeTempDirSync() + "test";
- try {
- Deno.chdir(path);
- throw Error("directory not available, should throw error");
- } catch (err) {
- if (err instanceof Deno.errors.NotFound) {
- assert(err.name === "NotFound");
- } else {
- throw Error("raised different exception");
+unitTest(
+ { perms: { read: true, write: true } },
+ function dirChdirError(): void {
+ const path = Deno.makeTempDirSync() + "test";
+ try {
+ Deno.chdir(path);
+ throw Error("directory not available, should throw error");
+ } catch (err) {
+ if (err instanceof Deno.errors.NotFound) {
+ assert(err.name === "NotFound");
+ } else {
+ throw Error("raised different exception");
+ }
}
}
-});
+);
diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs
index 55ee1afa3..cccf32c12 100644
--- a/cli/ops/fs.rs
+++ b/cli/ops/fs.rs
@@ -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!({})))
}