File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ use std::ffi::OsString;
1010use std:: fs;
1111use std:: io:: { Write , stdout} ;
1212use std:: path:: { Path , PathBuf } ;
13- use uucore:: error:: { FromIo , UResult , USimpleError , UUsageError } ;
13+ use uucore:: error:: { FromIo , UResult , UUsageError } ;
1414use uucore:: fs:: { MissingHandling , ResolveMode , canonicalize} ;
15+ use uucore:: libc:: EINVAL ;
1516use uucore:: line_ending:: LineEnding ;
1617use uucore:: translate;
1718use uucore:: { format_usage, show_error} ;
@@ -88,15 +89,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8889 show ( & path, line_ending) . map_err_context ( String :: new) ?;
8990 }
9091 Err ( err) => {
91- return if verbose {
92- Err ( USimpleError :: new (
93- 1 ,
94- err. map_err_context ( move || p. to_string_lossy ( ) . to_string ( ) )
95- . to_string ( ) ,
96- ) )
92+ if silent && !verbose {
93+ return Err ( 1 . into ( ) ) ;
94+ }
95+
96+ let path = p. to_string_lossy ( ) . into_owned ( ) ;
97+ let message = if err. raw_os_error ( ) == Some ( EINVAL ) {
98+ format ! ( "{path}: Invalid argument" )
9799 } else {
98- Err ( 1 . into ( ) )
100+ err . map_err_context ( || path . clone ( ) ) . to_string ( )
99101 } ;
102+ show_error ! ( "{message}" ) ;
103+ return Err ( 1 . into ( ) ) ;
100104 }
101105 }
102106 }
Original file line number Diff line number Diff line change @@ -102,6 +102,20 @@ fn test_symlink_to_itself_verbose() {
102102 . stderr_contains ( "Too many levels of symbolic links" ) ;
103103}
104104
105+ #[ test]
106+ fn test_posixly_correct_regular_file ( ) {
107+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
108+ let at = & scene. fixtures ;
109+ at. touch ( "regfile" ) ;
110+ scene
111+ . ucmd ( )
112+ . env ( "POSIXLY_CORRECT" , "1" )
113+ . arg ( "regfile" )
114+ . fails_with_code ( 1 )
115+ . stderr_contains ( "Invalid argument" )
116+ . no_stdout ( ) ;
117+ }
118+
105119#[ test]
106120fn test_trailing_slash_regular_file ( ) {
107121 let scene = TestScenario :: new ( util_name ! ( ) ) ;
You can’t perform that action at this time.
0 commit comments