diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-05-15 16:32:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 16:32:52 +0200 |
commit | 89fe81168e75a375a67e9d391b367d2a9749153c (patch) | |
tree | 167624ec7acdb899e0ddf6a2a45fc093a5c44fc5 /cli/deno_dir.rs | |
parent | d4afc9890dfa60a233167e2ea003d9e7c830ee61 (diff) |
fix: panic if $DENO_DIR is a relative path (#5375)
This commit fixes panic occurring if $DENO_DIR is set to a relative
path, eg. "DENO_DIR=denodir deno run main.ts".
Before creating DenoDir instance given path is checked and if necessary
resolved against current working directory.
Additional sanity checks were put in place to ensure all caches
receive absolute path for the location.
Diffstat (limited to 'cli/deno_dir.rs')
-rw-r--r-- | cli/deno_dir.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs index 645a053d0..3224fbf46 100644 --- a/cli/deno_dir.rs +++ b/cli/deno_dir.rs @@ -13,7 +13,7 @@ pub struct DenoDir { } impl DenoDir { - pub fn new(custom_root: Option<PathBuf>) -> std::io::Result<Self> { + pub fn new(maybe_custom_root: Option<PathBuf>) -> std::io::Result<Self> { // Only setup once. let home_dir = dirs::home_dir().expect("Could not get home directory."); let fallback = home_dir.join(".deno"); @@ -24,7 +24,16 @@ impl DenoDir { .map(|d| d.join("deno")) .unwrap_or(fallback); - let root: PathBuf = custom_root.unwrap_or(default); + let root: PathBuf = if let Some(root) = maybe_custom_root { + if root.is_absolute() { + root + } else { + std::env::current_dir()?.join(root) + } + } else { + default + }; + assert!(root.is_absolute()); let gen_path = root.join("gen"); let deno_dir = Self { |