From 14e7e1e3af43b2322a26fcc542428c8f1af4460d Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 25 Feb 2020 14:23:23 +0000 Subject: [PATCH] fix: Resolve makeTemp* paths from CWD (#4104) --- cli/ops/fs.rs | 10 +++++++--- cli/tests/056_make_temp_file_write_perm.out | 1 + cli/tests/056_make_temp_file_write_perm.ts | 8 ++++++++ cli/tests/integration_tests.rs | 17 +++++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 cli/tests/056_make_temp_file_write_perm.out create mode 100644 cli/tests/056_make_temp_file_write_perm.ts diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 13c2418cb4..4d7bd9d158 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -9,7 +9,7 @@ use deno_core::*; use remove_dir_all::remove_dir_all; use std::convert::From; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::time::UNIX_EPOCH; #[cfg(unix)] @@ -534,7 +534,9 @@ fn op_make_temp_dir( ) -> Result { let args: MakeTempArgs = serde_json::from_value(args)?; - let dir = args.dir.map(PathBuf::from); + let dir = args + .dir + .map(|s| deno_fs::resolve_from_cwd(Path::new(&s)).unwrap()); let prefix = args.prefix.map(String::from); let suffix = args.suffix.map(String::from); @@ -566,7 +568,9 @@ fn op_make_temp_file( ) -> Result { let args: MakeTempArgs = serde_json::from_value(args)?; - let dir = args.dir.map(PathBuf::from); + let dir = args + .dir + .map(|s| deno_fs::resolve_from_cwd(Path::new(&s)).unwrap()); let prefix = args.prefix.map(String::from); let suffix = args.suffix.map(String::from); diff --git a/cli/tests/056_make_temp_file_write_perm.out b/cli/tests/056_make_temp_file_write_perm.out new file mode 100644 index 0000000000..c56aae43f6 --- /dev/null +++ b/cli/tests/056_make_temp_file_write_perm.out @@ -0,0 +1 @@ +good [WILDCARD]subdir[WILDCARD] diff --git a/cli/tests/056_make_temp_file_write_perm.ts b/cli/tests/056_make_temp_file_write_perm.ts new file mode 100644 index 0000000000..15aefaff99 --- /dev/null +++ b/cli/tests/056_make_temp_file_write_perm.ts @@ -0,0 +1,8 @@ +const path = await Deno.makeTempFile({ dir: "./subdir/" }); +if (path.startsWith(Deno.cwd())) { + console.log("good", path); +} else { + throw Error("bad " + path); +} +console.log(path); +await Deno.remove(path); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index ccc5713314..3e2c289803 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -784,6 +784,17 @@ itest!(_054_info_local_imports { exit_code: 0, }); +itest!(_055_import_wasm_via_network { + args: "run --reload http://127.0.0.1:4545/cli/tests/055_import_wasm_via_network.ts", + output: "055_import_wasm_via_network.ts.out", + http_server: true, +}); + +itest!(_056_make_temp_file_write_perm { + args: "run --allow-write=./subdir/ 056_make_temp_file_write_perm.ts", + output: "056_make_temp_file_write_perm.out", +}); + itest!(js_import_detect { args: "run --reload js_import_detect.ts", output: "js_import_detect.ts.out", @@ -1129,12 +1140,6 @@ itest!(_053_import_compression { http_server: true, }); -itest!(import_wasm_via_network { - args: "run --reload http://127.0.0.1:4545/cli/tests/055_import_wasm_via_network.ts", - output: "055_import_wasm_via_network.ts.out", - http_server: true, -}); - itest!(cafile_url_imports { args: "run --reload --cert tls/RootCA.pem cafile_url_imports.ts", output: "cafile_url_imports.ts.out",