@@ -8,7 +8,7 @@ use std::ops::{BitAnd, BitAndAssign};
88use std:: path:: { Path , PathBuf } ;
99use std:: process:: ExitStatus ;
1010
11- use anyhow:: { Context , Result , anyhow, bail } ;
11+ use anyhow:: { Context , Result , anyhow} ;
1212use retry:: delay:: { Fibonacci , jitter} ;
1313use retry:: { OperationResult , retry} ;
1414use tracing:: { debug, info, warn} ;
@@ -444,40 +444,13 @@ pub(crate) fn delete_dir_contents_following_links(dir_path: &Path) {
444444 }
445445}
446446
447- pub ( crate ) struct FileReaderWithProgress {
448- fh : BufReader < File > ,
449- nbytes : u64 ,
450- }
451-
452- impl FileReaderWithProgress {
453- pub ( crate ) fn new_file ( path : & Path ) -> Result < Self > {
454- let fh = match File :: open ( path) {
455- Ok ( fh) => fh,
456- Err ( _) => {
457- bail ! ( RustupError :: ReadingFile {
458- name: "downloaded" ,
459- path: path. to_path_buf( ) ,
460- } )
461- }
462- } ;
463-
464- // Inform the tracker of the file size
465- Ok ( FileReaderWithProgress {
466- fh : BufReader :: with_capacity ( 8 * 1024 * 1024 , fh) ,
467- nbytes : 0 ,
468- } )
469- }
470- }
471-
472- impl io:: Read for FileReaderWithProgress {
473- fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
474- match self . fh . read ( buf) {
475- Ok ( nbytes) => {
476- self . nbytes += nbytes as u64 ;
477- Ok ( nbytes)
478- }
479- Err ( e) => Err ( e) ,
480- }
447+ pub ( crate ) fn buffered ( path : & Path ) -> Result < BufReader < File > , anyhow:: Error > {
448+ match File :: open ( path) {
449+ Ok ( fh) => Ok ( BufReader :: with_capacity ( 8 * 1024 * 1024 , fh) ) ,
450+ Err ( _) => Err ( anyhow ! ( RustupError :: ReadingFile {
451+ name: "downloaded" ,
452+ path: path. to_path_buf( ) ,
453+ } ) ) ,
481454 }
482455}
483456
0 commit comments