summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-04-24 19:55:33 -0400
committerGitHub <noreply@github.com>2020-04-24 19:55:33 -0400
commitf8d83361cd11d3aa42333171ecb6b129fdcbefeb (patch)
tree3b333407a691fa88041b917f932cac74a5261a2f
parent1378df33647e2608733d88121b77ff2f839cddfa (diff)
chdir should require --allow-write (#4889)
-rw-r--r--cli/js/lib.deno.ns.d.ts5
-rw-r--r--cli/ops/fs.rs6
2 files changed, 6 insertions, 5 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 493ebd5e2..64e3613f5 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -405,9 +405,6 @@ declare namespace Deno {
export function cwd(): string;
/**
- * **UNSTABLE**: Currently under evaluation to decide if explicit permission is
- * required to change the current working directory.
- *
* Change the current working directory to the specified path.
*
* Deno.chdir("/home/userA");
@@ -417,6 +414,8 @@ declare namespace Deno {
* Throws `Deno.errors.NotFound` if directory not found.
* Throws `Deno.errors.PermissionDenied` if the user does not have access
* rights
+ *
+ * Requires --allow-write.
*/
export function chdir(directory: string): void;
diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs
index 6b259e033..c46da6c04 100644
--- a/cli/ops/fs.rs
+++ b/cli/ops/fs.rs
@@ -245,12 +245,14 @@ struct ChdirArgs {
}
fn op_chdir(
- _state: &State,
+ state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
let args: ChdirArgs = serde_json::from_value(args)?;
- set_current_dir(&args.directory)?;
+ let d = PathBuf::from(&args.directory);
+ state.check_write(&d)?;
+ set_current_dir(&d)?;
Ok(JsonOp::Sync(json!({})))
}