diff options
-rw-r--r-- | cli/deno_dir.rs | 13 | ||||
-rw-r--r-- | cli/disk_cache.rs | 9 | ||||
-rw-r--r-- | cli/http_cache.rs | 3 |
3 files changed, 22 insertions, 3 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 { diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs index f486e88af..828ca90ca 100644 --- a/cli/disk_cache.rs +++ b/cli/disk_cache.rs @@ -22,7 +22,9 @@ fn with_io_context<T: AsRef<str>>( } impl DiskCache { + /// `location` must be an absolute path. pub fn new(location: &Path) -> Self { + assert!(location.is_absolute()); Self { location: location.to_owned(), } @@ -211,7 +213,12 @@ mod tests { #[test] fn test_get_cache_filename_with_extension() { - let cache = DiskCache::new(&PathBuf::from("foo")); + let p = if cfg!(target_os = "windows") { + "C:\\foo" + } else { + "/foo" + }; + let cache = DiskCache::new(&PathBuf::from(p)); let mut test_cases = vec![ ( diff --git a/cli/http_cache.rs b/cli/http_cache.rs index 2771cb763..2a9882376 100644 --- a/cli/http_cache.rs +++ b/cli/http_cache.rs @@ -103,7 +103,10 @@ impl Metadata { impl HttpCache { /// Returns a new instance. + /// + /// `location` must be an absolute path. pub fn new(location: &Path) -> Self { + assert!(location.is_absolute()); Self { location: location.to_owned(), } |