File tree 1 file changed +15
-2
lines changed
library/std/src/sys/windows
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -1018,6 +1018,10 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> {
1018
1018
}
1019
1019
1020
1020
fn remove_dir_all_iterative ( f : & File , delete : fn ( & File ) -> io:: Result < ( ) > ) -> io:: Result < ( ) > {
1021
+ // When deleting files we may loop this many times when certain error conditions occur.
1022
+ // This allows remove_dir_all to succeed when the error is temporary.
1023
+ const MAX_RETRIES : u32 = 10 ;
1024
+
1021
1025
let mut buffer = DirBuff :: new ( ) ;
1022
1026
let mut dirlist = vec ! [ f. duplicate( ) ?] ;
1023
1027
@@ -1040,7 +1044,6 @@ fn remove_dir_all_iterative(f: &File, delete: fn(&File) -> io::Result<()>) -> io
1040
1044
) ?;
1041
1045
dirlist. push ( child_dir) ;
1042
1046
} else {
1043
- const MAX_RETRIES : u32 = 10 ;
1044
1047
for i in 1 ..=MAX_RETRIES {
1045
1048
let result = open_link_no_reparse ( & dir, name, c:: SYNCHRONIZE | c:: DELETE ) ;
1046
1049
match result {
@@ -1062,7 +1065,17 @@ fn remove_dir_all_iterative(f: &File, delete: fn(&File) -> io::Result<()>) -> io
1062
1065
// If there were no more files then delete the directory.
1063
1066
if !more_data {
1064
1067
if let Some ( dir) = dirlist. pop ( ) {
1065
- delete ( & dir) ?;
1068
+ // Retry deleting a few times in case we need to wait for a file to be deleted.
1069
+ for i in 1 ..=MAX_RETRIES {
1070
+ let result = delete ( & dir) ;
1071
+ if let Err ( e) = result {
1072
+ if i == MAX_RETRIES || e. kind ( ) != io:: ErrorKind :: DirectoryNotEmpty {
1073
+ return Err ( e) ;
1074
+ }
1075
+ } else {
1076
+ break ;
1077
+ }
1078
+ }
1066
1079
}
1067
1080
}
1068
1081
}
You can’t perform that action at this time.
0 commit comments