summaryrefslogtreecommitdiff
path: root/cli/deno_dir.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-02-03 14:08:17 +0100
committerGitHub <noreply@github.com>2022-02-03 14:08:17 +0100
commit681c3be18de764d3844acbff4a05ac5f40bc3a5f (patch)
tree8389c8885e10d14b4f019916738d869659c73848 /cli/deno_dir.rs
parented3086e4b129843c13a009112cf21dfd05745905 (diff)
fix: don't crash when $HOME is a relative path (#13581)
Absolutize the cache/home dir before use in DenoDir.
Diffstat (limited to 'cli/deno_dir.rs')
-rw-r--r--cli/deno_dir.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs
index 674d32c51..ca6f8b81f 100644
--- a/cli/deno_dir.rs
+++ b/cli/deno_dir.rs
@@ -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)
- }
+ 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");