@@ -9,7 +9,7 @@ use clap::builder::ValueParser;
99use clap:: { Arg , ArgAction , Command , value_parser} ;
1010use std:: ffi:: { OsStr , OsString } ;
1111use std:: fs:: File ;
12- use std:: io:: { self , BufReader , Read , Write , stdin, stdout} ;
12+ use std:: io:: { BufReader , Read , Write , stdin, stdout} ;
1313use std:: iter;
1414use std:: path:: Path ;
1515use uucore:: checksum:: {
@@ -68,14 +68,20 @@ where
6868 let filename = Path :: new ( filename) ;
6969 let stdin_buf;
7070 let file_buf;
71- let not_file = filename == OsStr :: new ( "-" ) ;
71+ let is_stdin = filename == OsStr :: new ( "-" ) ;
72+
73+ if filename. is_dir ( ) {
74+ show ! ( USimpleError :: new(
75+ 1 ,
76+ translate!( "cksum-error-is-directory" , "file" => filename. display( ) )
77+ ) ) ;
78+ continue ;
79+ }
7280
7381 // Handle the file input
74- let mut file = BufReader :: new ( if not_file {
82+ let mut file = BufReader :: new ( if is_stdin {
7583 stdin_buf = stdin ( ) ;
7684 Box :: new ( stdin_buf) as Box < dyn Read >
77- } else if filename. is_dir ( ) {
78- Box :: new ( BufReader :: new ( io:: empty ( ) ) ) as Box < dyn Read >
7985 } else {
8086 file_buf = match File :: open ( filename) {
8187 Ok ( file) => file,
8793 Box :: new ( file_buf) as Box < dyn Read >
8894 } ) ;
8995
90- if filename. is_dir ( ) {
91- show ! ( USimpleError :: new(
92- 1 ,
93- translate!( "cksum-error-is-directory" , "file" => filename. display( ) )
94- ) ) ;
95- continue ;
96- }
97-
9896 let ( sum_hex, sz) =
9997 digest_reader ( & mut options. digest , & mut file, false , options. output_bits )
10098 . map_err_context ( || translate ! ( "cksum-error-failed-to-read-input" ) ) ?;
@@ -130,24 +128,24 @@ where
130128 "{} {}{}" ,
131129 sum. parse:: <u16 >( ) . unwrap( ) ,
132130 sz. div_ceil( options. output_bits) ,
133- if not_file { "" } else { " " }
131+ if is_stdin { "" } else { " " }
134132 ) ,
135- !not_file ,
133+ !is_stdin ,
136134 String :: new ( ) ,
137135 ) ,
138136 ALGORITHM_OPTIONS_BSD => (
139137 format ! (
140138 "{:0bsd_width$} {:bsd_width$}{}" ,
141139 sum. parse:: <u16 >( ) . unwrap( ) ,
142140 sz. div_ceil( options. output_bits) ,
143- if not_file { "" } else { " " }
141+ if is_stdin { "" } else { " " }
144142 ) ,
145- !not_file ,
143+ !is_stdin ,
146144 String :: new ( ) ,
147145 ) ,
148146 ALGORITHM_OPTIONS_CRC | ALGORITHM_OPTIONS_CRC32B => (
149- format ! ( "{sum} {sz}{}" , if not_file { "" } else { " " } ) ,
150- !not_file ,
147+ format ! ( "{sum} {sz}{}" , if is_stdin { "" } else { " " } ) ,
148+ !is_stdin ,
151149 String :: new ( ) ,
152150 ) ,
153151 ALGORITHM_OPTIONS_BLAKE2B if options. tag => {
0 commit comments