@@ -22,9 +22,9 @@ use std::panic;
22
22
use std:: path:: { Path , PathBuf } ;
23
23
24
24
pub use gimli;
25
- pub use glob;
26
25
pub use object;
27
26
pub use regex;
27
+ pub use walkdir;
28
28
pub use wasmparser;
29
29
30
30
pub use cc:: { cc, extra_c_flags, extra_cxx_flags, Cc } ;
@@ -209,40 +209,34 @@ pub fn bin_name(name: &str) -> String {
209
209
if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
210
210
}
211
211
212
- /// Remove all dynamic libraries possessing a name starting with `paths`.
212
+ /// Count the number of files in the current
213
+ /// working directory possessing the extension `ext`.
213
214
#[ track_caller]
214
- pub fn remove_dylibs ( paths : & str ) {
215
- let paths = format ! ( r"{paths}*" ) ;
216
- remove_glob ( dynamic_lib_name ( & paths) . as_str ( ) ) ;
217
- }
215
+ pub fn count_files_with_extension ( ext : & str ) -> usize {
216
+ use walkdir:: { DirEntry , WalkDir } ;
218
217
219
- /// Remove all rust libraries possessing a name starting with `paths`.
220
- #[ track_caller]
221
- pub fn remove_rlibs ( paths : & str ) {
222
- let paths = format ! ( r"{paths}*" ) ;
223
- remove_glob ( rust_lib_name ( & paths) . as_str ( ) ) ;
224
- }
218
+ let walker = WalkDir :: new ( cwd ( ) ) . into_iter ( ) ;
225
219
226
- #[ track_caller]
227
- fn remove_glob ( paths : & str ) {
228
- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
229
- paths
230
- . filter_map ( |entry| entry. ok ( ) )
231
- . filter ( |entry| entry. as_path ( ) . is_file ( ) )
232
- . for_each ( |file| fs_wrapper:: remove_file ( & file) ) ;
233
- }
220
+ fn is_hidden ( entry : & DirEntry ) -> bool {
221
+ entry. file_name ( ) . to_str ( ) . map ( |s| s. starts_with ( "." ) ) . unwrap_or ( false )
222
+ }
234
223
235
- #[ track_caller]
236
- fn count_glob ( paths : & str ) -> usize {
237
- let paths = glob:: glob ( paths) . expect ( format ! ( "Glob expression {paths} is not valid." ) . as_str ( ) ) ;
238
- paths. filter_map ( |entry| entry. ok ( ) ) . filter ( |entry| entry. as_path ( ) . is_file ( ) ) . count ( )
239
- }
224
+ let mut count = 0 ;
240
225
241
- /// Count the number of rust libraries possessing a name starting with `paths`.
242
- #[ track_caller]
243
- pub fn count_rlibs ( paths : & str ) -> usize {
244
- let paths = format ! ( r"{paths}*" ) ;
245
- count_glob ( rust_lib_name ( & paths) . as_str ( ) )
226
+ for entry in walker. filter_entry ( |e| !is_hidden ( e) ) {
227
+ let entry = entry. expect ( "failed to get DirEntry" ) ;
228
+ if !entry. path ( ) . is_file ( ) {
229
+ continue ;
230
+ }
231
+
232
+ if !entry. path ( ) . extension ( ) . is_some_and ( |e| e == ext) {
233
+ continue ;
234
+ }
235
+
236
+ count += 1 ;
237
+ }
238
+
239
+ count
246
240
}
247
241
248
242
/// Return the current working directory.
0 commit comments