@@ -22,7 +22,6 @@ use std::panic;
2222use std:: path:: { Path , PathBuf } ;
2323
2424pub use gimli;
25- pub use glob;
2625pub use object;
2726pub use regex;
2827pub use wasmparser;
@@ -223,40 +222,33 @@ pub fn bin_name(name: &str) -> String {
223222 if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
224223}
225224
226- /// Remove all dynamic libraries possessing a name starting with `paths`.
225+ /// Browse the directory `path` non-recursively and return all files which respect the parameters
226+ /// outlined by `closure`.
227227#[ track_caller]
228- pub fn remove_dylibs ( paths : & str ) {
229- let paths = format ! ( r"{paths}*" ) ;
230- remove_glob ( dynamic_lib_name ( & paths) . as_str ( ) ) ;
231- }
232-
233- /// Remove all rust libraries possessing a name starting with `paths`.
234- #[ track_caller]
235- pub fn remove_rlibs ( paths : & str ) {
236- let paths = format ! ( r"{paths}*" ) ;
237- remove_glob ( rust_lib_name ( & paths) . as_str ( ) ) ;
238- }
239-
240- #[ track_caller]
241- fn remove_glob ( paths : & str ) {
242- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
243- paths
244- . filter_map ( |entry| entry. ok ( ) )
245- . filter ( |entry| entry. as_path ( ) . is_file ( ) )
246- . for_each ( |file| fs_wrapper:: remove_file ( & file) ) ;
228+ pub fn shallow_find_files < P : AsRef < Path > , F : Fn ( & PathBuf ) -> bool > (
229+ path : P ,
230+ closure : F ,
231+ ) -> Vec < PathBuf > {
232+ let mut matching_files = Vec :: new ( ) ;
233+ for entry in fs_wrapper:: read_dir ( path) {
234+ let entry = entry. expect ( "failed to read directory entry." ) ;
235+ let path = entry. path ( ) ;
236+
237+ if path. is_file ( ) && closure ( & path) {
238+ matching_files. push ( path) ;
239+ }
240+ }
241+ matching_files
247242}
248243
249- #[ track_caller]
250- fn count_glob ( paths : & str ) -> usize {
251- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
252- paths. filter_map ( |entry| entry. ok ( ) ) . filter ( |entry| entry. as_path ( ) . is_file ( ) ) . count ( )
244+ /// Returns true if the filename at `path` starts with `prefix`.
245+ pub fn has_prefix < P : AsRef < Path > > ( path : P , prefix : & str ) -> bool {
246+ path. as_ref ( ) . file_name ( ) . is_some_and ( |name| name. to_str ( ) . unwrap ( ) . starts_with ( prefix) )
253247}
254248
255- /// Count the number of rust libraries possessing a name starting with `paths`.
256- #[ track_caller]
257- pub fn count_rlibs ( paths : & str ) -> usize {
258- let paths = format ! ( r"{paths}*" ) ;
259- count_glob ( rust_lib_name ( & paths) . as_str ( ) )
249+ /// Returns true if the filename at `path` has the extension `extension`.
250+ pub fn has_extension < P : AsRef < Path > > ( path : P , extension : & str ) -> bool {
251+ path. as_ref ( ) . extension ( ) . is_some_and ( |ext| ext == extension)
260252}
261253
262254/// Return the current working directory.
0 commit comments