File tree Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ use clap::value_parser;
1111use clap:: { Arg , ArgMatches , Command } ;
1212use std:: ffi:: { OsStr , OsString } ;
1313use std:: fs:: File ;
14- use std:: io:: { BufReader , Read , stdin} ;
14+ use std:: io:: { BufReader , ErrorKind , Read , stdin} ;
1515use std:: iter;
1616use std:: num:: ParseIntError ;
1717use std:: path:: Path ;
@@ -559,13 +559,31 @@ where
559559 Box :: new ( file_buf) as Box < dyn Read >
560560 } ) ;
561561
562- let ( sum, _ ) = digest_reader (
562+ let sum = match digest_reader (
563563 & mut options. digest ,
564564 & mut file,
565565 options. binary ,
566566 options. output_bits ,
567- )
568- . map_err_context ( || translate ! ( "hashsum-error-failed-to-read-input" ) ) ?;
567+ ) {
568+ Ok ( ( sum, _) ) => sum,
569+ Err ( e) => match e. kind ( ) {
570+ ErrorKind :: IsADirectory => {
571+ eprintln ! (
572+ "{}: {}: {e}" ,
573+ options. binary_name,
574+ filename. to_string_lossy( )
575+ ) ;
576+ err_found = Some ( ChecksumError :: Io ( e) ) ;
577+ continue ;
578+ }
579+ _ => {
580+ return Err (
581+ e. map_err_context ( || translate ! ( "hashsum-error-failed-to-read-input" ) )
582+ ) ;
583+ }
584+ } ,
585+ } ;
586+
569587 let ( escaped_filename, prefix) = escape_filename ( filename) ;
570588 if options. tag {
571589 if options. algoname == "blake2b" {
Original file line number Diff line number Diff line change @@ -872,6 +872,26 @@ fn test_check_directory_error() {
872872 . stderr_contains ( err_msg) ;
873873}
874874
875+ #[ test]
876+ fn test_continue_after_directory_error ( ) {
877+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
878+ let at = & scene. fixtures ;
879+
880+ at. mkdir ( "d" ) ;
881+ at. touch ( "file" ) ;
882+ #[ cfg( not( windows) ) ]
883+ let err_msg = "md5sum: d: Is a directory (os error 21)\n " ;
884+ #[ cfg( windows) ]
885+ let err_msg = "md5sum: d: Permission denied\n " ;
886+ scene
887+ . ccmd ( "md5sum" )
888+ . arg ( "d" )
889+ . arg ( "file" )
890+ . fails ( )
891+ . stdout_contains ( "d41d8cd98f00b204e9800998ecf8427e file" )
892+ . stderr_contains ( err_msg) ;
893+ }
894+
875895#[ test]
876896fn test_check_quiet ( ) {
877897 let scene = TestScenario :: new ( util_name ! ( ) ) ;
You can’t perform that action at this time.
0 commit comments