File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed
Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ use nix::{
5454} ;
5555use uucore:: display:: Quotable ;
5656#[ cfg( unix) ]
57- use uucore:: error:: set_exit_code;
57+ use uucore:: error:: { set_exit_code, USimpleError } ;
5858use uucore:: error:: { FromIo , UResult } ;
5959#[ cfg( target_os = "linux" ) ]
6060use uucore:: show_if_err;
@@ -338,11 +338,11 @@ impl<'a> Input<'a> {
338338 let mut src = Source :: stdin_as_file ( ) ;
339339 #[ cfg( unix) ]
340340 if let Source :: StdinFile ( f) = & src {
341- // GNU compatibility:
342- // this will check whether stdin points to a folder or not
343- if f . metadata ( ) ? . is_file ( ) && settings . iflags . directory {
344- show_error ! ( " standard input: not a directory") ;
345- return Err ( 1 . into ( ) ) ;
341+ if settings . iflags . directory && !f . metadata ( ) ? . is_dir ( ) {
342+ return Err ( USimpleError :: new (
343+ 1 ,
344+ "setting flags for ' standard input': Not a directory",
345+ ) ) ;
346346 }
347347 } ;
348348 if settings. skip > 0 {
Original file line number Diff line number Diff line change @@ -1728,7 +1728,26 @@ fn test_iflag_directory_fails_when_file_is_passed_via_std_in() {
17281728 . args ( & [ "iflag=directory" , "count=0" ] )
17291729 . set_stdin ( std:: process:: Stdio :: from ( File :: open ( filename) . unwrap ( ) ) )
17301730 . fails ( )
1731- . stderr_contains ( "standard input: not a directory" ) ;
1731+ . stderr_only ( "dd: setting flags for 'standard input': Not a directory\n " ) ;
1732+ }
1733+
1734+ #[ test]
1735+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1736+ fn test_iflag_directory_passes_when_dir_is_redirected ( ) {
1737+ new_ucmd ! ( )
1738+ . args ( & [ "iflag=directory" , "count=0" ] )
1739+ . set_stdin ( std:: process:: Stdio :: from ( File :: open ( "." ) . unwrap ( ) ) )
1740+ . succeeds ( ) ;
1741+ }
1742+
1743+ #[ test]
1744+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1745+ fn test_iflag_directory_fails_when_file_is_piped_via_std_in ( ) {
1746+ new_ucmd ! ( )
1747+ . arg ( "iflag=directory" )
1748+ . pipe_in ( "" )
1749+ . fails ( )
1750+ . stderr_only ( "dd: setting flags for 'standard input': Not a directory\n " ) ;
17321751}
17331752
17341753#[ test]
You can’t perform that action at this time.
0 commit comments