diff options
author | Lorran Rosa <rosalorran98@gmail.com> | 2020-04-03 23:43:49 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 22:43:49 -0400 |
commit | b017409dcdbcaa5d3522f0efb191522240a6e757 (patch) | |
tree | 2d7ac4b002fca5139e409993e620a259357161fa /cli/disk_cache.rs | |
parent | f5274072870558973f70b7fad30c078647790d6c (diff) |
on init create disk_cache directory if it doesn't already exists (#4617)
Diffstat (limited to 'cli/disk_cache.rs')
-rw-r--r-- | cli/disk_cache.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs index bfef8ab64..51c9d8612 100644 --- a/cli/disk_cache.rs +++ b/cli/disk_cache.rs @@ -22,7 +22,9 @@ fn with_io_context<T: AsRef<str>>( impl DiskCache { pub fn new(location: &Path) -> Self { - // TODO: ensure that 'location' is a directory + if !&location.is_dir() { + fs::create_dir_all(&location).ok(); + } Self { location: location.to_owned(), } @@ -131,6 +133,28 @@ impl DiskCache { #[cfg(test)] mod tests { use super::*; + use tempfile::TempDir; + + #[test] + fn test_create_cache_if_dir_exits() { + let cache_location = TempDir::new().unwrap(); + let mut cache_path = cache_location.path().to_owned(); + cache_path.push("foo"); + DiskCache::new(&cache_path); + assert!(cache_path.is_dir()); + } + + #[test] + fn test_create_cache_if_dir_not_exits() { + let cache_location = if cfg!(target_os = "windows") { + PathBuf::from(r"C:\deno_dir\foo") + } else { + PathBuf::from("~/deno_dir/foo") + }; + assert_eq!(cache_location.is_dir(), false); + DiskCache::new(&cache_location); + assert_eq!(cache_location.is_dir(), true); + } #[test] fn test_get_cache_filename() { |