0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

on init create disk_cache directory if it doesn't already exists (#4617)

This commit is contained in:
Lorran Rosa 2020-04-03 23:43:49 -03:00 committed by GitHub
parent f527407287
commit b017409dcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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() {