File tree Expand file tree Collapse file tree 4 files changed +60
-13
lines changed Expand file tree Collapse file tree 4 files changed +60
-13
lines changed Original file line number Diff line number Diff line change @@ -539,16 +539,19 @@ impl EnvAppData {
539
539
}
540
540
return Err ( exit. code ( ) . unwrap ( ) . into ( ) ) ;
541
541
}
542
- Err ( ref err)
543
- if ( err. kind ( ) == io:: ErrorKind :: NotFound )
544
- || ( err. kind ( ) == io:: ErrorKind :: InvalidInput ) =>
545
- {
546
- return Err ( self . make_error_no_such_file_or_dir ( prog. deref ( ) ) ) ;
547
- }
548
- Err ( e) => {
549
- uucore:: show_error!( "unknown error: {:?}" , e) ;
550
- return Err ( 126 . into ( ) ) ;
551
- }
542
+ Err ( ref err) => match err. kind ( ) {
543
+ io:: ErrorKind :: NotFound | io:: ErrorKind :: InvalidInput => {
544
+ return Err ( self . make_error_no_such_file_or_dir ( prog. deref ( ) ) ) ;
545
+ }
546
+ io:: ErrorKind :: PermissionDenied => {
547
+ uucore:: show_error!( "{}: Permission denied" , prog. quote( ) ) ;
548
+ return Err ( 126 . into ( ) ) ;
549
+ }
550
+ _ => {
551
+ uucore:: show_error!( "unknown error: {:?}" , err) ;
552
+ return Err ( 126 . into ( ) ) ;
553
+ }
554
+ } ,
552
555
Ok ( _) => ( ) ,
553
556
}
554
557
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -157,9 +157,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
157
157
set_command_env ( & mut command, "_STDBUF_E" , & options. stderr ) ;
158
158
command. args ( command_params) ;
159
159
160
- let mut process = command
161
- . spawn ( )
162
- . map_err_context ( || "failed to execute process" . to_string ( ) ) ?;
160
+ const EXEC_ERROR : & str = "failed to execute process:" ;
161
+ let mut process = match command. spawn ( ) {
162
+ Ok ( p) => p,
163
+ Err ( e) => {
164
+ return match e. kind ( ) {
165
+ std:: io:: ErrorKind :: PermissionDenied => Err ( USimpleError :: new (
166
+ 126 ,
167
+ format ! ( "{EXEC_ERROR} Permission denied" ) ,
168
+ ) ) ,
169
+ std:: io:: ErrorKind :: NotFound => Err ( USimpleError :: new (
170
+ 127 ,
171
+ format ! ( "{EXEC_ERROR} No such file or directory" ) ,
172
+ ) ) ,
173
+ _ => Err ( USimpleError :: new ( 1 , format ! ( "{EXEC_ERROR} {}" , e) ) ) ,
174
+ }
175
+ }
176
+ } ;
177
+
163
178
let status = process. wait ( ) . map_err_context ( String :: new) ?;
164
179
match status. code ( ) {
165
180
Some ( i) => {
Original file line number Diff line number Diff line change @@ -80,6 +80,15 @@ fn test_env_version() {
80
80
. stdout_contains ( util_name ! ( ) ) ;
81
81
}
82
82
83
+ #[ test]
84
+ fn test_env_permissions ( ) {
85
+ new_ucmd ! ( )
86
+ . arg ( "." )
87
+ . fails ( )
88
+ . code_is ( 126 )
89
+ . stderr_is ( "env: '.': Permission denied\n " ) ;
90
+ }
91
+
83
92
#[ test]
84
93
fn test_echo ( ) {
85
94
#[ cfg( target_os = "windows" ) ]
Original file line number Diff line number Diff line change @@ -10,6 +10,26 @@ fn invalid_input() {
10
10
new_ucmd ! ( ) . arg ( "-/" ) . fails ( ) . code_is ( 125 ) ;
11
11
}
12
12
13
+ #[ test]
14
+ fn test_permission ( ) {
15
+ new_ucmd ! ( )
16
+ . arg ( "-o1" )
17
+ . arg ( "." )
18
+ . fails ( )
19
+ . code_is ( 126 )
20
+ . stderr_contains ( "Permission denied" ) ;
21
+ }
22
+
23
+ #[ test]
24
+ fn test_no_such ( ) {
25
+ new_ucmd ! ( )
26
+ . arg ( "-o1" )
27
+ . arg ( "no_such" )
28
+ . fails ( )
29
+ . code_is ( 127 )
30
+ . stderr_contains ( "No such file or directory" ) ;
31
+ }
32
+
13
33
#[ cfg( all( not( target_os = "windows" ) , not( target_os = "openbsd" ) ) ) ]
14
34
#[ test]
15
35
fn test_stdbuf_unbuffered_stdout ( ) {
You can’t perform that action at this time.
0 commit comments