77
88// spell-checker:ignore fstatat unlinkat
99
10+ use indicatif:: ProgressBar ;
1011use std:: ffi:: OsStr ;
1112use std:: fs;
1213use std:: path:: Path ;
@@ -28,14 +29,22 @@ pub fn is_readable(path: &Path) -> bool {
2829}
2930
3031/// Remove a single file using safe traversal
31- pub fn safe_remove_file ( path : & Path , options : & Options ) -> Option < bool > {
32+ pub fn safe_remove_file (
33+ path : & Path ,
34+ options : & Options ,
35+ progress_bar : Option < & ProgressBar > ,
36+ ) -> Option < bool > {
3237 let parent = path. parent ( ) ?;
3338 let file_name = path. file_name ( ) ?;
3439
3540 let dir_fd = DirFd :: open ( parent) . ok ( ) ?;
3641
3742 match dir_fd. unlink_at ( file_name, false ) {
3843 Ok ( _) => {
44+ // Update progress bar for file removal
45+ if let Some ( pb) = progress_bar {
46+ pb. inc ( 1 ) ;
47+ }
3948 verbose_removed_file ( path, options) ;
4049 Some ( false )
4150 }
@@ -51,14 +60,22 @@ pub fn safe_remove_file(path: &Path, options: &Options) -> Option<bool> {
5160}
5261
5362/// Remove an empty directory using safe traversal
54- pub fn safe_remove_empty_dir ( path : & Path , options : & Options ) -> Option < bool > {
63+ pub fn safe_remove_empty_dir (
64+ path : & Path ,
65+ options : & Options ,
66+ progress_bar : Option < & ProgressBar > ,
67+ ) -> Option < bool > {
5568 let parent = path. parent ( ) ?;
5669 let dir_name = path. file_name ( ) ?;
5770
5871 let dir_fd = DirFd :: open ( parent) . ok ( ) ?;
5972
6073 match dir_fd. unlink_at ( dir_name, true ) {
6174 Ok ( _) => {
75+ // Update progress bar for directory removal
76+ if let Some ( pb) = progress_bar {
77+ pb. inc ( 1 ) ;
78+ }
6279 verbose_removed_directory ( path, options) ;
6380 Some ( false )
6481 }
@@ -172,12 +189,16 @@ pub fn remove_dir_with_special_cases(path: &Path, options: &Options, error_occur
172189 }
173190}
174191
175- pub fn safe_remove_dir_recursive ( path : & Path , options : & Options ) -> bool {
192+ pub fn safe_remove_dir_recursive (
193+ path : & Path ,
194+ options : & Options ,
195+ progress_bar : Option < & ProgressBar > ,
196+ ) -> bool {
176197 // Base case 1: this is a file or a symbolic link.
177198 // Use lstat to avoid race condition between check and use
178199 match fs:: symlink_metadata ( path) {
179200 Ok ( metadata) if !metadata. is_dir ( ) => {
180- return remove_file ( path, options) ;
201+ return remove_file ( path, options, progress_bar ) ;
181202 }
182203 Ok ( _) => { }
183204 Err ( e) => {
0 commit comments