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