@@ -6,13 +6,14 @@ use crate::args::Flags;
66use crate :: args:: UpgradeFlags ;
77use crate :: args:: UPGRADE_USAGE ;
88use crate :: colors;
9+ use crate :: download_deno_binary:: archive_name;
10+ use crate :: download_deno_binary:: download_deno_binary;
11+ use crate :: download_deno_binary:: BinaryKind ;
912use crate :: factory:: CliFactory ;
1013use crate :: http_util:: HttpClient ;
1114use crate :: http_util:: HttpClientProvider ;
1215use crate :: shared:: ReleaseChannel ;
1316use crate :: util:: archive;
14- use crate :: util:: progress_bar:: ProgressBar ;
15- use crate :: util:: progress_bar:: ProgressBarStyle ;
1617use crate :: version;
1718
1819use async_trait:: async_trait;
@@ -34,12 +35,8 @@ use std::process::Command;
3435use std:: sync:: Arc ;
3536use std:: time:: Duration ;
3637
37- const RELEASE_URL : & str = "https://github.com/denoland/deno/releases" ;
38- const CANARY_URL : & str = "https://dl.deno.land/canary" ;
39- const DL_RELEASE_URL : & str = "https://dl.deno.land/release" ;
40-
41- pub static ARCHIVE_NAME : Lazy < String > =
42- Lazy :: new ( || format ! ( "deno-{}.zip" , env!( "TARGET" ) ) ) ;
38+ static ARCHIVE_NAME : Lazy < String > =
39+ Lazy :: new ( || archive_name ( BinaryKind :: Deno , env ! ( "TARGET" ) ) ) ;
4340
4441// How often query server for new version. In hours.
4542const UPGRADE_CHECK_INTERVAL : i64 = 24 ;
@@ -532,13 +529,17 @@ pub async fn upgrade(
532529 return Ok ( ( ) ) ;
533530 } ;
534531
535- let download_url = get_download_url (
532+ let binary_path = download_deno_binary (
533+ http_client_provider,
534+ factory. deno_dir ( ) ?,
535+ BinaryKind :: Deno ,
536+ env ! ( "TARGET" ) ,
536537 & selected_version_to_upgrade. version_or_hash ,
537538 requested_version. release_channel ( ) ,
538- ) ? ;
539- log :: info! ( "{}" , colors :: gray ( format! ( "Downloading {}" , & download_url ) ) ) ;
540- let Some ( archive_data ) = download_package ( & client , download_url ) . await ?
541- else {
539+ )
540+ . await ? ;
541+
542+ let Ok ( archive_data ) = tokio :: fs :: read ( & binary_path ) . await else {
542543 log:: error!( "Download could not be found, aborting" ) ;
543544 std:: process:: exit ( 1 )
544545 } ;
@@ -881,48 +882,6 @@ fn base_upgrade_url() -> Cow<'static, str> {
881882 }
882883}
883884
884- fn get_download_url (
885- version : & str ,
886- release_channel : ReleaseChannel ,
887- ) -> Result < Url , AnyError > {
888- let download_url = match release_channel {
889- ReleaseChannel :: Stable => {
890- format ! ( "{}/download/v{}/{}" , RELEASE_URL , version, * ARCHIVE_NAME )
891- }
892- ReleaseChannel :: Rc => {
893- format ! ( "{}/v{}/{}" , DL_RELEASE_URL , version, * ARCHIVE_NAME )
894- }
895- ReleaseChannel :: Canary => {
896- format ! ( "{}/{}/{}" , CANARY_URL , version, * ARCHIVE_NAME )
897- }
898- ReleaseChannel :: Lts => {
899- format ! ( "{}/v{}/{}" , DL_RELEASE_URL , version, * ARCHIVE_NAME )
900- }
901- } ;
902-
903- Url :: parse ( & download_url) . with_context ( || {
904- format ! (
905- "Failed to parse URL to download new release: {}" ,
906- download_url
907- )
908- } )
909- }
910-
911- async fn download_package (
912- client : & HttpClient ,
913- download_url : Url ,
914- ) -> Result < Option < Vec < u8 > > , AnyError > {
915- let progress_bar = ProgressBar :: new ( ProgressBarStyle :: DownloadBars ) ;
916- // provide an empty string here in order to prefer the downloading
917- // text above which will stay alive after the progress bars are complete
918- let progress = progress_bar. update ( "" ) ;
919- let maybe_bytes = client
920- . download_with_progress_and_retries ( download_url. clone ( ) , None , & progress)
921- . await
922- . with_context ( || format ! ( "Failed downloading {download_url}. The version you requested may not have been built for the current architecture." ) ) ?;
923- Ok ( maybe_bytes)
924- }
925-
926885fn replace_exe ( from : & Path , to : & Path ) -> Result < ( ) , std:: io:: Error > {
927886 if cfg ! ( windows) {
928887 // On windows you cannot replace the currently running executable.
0 commit comments