From 0c0af67f89b610eb61e4f66a5dbf665474aa9383 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 25 Nov 2022 19:04:30 -0500 Subject: refactor: `DenoDir` - move to cache folder and make `root_dir` private (#16823) --- cli/args/mod.rs | 2 +- cli/cache/deno_dir.rs | 218 +++++++++++++++++++++++++++++++++++++++++++++ cli/cache/mod.rs | 2 + cli/deno_dir.rs | 176 ------------------------------------ cli/lsp/language_server.rs | 20 ++--- cli/lsp/registries.rs | 6 +- cli/main.rs | 3 +- cli/npm/cache.rs | 9 +- cli/proc_state.rs | 6 +- cli/tools/info.rs | 16 ++-- cli/tools/repl/mod.rs | 2 +- cli/tools/standalone.rs | 4 +- cli/tools/upgrade.rs | 16 ++-- cli/worker.rs | 4 +- 14 files changed, 257 insertions(+), 227 deletions(-) create mode 100644 cli/cache/deno_dir.rs delete mode 100644 cli/deno_dir.rs (limited to 'cli') diff --git a/cli/args/mod.rs b/cli/args/mod.rs index ae43bccaf..50a407ee3 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -44,7 +44,7 @@ use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; -use crate::deno_dir::DenoDir; +use crate::cache::DenoDir; use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::CacheSetting; use crate::fs_util; diff --git a/cli/cache/deno_dir.rs b/cli/cache/deno_dir.rs new file mode 100644 index 000000000..217658c15 --- /dev/null +++ b/cli/cache/deno_dir.rs @@ -0,0 +1,218 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +use super::DiskCache; + +use std::path::PathBuf; + +/// `DenoDir` serves as coordinator for multiple `DiskCache`s containing them +/// in single directory that can be controlled with `$DENO_DIR` env variable. +#[derive(Clone)] +pub struct DenoDir { + /// Example: /Users/rld/.deno/ + /// Note: This is not exposed in order to encourage using re-usable methods. + root: PathBuf, + /// Used by TsCompiler to cache compiler output. + pub gen_cache: DiskCache, +} + +impl DenoDir { + pub fn new(maybe_custom_root: Option) -> std::io::Result { + let root: PathBuf = if let Some(root) = maybe_custom_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 + // is not set, and keep a single one if it is. + cache_dir.join("deno") + } else if let Some(home_dir) = dirs::home_dir() { + // fallback path + home_dir.join(".deno") + } 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"); + + let deno_dir = Self { + root, + gen_cache: DiskCache::new(&gen_path), + }; + deno_dir.gen_cache.ensure_dir_exists(&gen_path)?; + + Ok(deno_dir) + } + + /// The root directory of the DENO_DIR for display purposes only. + pub fn root_path_for_display(&self) -> std::path::Display { + self.root.display() + } + + /// Path for the incremental cache used for formatting. + pub fn fmt_incremental_cache_db_file_path(&self) -> PathBuf { + // bump this version name to invalidate the entire cache + self.root.join("fmt_incremental_cache_v1") + } + + /// Path for the incremental cache used for linting. + pub fn lint_incremental_cache_db_file_path(&self) -> PathBuf { + // bump this version name to invalidate the entire cache + self.root.join("lint_incremental_cache_v1") + } + + /// Path for caching swc dependency analysis. + pub fn dep_analysis_db_file_path(&self) -> PathBuf { + // bump this version name to invalidate the entire cache + self.root.join("dep_analysis_cache_v1") + } + + /// Path for caching node analysis. + pub fn node_analysis_db_file_path(&self) -> PathBuf { + // bump this version name to invalidate the entire cache + self.root.join("node_analysis_cache_v1") + } + + /// Path for the cache used for type checking. + pub fn type_checking_cache_db_file_path(&self) -> PathBuf { + // bump this version name to invalidate the entire cache + self.root.join("check_cache_v1") + } + + /// Path to the registries cache, used for the lps. + pub fn registries_folder_path(&self) -> PathBuf { + self.root.join("registries") + } + + /// Path to the dependencies cache folder. + pub fn deps_folder_path(&self) -> PathBuf { + self.root.join("deps") + } + + /// Path to the origin data cache folder. + pub fn origin_data_folder_path(&self) -> PathBuf { + // TODO(@crowlKats): change to origin_data for 2.0 + self.root.join("location_data") + } + + /// File used for the upgrade checker. + pub fn upgrade_check_file_path(&self) -> PathBuf { + self.root.join("latest.txt") + } + + /// Folder used for the npm cache. + pub fn npm_folder_path(&self) -> PathBuf { + self.root.join("npm") + } + + /// Path used for the REPL history file. + pub fn repl_history_file_path(&self) -> PathBuf { + self.root.join("deno_history.txt") + } + + /// Folder path used for downloading new versions of deno. + pub fn dl_folder_path(&self) -> PathBuf { + self.root.join("dl") + } +} + +/// To avoid the poorly managed dirs crate +#[cfg(not(windows))] +mod dirs { + use std::path::PathBuf; + + pub fn cache_dir() -> Option { + if cfg!(target_os = "macos") { + home_dir().map(|h| h.join("Library/Caches")) + } else { + std::env::var_os("XDG_CACHE_HOME") + .map(PathBuf::from) + .or_else(|| home_dir().map(|h| h.join(".cache"))) + } + } + + pub fn home_dir() -> Option { + std::env::var_os("HOME") + .and_then(|h| if h.is_empty() { None } else { Some(h) }) + .or_else(|| { + // TODO(bartlomieju): + #[allow(clippy::undocumented_unsafe_blocks)] + unsafe { + fallback() + } + }) + .map(PathBuf::from) + } + + // This piece of code is taken from the deprecated home_dir() function in Rust's standard library: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/os.rs#L579 + // The same code is used by the dirs crate + unsafe fn fallback() -> Option { + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { + n if n < 0 => 512_usize, + n => n as usize, + }; + let mut buf = Vec::with_capacity(amt); + let mut passwd: libc::passwd = std::mem::zeroed(); + let mut result = std::ptr::null_mut(); + match libc::getpwuid_r( + libc::getuid(), + &mut passwd, + buf.as_mut_ptr(), + buf.capacity(), + &mut result, + ) { + 0 if !result.is_null() => { + let ptr = passwd.pw_dir as *const _; + let bytes = std::ffi::CStr::from_ptr(ptr).to_bytes().to_vec(); + Some(std::os::unix::ffi::OsStringExt::from_vec(bytes)) + } + _ => None, + } + } +} + +/// To avoid the poorly managed dirs crate +// Copied from +// https://github.com/dirs-dev/dirs-sys-rs/blob/ec7cee0b3e8685573d847f0a0f60aae3d9e07fa2/src/lib.rs#L140-L164 +// MIT license. Copyright (c) 2018-2019 dirs-rs contributors +#[cfg(windows)] +mod dirs { + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + use std::path::PathBuf; + use winapi::shared::winerror; + use winapi::um::{combaseapi, knownfolders, shlobj, shtypes, winbase, winnt}; + + fn known_folder(folder_id: shtypes::REFKNOWNFOLDERID) -> Option { + // SAFETY: winapi calls + unsafe { + let mut path_ptr: winnt::PWSTR = std::ptr::null_mut(); + let result = shlobj::SHGetKnownFolderPath( + folder_id, + 0, + std::ptr::null_mut(), + &mut path_ptr, + ); + if result == winerror::S_OK { + let len = winbase::lstrlenW(path_ptr) as usize; + let path = std::slice::from_raw_parts(path_ptr, len); + let ostr: OsString = OsStringExt::from_wide(path); + combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); + Some(PathBuf::from(ostr)) + } else { + None + } + } + } + + pub fn cache_dir() -> Option { + known_folder(&knownfolders::FOLDERID_LocalAppData) + } + + pub fn home_dir() -> Option { + known_folder(&knownfolders::FOLDERID_Profile) + } +} diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 16390013a..cf9a4c441 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -16,6 +16,7 @@ use std::sync::Arc; mod check; mod common; +mod deno_dir; mod disk_cache; mod emit; mod incremental; @@ -24,6 +25,7 @@ mod parsed_source; pub use check::TypeCheckCache; pub use common::FastInsecureHasher; +pub use deno_dir::DenoDir; pub use disk_cache::DiskCache; pub use emit::EmitCache; pub use incremental::IncrementalCache; diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs deleted file mode 100644 index c0d116a6a..000000000 --- a/cli/deno_dir.rs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. - -use crate::cache::DiskCache; - -use std::path::PathBuf; - -/// `DenoDir` serves as coordinator for multiple `DiskCache`s containing them -/// in single directory that can be controlled with `$DENO_DIR` env variable. -#[derive(Clone)] -pub struct DenoDir { - /// Example: /Users/rld/.deno/ - pub root: PathBuf, - /// Used by TsCompiler to cache compiler output. - pub gen_cache: DiskCache, -} - -impl DenoDir { - pub fn new(maybe_custom_root: Option) -> std::io::Result { - let root: PathBuf = if let Some(root) = maybe_custom_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 - // is not set, and keep a single one if it is. - cache_dir.join("deno") - } else if let Some(home_dir) = dirs::home_dir() { - // fallback path - home_dir.join(".deno") - } 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"); - - let deno_dir = Self { - root, - gen_cache: DiskCache::new(&gen_path), - }; - deno_dir.gen_cache.ensure_dir_exists(&gen_path)?; - - Ok(deno_dir) - } - - /// Path for the incremental cache used for formatting. - pub fn fmt_incremental_cache_db_file_path(&self) -> PathBuf { - // bump this version name to invalidate the entire cache - self.root.join("fmt_incremental_cache_v1") - } - - /// Path for the incremental cache used for linting. - pub fn lint_incremental_cache_db_file_path(&self) -> PathBuf { - // bump this version name to invalidate the entire cache - self.root.join("lint_incremental_cache_v1") - } - - /// Path for caching swc dependency analysis. - pub fn dep_analysis_db_file_path(&self) -> PathBuf { - // bump this version name to invalidate the entire cache - self.root.join("dep_analysis_cache_v1") - } - - /// Path for caching node analysis. - pub fn node_analysis_db_file_path(&self) -> PathBuf { - // bump this version name to invalidate the entire cache - self.root.join("node_analysis_cache_v1") - } - - /// Path for the cache used for type checking. - pub fn type_checking_cache_db_file_path(&self) -> PathBuf { - // bump this version name to invalidate the entire cache - self.root.join("check_cache_v1") - } -} - -/// To avoid the poorly managed dirs crate -#[cfg(not(windows))] -mod dirs { - use std::path::PathBuf; - - pub fn cache_dir() -> Option { - if cfg!(target_os = "macos") { - home_dir().map(|h| h.join("Library/Caches")) - } else { - std::env::var_os("XDG_CACHE_HOME") - .map(PathBuf::from) - .or_else(|| home_dir().map(|h| h.join(".cache"))) - } - } - - pub fn home_dir() -> Option { - std::env::var_os("HOME") - .and_then(|h| if h.is_empty() { None } else { Some(h) }) - .or_else(|| { - // TODO(bartlomieju): - #[allow(clippy::undocumented_unsafe_blocks)] - unsafe { - fallback() - } - }) - .map(PathBuf::from) - } - - // This piece of code is taken from the deprecated home_dir() function in Rust's standard library: https://github.com/rust-lang/rust/blob/master/src/libstd/sys/unix/os.rs#L579 - // The same code is used by the dirs crate - unsafe fn fallback() -> Option { - let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { - n if n < 0 => 512_usize, - n => n as usize, - }; - let mut buf = Vec::with_capacity(amt); - let mut passwd: libc::passwd = std::mem::zeroed(); - let mut result = std::ptr::null_mut(); - match libc::getpwuid_r( - libc::getuid(), - &mut passwd, - buf.as_mut_ptr(), - buf.capacity(), - &mut result, - ) { - 0 if !result.is_null() => { - let ptr = passwd.pw_dir as *const _; - let bytes = std::ffi::CStr::from_ptr(ptr).to_bytes().to_vec(); - Some(std::os::unix::ffi::OsStringExt::from_vec(bytes)) - } - _ => None, - } - } -} - -/// To avoid the poorly managed dirs crate -// Copied from -// https://github.com/dirs-dev/dirs-sys-rs/blob/ec7cee0b3e8685573d847f0a0f60aae3d9e07fa2/src/lib.rs#L140-L164 -// MIT license. Copyright (c) 2018-2019 dirs-rs contributors -#[cfg(windows)] -mod dirs { - use std::ffi::OsString; - use std::os::windows::ffi::OsStringExt; - use std::path::PathBuf; - use winapi::shared::winerror; - use winapi::um::{combaseapi, knownfolders, shlobj, shtypes, winbase, winnt}; - - fn known_folder(folder_id: shtypes::REFKNOWNFOLDERID) -> Option { - // SAFETY: winapi calls - unsafe { - let mut path_ptr: winnt::PWSTR = std::ptr::null_mut(); - let result = shlobj::SHGetKnownFolderPath( - folder_id, - 0, - std::ptr::null_mut(), - &mut path_ptr, - ); - if result == winerror::S_OK { - let len = winbase::lstrlenW(path_ptr) as usize; - let path = std::slice::from_raw_parts(path_ptr, len); - let ostr: OsString = OsStringExt::from_wide(path); - combaseapi::CoTaskMemFree(path_ptr as *mut winapi::ctypes::c_void); - Some(PathBuf::from(ostr)) - } else { - None - } - } - } - - pub fn cache_dir() -> Option { - known_folder(&knownfolders::FOLDERID_LocalAppData) - } - - pub fn home_dir() -> Option { - known_folder(&knownfolders::FOLDERID_Profile) - } -} diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 4595d2146..4e7c4b240 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -63,8 +63,7 @@ use crate::args::Flags; use crate::args::FmtConfig; use crate::args::LintConfig; use crate::args::TsConfig; -use crate::deno_dir; -use crate::deno_dir::DenoDir; +use crate::cache::DenoDir; use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::get_source_from_data_url; use crate::file_fetcher::CacheSetting; @@ -80,9 +79,6 @@ use crate::progress_bar::ProgressBar; use crate::tools::fmt::format_file; use crate::tools::fmt::format_parsed_source; -pub const REGISTRIES_PATH: &str = "registries"; -const CACHE_PATH: &str = "deps"; - #[derive(Debug, Clone)] pub struct LanguageServer(Arc>); @@ -267,14 +263,14 @@ fn create_lsp_npm_resolver( impl Inner { fn new(client: Client) -> Self { let maybe_custom_root = env::var("DENO_DIR").map(String::into).ok(); - let dir = deno_dir::DenoDir::new(maybe_custom_root) - .expect("could not access DENO_DIR"); - let module_registries_location = dir.root.join(REGISTRIES_PATH); + let dir = + DenoDir::new(maybe_custom_root).expect("could not access DENO_DIR"); + let module_registries_location = dir.registries_folder_path(); let http_client = HttpClient::new(None, None).unwrap(); let module_registries = ModuleRegistry::new(&module_registries_location, http_client.clone()) .unwrap(); - let location = dir.root.join(CACHE_PATH); + let location = dir.deps_folder_path(); let documents = Documents::new(&location); let cache_metadata = cache::CacheMetadata::new(&location); let performance = Arc::new(Performance::default()); @@ -521,7 +517,7 @@ impl Inner { let maybe_custom_root = new_cache_path .clone() .or_else(|| env::var("DENO_DIR").map(String::into).ok()); - let dir = deno_dir::DenoDir::new(maybe_custom_root)?; + let dir = DenoDir::new(maybe_custom_root)?; let workspace_settings = self.config.get_workspace_settings(); let maybe_root_path = self .config @@ -537,13 +533,13 @@ impl Inner { root_cert_store, workspace_settings.unsafely_ignore_certificate_errors, )?; - let module_registries_location = dir.root.join(REGISTRIES_PATH); + let module_registries_location = dir.registries_folder_path(); self.module_registries = ModuleRegistry::new(&module_registries_location, client.clone())?; self.module_registries_location = module_registries_location; self.npm_resolver = create_lsp_npm_resolver(&dir, client); // update the cache path - let location = dir.root.join(CACHE_PATH); + let location = dir.deps_folder_path(); self.documents.set_location(&location); self.cache_metadata.set_location(&location); self.maybe_cache_path = new_cache_path; diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 6fd48d8b9..43500e697 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -12,7 +12,7 @@ use super::path_to_regex::StringOrNumber; use super::path_to_regex::StringOrVec; use super::path_to_regex::Token; -use crate::deno_dir; +use crate::cache::DenoDir; use crate::file_fetcher::CacheSetting; use crate::file_fetcher::FileFetcher; use crate::http_cache::HttpCache; @@ -422,8 +422,8 @@ impl Default for ModuleRegistry { // This only gets used when creating the tsc runtime and for testing, and so // it shouldn't ever actually access the DenoDir, so it doesn't support a // custom root. - let dir = deno_dir::DenoDir::new(None).unwrap(); - let location = dir.root.join("registries"); + let dir = DenoDir::new(None).unwrap(); + let location = dir.registries_folder_path(); let http_client = HttpClient::new(None, None).unwrap(); Self::new(&location, http_client).unwrap() } diff --git a/cli/main.rs b/cli/main.rs index e42c6325e..4eaaeb755 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -4,7 +4,6 @@ mod args; mod auth_tokens; mod cache; mod checksum; -mod deno_dir; mod deno_std; mod diff; mod display; @@ -706,7 +705,7 @@ To grant permissions, set them before the script argument. For example: // Run a background task that checks for available upgrades. If an earlier // run of this background task found a new version of Deno. - tools::upgrade::check_for_upgrades(ps.dir.root.clone()); + tools::upgrade::check_for_upgrades(ps.dir.upgrade_check_file_path()); let main_module = if NpmPackageReference::from_str(&run_flags.script).is_ok() { diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs index ce2208db7..b2c842309 100644 --- a/cli/npm/cache.rs +++ b/cli/npm/cache.rs @@ -11,7 +11,7 @@ use deno_core::error::custom_error; use deno_core::error::AnyError; use deno_core::url::Url; -use crate::deno_dir::DenoDir; +use crate::cache::DenoDir; use crate::file_fetcher::CacheSetting; use crate::fs_util; use crate::http_util::HttpClient; @@ -146,7 +146,7 @@ impl Default for ReadonlyNpmCache { // This only gets used when creating the tsc runtime and for testing, and so // it shouldn't ever actually access the DenoDir, so it doesn't support a // custom root. - Self::from_deno_dir(&crate::deno_dir::DenoDir::new(None).unwrap()) + Self::from_deno_dir(&DenoDir::new(None).unwrap()) } } @@ -173,7 +173,7 @@ impl ReadonlyNpmCache { } pub fn from_deno_dir(dir: &DenoDir) -> Self { - Self::new(dir.root.join("npm")) + Self::new(dir.npm_folder_path()) } pub fn package_folder_for_id( @@ -510,7 +510,8 @@ mod test { #[test] fn should_get_package_folder() { - let root_dir = crate::deno_dir::DenoDir::new(None).unwrap().root; + let deno_dir = crate::cache::DenoDir::new(None).unwrap(); + let root_dir = deno_dir.npm_folder_path(); let cache = ReadonlyNpmCache::new(root_dir.clone()); let registry_url = Url::parse("https://registry.npmjs.org/").unwrap(); diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 019b6e447..dc80ca8db 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -8,12 +8,12 @@ use crate::args::TsConfigType; use crate::args::TsTypeLib; use crate::args::TypeCheckMode; use crate::cache; +use crate::cache::DenoDir; use crate::cache::EmitCache; use crate::cache::FastInsecureHasher; use crate::cache::NodeAnalysisCache; use crate::cache::ParsedSourceCache; use crate::cache::TypeCheckCache; -use crate::deno_dir; use crate::emit::emit_parsed_source; use crate::file_fetcher::FileFetcher; use crate::graph_util::graph_lock_or_exit; @@ -73,7 +73,7 @@ use std::sync::Arc; pub struct ProcState(Arc); pub struct Inner { - pub dir: deno_dir::DenoDir, + pub dir: DenoDir, pub file_fetcher: FileFetcher, pub options: Arc, pub emit_cache: EmitCache, @@ -152,7 +152,7 @@ impl ProcState { let shared_array_buffer_store = SharedArrayBufferStore::default(); let compiled_wasm_module_store = CompiledWasmModuleStore::default(); let dir = cli_options.resolve_deno_dir()?; - let deps_cache_location = dir.root.join("deps"); + let deps_cache_location = dir.deps_folder_path(); let http_cache = http_cache::HttpCache::new(&deps_cache_location); let root_cert_store = cli_options.resolve_root_cert_store()?; let cache_usage = cli_options.cache_setting(); diff --git a/cli/tools/info.rs b/cli/tools/info.rs index f718d8e52..38aa40a5e 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -22,7 +22,6 @@ use crate::args::Flags; use crate::args::InfoFlags; use crate::checksum; use crate::display; -use crate::lsp; use crate::npm::NpmPackageId; use crate::npm::NpmPackageReference; use crate::npm::NpmPackageReq; @@ -58,13 +57,12 @@ fn print_cache_info( json: bool, location: Option<&deno_core::url::Url>, ) -> Result<(), AnyError> { - let deno_dir = &state.dir.root; + let deno_dir = &state.dir.root_path_for_display(); let modules_cache = &state.file_fetcher.get_http_cache_location(); let npm_cache = &state.npm_cache.as_readonly().get_cache_location(); let typescript_cache = &state.dir.gen_cache.location; - let registry_cache = - &state.dir.root.join(lsp::language_server::REGISTRIES_PATH); - let mut origin_dir = state.dir.root.join("location_data"); + let registry_cache = &state.dir.registries_folder_path(); + let mut origin_dir = state.dir.origin_data_folder_path(); if let Some(location) = &location { origin_dir = @@ -75,7 +73,7 @@ fn print_cache_info( if json { let mut output = json!({ - "denoDir": deno_dir, + "denoDir": deno_dir.to_string(), "modulesCache": modules_cache, "npmCache": npm_cache, "typescriptCache": typescript_cache, @@ -89,11 +87,7 @@ fn print_cache_info( display::write_json_to_stdout(&output) } else { - println!( - "{} {}", - colors::bold("DENO_DIR location:"), - deno_dir.display() - ); + println!("{} {}", colors::bold("DENO_DIR location:"), deno_dir); println!( "{} {}", colors::bold("Remote modules cache:"), diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 597b3ff5f..1cdb17ab1 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -89,7 +89,7 @@ pub async fn run( sync_sender: rustyline_channel.0, }; - let history_file_path = ps.dir.root.join("deno_history.txt"); + let history_file_path = ps.dir.repl_history_file_path(); let editor = ReplEditor::new(helper, history_file_path)?; if let Some(eval_files) = maybe_eval_files { diff --git a/cli/tools/standalone.rs b/cli/tools/standalone.rs index 494c2f476..f173103cb 100644 --- a/cli/tools/standalone.rs +++ b/cli/tools/standalone.rs @@ -5,7 +5,7 @@ use crate::args::DenoSubcommand; use crate::args::Flags; use crate::args::RunFlags; use crate::args::TypeCheckMode; -use crate::deno_dir::DenoDir; +use crate::cache::DenoDir; use crate::fs_util; use crate::standalone::Metadata; use crate::standalone::MAGIC_TRAILER; @@ -50,7 +50,7 @@ pub async fn get_base_binary( format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name) }; - let download_directory = deno_dir.root.join("dl"); + let download_directory = deno_dir.dl_folder_path(); let binary_path = download_directory.join(&binary_path_suffix); if !binary_path.exists() { diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index f39823600..c5f469835 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -31,7 +31,6 @@ const RELEASE_URL: &str = "https://github.com/denoland/deno/releases"; // How often query server for new version. In hours. const UPGRADE_CHECK_INTERVAL: i64 = 24; -const UPGRADE_CHECK_FILE_NAME: &str = "latest.txt"; const UPGRADE_CHECK_FETCH_DELAY: Duration = Duration::from_millis(500); @@ -47,14 +46,14 @@ trait UpdateCheckerEnvironment: Clone + Send + Sync { #[derive(Clone)] struct RealUpdateCheckerEnvironment { - cache_dir: PathBuf, + cache_file_path: PathBuf, current_time: chrono::DateTime, } impl RealUpdateCheckerEnvironment { - pub fn new(cache_dir: PathBuf) -> Self { + pub fn new(cache_file_path: PathBuf) -> Self { Self { - cache_dir, + cache_file_path, // cache the current time current_time: chrono::Utc::now(), } @@ -79,12 +78,11 @@ impl UpdateCheckerEnvironment for RealUpdateCheckerEnvironment { } fn read_check_file(&self) -> String { - std::fs::read_to_string(self.cache_dir.join(UPGRADE_CHECK_FILE_NAME)) - .unwrap_or_default() + std::fs::read_to_string(&self.cache_file_path).unwrap_or_default() } fn write_check_file(&self, text: &str) { - let _ = std::fs::write(self.cache_dir.join(UPGRADE_CHECK_FILE_NAME), text); + let _ = std::fs::write(&self.cache_file_path, text); } fn current_time(&self) -> chrono::DateTime { @@ -160,12 +158,12 @@ impl UpdateChecker { } } -pub fn check_for_upgrades(cache_dir: PathBuf) { +pub fn check_for_upgrades(cache_file_path: PathBuf) { if env::var("DENO_NO_UPDATE_CHECK").is_ok() { return; } - let env = RealUpdateCheckerEnvironment::new(cache_dir); + let env = RealUpdateCheckerEnvironment::new(cache_file_path); let update_checker = UpdateChecker::new(env); if update_checker.should_check_for_new_version() { diff --git a/cli/worker.rs b/cli/worker.rs index d06864634..fb021b614 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -483,9 +483,7 @@ async fn create_main_worker_internal( let maybe_storage_key = ps.options.resolve_storage_key(&main_module); let origin_storage_dir = maybe_storage_key.as_ref().map(|key| { ps.dir - .root - // TODO(@crowlKats): change to origin_data for 2.0 - .join("location_data") + .origin_data_folder_path() .join(checksum::gen(&[key.as_bytes()])) }); let cache_storage_dir = maybe_storage_key.map(|key| { -- cgit v1.2.3