summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-11-10 09:00:44 +0530
committerGitHub <noreply@github.com>2024-11-10 09:00:44 +0530
commitce778a947e70616b435920fd6f1fc28c4b2a78d1 (patch)
treec7e5f4ee47f94f2279e745b1825959f82a66a22d /cli/tools
parent01de3317424cc870913dbe85ff3b80eadaf8cc87 (diff)
Revert "perf(upgrade): cache downloaded binaries in DENO_DIR" (#26799)
Reverts denoland/deno#26108 Tests are flaky on main https://github.com/denoland/deno/commit/01de3317424cc870913dbe85ff3b80eadaf8cc87
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/upgrade.rs69
1 files changed, 55 insertions, 14 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs
index ed1bc06cf..77a9f72b8 100644
--- a/cli/tools/upgrade.rs
+++ b/cli/tools/upgrade.rs
@@ -6,14 +6,13 @@ use crate::args::Flags;
use crate::args::UpgradeFlags;
use crate::args::UPGRADE_USAGE;
use crate::colors;
-use crate::download_deno_binary::archive_name;
-use crate::download_deno_binary::download_deno_binary;
-use crate::download_deno_binary::BinaryKind;
use crate::factory::CliFactory;
use crate::http_util::HttpClient;
use crate::http_util::HttpClientProvider;
use crate::shared::ReleaseChannel;
use crate::util::archive;
+use crate::util::progress_bar::ProgressBar;
+use crate::util::progress_bar::ProgressBarStyle;
use crate::version;
use async_trait::async_trait;
@@ -35,8 +34,12 @@ use std::process::Command;
use std::sync::Arc;
use std::time::Duration;
-static ARCHIVE_NAME: Lazy<String> =
- Lazy::new(|| archive_name(BinaryKind::Deno, env!("TARGET")));
+const RELEASE_URL: &str = "https://github.com/denoland/deno/releases";
+const CANARY_URL: &str = "https://dl.deno.land/canary";
+const DL_RELEASE_URL: &str = "https://dl.deno.land/release";
+
+pub static ARCHIVE_NAME: Lazy<String> =
+ Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
// How often query server for new version. In hours.
const UPGRADE_CHECK_INTERVAL: i64 = 24;
@@ -529,17 +532,13 @@ pub async fn upgrade(
return Ok(());
};
- let binary_path = download_deno_binary(
- http_client_provider,
- factory.deno_dir()?,
- BinaryKind::Deno,
- env!("TARGET"),
+ let download_url = get_download_url(
&selected_version_to_upgrade.version_or_hash,
requested_version.release_channel(),
- )
- .await?;
-
- let Ok(archive_data) = tokio::fs::read(&binary_path).await else {
+ )?;
+ log::info!("{}", colors::gray(format!("Downloading {}", &download_url)));
+ let Some(archive_data) = download_package(&client, download_url).await?
+ else {
log::error!("Download could not be found, aborting");
std::process::exit(1)
};
@@ -882,6 +881,48 @@ fn base_upgrade_url() -> Cow<'static, str> {
}
}
+fn get_download_url(
+ version: &str,
+ release_channel: ReleaseChannel,
+) -> Result<Url, AnyError> {
+ let download_url = match release_channel {
+ ReleaseChannel::Stable => {
+ format!("{}/download/v{}/{}", RELEASE_URL, version, *ARCHIVE_NAME)
+ }
+ ReleaseChannel::Rc => {
+ format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME)
+ }
+ ReleaseChannel::Canary => {
+ format!("{}/{}/{}", CANARY_URL, version, *ARCHIVE_NAME)
+ }
+ ReleaseChannel::Lts => {
+ format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME)
+ }
+ };
+
+ Url::parse(&download_url).with_context(|| {
+ format!(
+ "Failed to parse URL to download new release: {}",
+ download_url
+ )
+ })
+}
+
+async fn download_package(
+ client: &HttpClient,
+ download_url: Url,
+) -> Result<Option<Vec<u8>>, AnyError> {
+ let progress_bar = ProgressBar::new(ProgressBarStyle::DownloadBars);
+ // provide an empty string here in order to prefer the downloading
+ // text above which will stay alive after the progress bars are complete
+ let progress = progress_bar.update("");
+ let maybe_bytes = client
+ .download_with_progress_and_retries(download_url.clone(), None, &progress)
+ .await
+ .with_context(|| format!("Failed downloading {download_url}. The version you requested may not have been built for the current architecture."))?;
+ Ok(maybe_bytes)
+}
+
fn replace_exe(from: &Path, to: &Path) -> Result<(), std::io::Error> {
if cfg!(windows) {
// On windows you cannot replace the currently running executable.