Skip to content

Commit

Permalink
fix: Resolve makeTemp* paths from CWD (#4104)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Feb 25, 2020
1 parent 91b606a commit 14e7e1e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
10 changes: 7 additions & 3 deletions cli/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -534,7 +534,9 @@ fn op_make_temp_dir(
) -> Result<JsonOp, OpError> {
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);

Expand Down Expand Up @@ -566,7 +568,9 @@ fn op_make_temp_file(
) -> Result<JsonOp, OpError> {
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);

Expand Down
1 change: 1 addition & 0 deletions cli/tests/056_make_temp_file_write_perm.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
good [WILDCARD]subdir[WILDCARD]
8 changes: 8 additions & 0 deletions cli/tests/056_make_temp_file_write_perm.ts
Original file line number Diff line number Diff line change
@@ -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);
17 changes: 11 additions & 6 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 14e7e1e

Please sign in to comment.