@@ -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} ;
@@ -441,40 +441,13 @@ pub(crate) fn delete_dir_contents_following_links(dir_path: &Path) {
441441 }
442442}
443443
444- pub ( crate ) struct FileReaderWithProgress {
445- fh : BufReader < File > ,
446- nbytes : u64 ,
447- }
448-
449- impl FileReaderWithProgress {
450- pub ( crate ) fn new_file ( path : & Path ) -> Result < Self > {
451- let fh = match File :: open ( path) {
452- Ok ( fh) => fh,
453- Err ( _) => {
454- bail ! ( RustupError :: ReadingFile {
455- name: "downloaded" ,
456- path: path. to_path_buf( ) ,
457- } )
458- }
459- } ;
460-
461- // Inform the tracker of the file size
462- Ok ( FileReaderWithProgress {
463- fh : BufReader :: with_capacity ( 8 * 1024 * 1024 , fh) ,
464- nbytes : 0 ,
465- } )
466- }
467- }
468-
469- impl io:: Read for FileReaderWithProgress {
470- fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
471- match self . fh . read ( buf) {
472- Ok ( nbytes) => {
473- self . nbytes += nbytes as u64 ;
474- Ok ( nbytes)
475- }
476- Err ( e) => Err ( e) ,
477- }
444+ pub ( crate ) fn buffered ( path : & Path ) -> Result < BufReader < File > , anyhow:: Error > {
445+ match File :: open ( path) {
446+ Ok ( fh) => Ok ( BufReader :: with_capacity ( 8 * 1024 * 1024 , fh) ) ,
447+ Err ( _) => Err ( anyhow ! ( RustupError :: ReadingFile {
448+ name: "downloaded" ,
449+ path: path. to_path_buf( ) ,
450+ } ) ) ,
478451 }
479452}
480453
0 commit comments