refactor: DenoDir - move to cache folder and make root_dir private (#16823)

This commit is contained in:
David Sherret 2022-11-25 19:04:30 -05:00 committed by GitHub
parent e0dd275935
commit 0c0af67f89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 83 additions and 53 deletions

View file

@ -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:"),

View file

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

View file

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

View file

@ -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<chrono::Utc>,
}
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<chrono::Utc> {
@ -160,12 +158,12 @@ impl<TEnvironment: UpdateCheckerEnvironment> UpdateChecker<TEnvironment> {
}
}
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() {