@@ -190,7 +190,7 @@ where
190190}
191191
192192/// Check whether a path points to a regular file and any executable flag is set
193- pub ( crate ) fn is_valid_executable ( path : & PathBuf ) -> bool {
193+ pub ( crate ) fn is_valid_executable ( path : & Path ) -> bool {
194194 if path. is_file ( ) {
195195 match fs:: metadata ( path) {
196196 Ok ( meta) => meta. mode ( ) & 0o111 != 0 ,
@@ -216,12 +216,12 @@ pub(crate) fn resolve_path(command: &Path, path: &str) -> Option<PathBuf> {
216216 // construct a possible executable absolute path candidate
217217 . map ( |path| path. join ( command) )
218218 // check whether the candidate is a regular file and any executable flag is set
219- . find ( is_valid_executable)
219+ . find ( |arg| is_valid_executable ( arg ) )
220220}
221221
222222#[ cfg( test) ]
223223mod tests {
224- use std:: path:: PathBuf ;
224+ use std:: path:: Path ;
225225
226226 use crate :: common:: resolve:: CurrentUser ;
227227 use crate :: system:: ROOT_GROUP_NAME ;
@@ -234,43 +234,18 @@ mod tests {
234234 let path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ;
235235
236236 assert ! ( is_valid_executable(
237- & resolve_path( & PathBuf :: from ( "yes" ) , path) . unwrap( )
237+ & resolve_path( Path :: new ( "yes" ) , path) . unwrap( )
238238 ) ) ;
239239
240240 assert ! ( is_valid_executable(
241- & resolve_path( & PathBuf :: from ( "whoami" ) , path) . unwrap( )
241+ & resolve_path( Path :: new ( "whoami" ) , path) . unwrap( )
242242 ) ) ;
243243
244244 assert ! ( is_valid_executable(
245- & resolve_path( & PathBuf :: from ( "env" ) , path) . unwrap( )
245+ & resolve_path( Path :: new ( "env" ) , path) . unwrap( )
246246 ) ) ;
247- assert_eq ! (
248- resolve_path( & PathBuf :: from( "thisisnotonyourfs" ) , path) ,
249- None
250- ) ;
251- assert_eq ! ( resolve_path( & PathBuf :: from( "thisisnotonyourfs" ) , "." ) , None ) ;
252- }
253-
254- #[ test]
255- fn test_cwd_resolve_path ( ) {
256- // We modify the path to contain ".", which is supposed to be ignored
257- let path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:." ;
258-
259- let cwd = std:: env:: current_dir ( ) . unwrap ( ) ;
260-
261- // we filter for executable files, so it is most likely going to pick one of the shell
262- // scripts in the project's root
263- let some_file = cwd
264- . read_dir ( )
265- . unwrap ( )
266- . filter_map ( |entry| entry. ok ( ) )
267- . find_map ( |entry| {
268- let pathbuf = PathBuf :: from ( entry. file_name ( ) ) ;
269- is_valid_executable ( & pathbuf) . then_some ( pathbuf)
270- } )
271- . unwrap ( ) ;
272-
273- assert_eq ! ( resolve_path( & some_file, path) , None ) ;
247+ assert_eq ! ( resolve_path( Path :: new( "thisisnotonyourfs" ) , path) , None ) ;
248+ assert_eq ! ( resolve_path( Path :: new( "thisisnotonyourfs" ) , "." ) , None ) ;
274249 }
275250
276251 #[ test]
0 commit comments