@@ -29,7 +29,14 @@ pub struct CachedFetchResponse {
2929}
3030
3131/// Download a file with retry logic and progress bar
32- pub async fn download_file ( url : & str , target_path : & AbsolutePath ) -> Result < ( ) , Error > {
32+ ///
33+ /// The `message` parameter is displayed to the user to indicate what is being downloaded
34+ /// (e.g., "Downloading Node.js v22.13.1").
35+ pub async fn download_file (
36+ url : & str ,
37+ target_path : & AbsolutePath ,
38+ message : & str ,
39+ ) -> Result < ( ) , Error > {
3340 tracing:: debug!( "Downloading {url} to {target_path:?}" ) ;
3441
3542 let response = ( || async { reqwest:: get ( url) . await ?. error_for_status ( ) } )
@@ -45,13 +52,6 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
4552 // Get Content-Length for progress bar
4653 let total_size = response. content_length ( ) ;
4754
48- // Extract filename for display
49- let filename = target_path
50- . as_path ( )
51- . file_name ( )
52- . map ( |s| s. to_string_lossy ( ) . to_string ( ) )
53- . unwrap_or_else ( || "file" . to_string ( ) ) ;
54-
5555 // Create progress bar (only in TTY and not in CI)
5656 let is_ci = std:: env:: var ( "CI" ) . is_ok ( ) ;
5757 let progress = if std:: io:: stderr ( ) . is_terminal ( ) && !is_ci {
@@ -61,7 +61,7 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
6161 pb. set_style (
6262 ProgressStyle :: default_bar ( )
6363 . template (
64- "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] \
64+ "{msg} \n { spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] \
6565 {bytes}/{total_bytes} ({bytes_per_sec}, {eta})",
6666 )
6767 . expect ( "valid progress bar template" )
@@ -74,15 +74,15 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
7474 pb. set_style (
7575 ProgressStyle :: default_spinner ( )
7676 . template (
77- "{spinner:.green} [{elapsed_precise}] {bytes} ({bytes_per_sec}) {msg} " ,
77+ "{msg} \n { spinner:.green} [{elapsed_precise}] {bytes} ({bytes_per_sec})" ,
7878 )
7979 . expect ( "valid spinner template" ) ,
8080 ) ;
8181 pb. enable_steady_tick ( Duration :: from_millis ( 100 ) ) ;
8282 pb
8383 }
8484 } ;
85- pb. set_message ( format ! ( "Downloading {filename}" ) ) ;
85+ pb. set_message ( message . to_string ( ) ) ;
8686 Some ( pb)
8787 } else {
8888 None
@@ -103,7 +103,7 @@ pub async fn download_file(url: &str, target_path: &AbsolutePath) -> Result<(),
103103 file. flush ( ) . await ?;
104104
105105 if let Some ( pb) = progress {
106- pb. finish_with_message ( format ! ( "Downloaded {filename}" ) ) ;
106+ pb. finish_and_clear ( ) ;
107107 }
108108
109109 tracing:: debug!( "Download completed: {target_path:?}" ) ;
0 commit comments