mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: don't crash when $HOME is a relative path (#13581)
Absolutize the cache/home dir before use in DenoDir.
This commit is contained in:
parent
be2b6ff5e2
commit
554d8b5ce1
2 changed files with 36 additions and 5 deletions
|
@ -16,11 +16,7 @@ pub struct DenoDir {
|
|||
impl DenoDir {
|
||||
pub fn new(maybe_custom_root: Option<PathBuf>) -> std::io::Result<Self> {
|
||||
let root: PathBuf = if let Some(root) = maybe_custom_root {
|
||||
if root.is_absolute() {
|
||||
root
|
||||
} else {
|
||||
std::env::current_dir()?.join(root)
|
||||
}
|
||||
} else if let Some(cache_dir) = dirs::cache_dir() {
|
||||
// We use the OS cache dir because all files deno writes are cache files
|
||||
// Once that changes we need to start using different roots if DENO_DIR
|
||||
|
@ -32,6 +28,11 @@ impl DenoDir {
|
|||
} else {
|
||||
panic!("Could not set the Deno root directory")
|
||||
};
|
||||
let root = if root.is_absolute() {
|
||||
root
|
||||
} else {
|
||||
std::env::current_dir()?.join(root)
|
||||
};
|
||||
assert!(root.is_absolute());
|
||||
let gen_path = root.join("gen");
|
||||
|
||||
|
|
|
@ -48,3 +48,33 @@ itest!(ignore_require {
|
|||
output_str: Some(""),
|
||||
exit_code: 0,
|
||||
});
|
||||
|
||||
// This test only runs on linux, because it hardcodes the XDG_CACHE_HOME env var
|
||||
// which is only used on linux.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn relative_home_dir() {
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
|
||||
let deno_dir = TempDir::new_in(util::testdata_path()).unwrap();
|
||||
let path = deno_dir.path().strip_prefix(util::testdata_path()).unwrap();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd();
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.env("XDG_CACHE_HOME", path)
|
||||
.env_remove("HOME")
|
||||
.env_remove("DENO_DIR")
|
||||
.arg("cache")
|
||||
.arg("--reload")
|
||||
.arg("--no-check")
|
||||
.arg("002_hello.ts")
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue