@@ -33,7 +33,7 @@ use core::sync::atomic::{Atomic, AtomicU32, Ordering};
33
33
34
34
use super :: { AsRawHandle , DirBuff , File , FromRawHandle } ;
35
35
use crate :: sys:: c;
36
- use crate :: sys:: pal:: api:: WinError ;
36
+ use crate :: sys:: pal:: api:: { UnicodeStrRef , WinError , unicode_str } ;
37
37
use crate :: thread;
38
38
39
39
// The maximum number of times to spin when waiting for deletes to complete.
@@ -74,7 +74,7 @@ unsafe fn nt_open_file(
74
74
/// `options` will be OR'd with `FILE_OPEN_REPARSE_POINT`.
75
75
fn open_link_no_reparse (
76
76
parent : & File ,
77
- path : & [ u16 ] ,
77
+ path : UnicodeStrRef < ' _ > ,
78
78
access : u32 ,
79
79
options : u32 ,
80
80
) -> Result < Option < File > , WinError > {
@@ -90,9 +90,8 @@ fn open_link_no_reparse(
90
90
static ATTRIBUTES : Atomic < u32 > = AtomicU32 :: new ( c:: OBJ_DONT_REPARSE ) ;
91
91
92
92
let result = unsafe {
93
- let mut path_str = c:: UNICODE_STRING :: from_ref ( path) ;
94
93
let mut object = c:: OBJECT_ATTRIBUTES {
95
- ObjectName : & mut path_str ,
94
+ ObjectName : path . as_ptr ( ) ,
96
95
RootDirectory : parent. as_raw_handle ( ) ,
97
96
Attributes : ATTRIBUTES . load ( Ordering :: Relaxed ) ,
98
97
..c:: OBJECT_ATTRIBUTES :: with_length ( )
@@ -129,7 +128,7 @@ fn open_link_no_reparse(
129
128
}
130
129
}
131
130
132
- fn open_dir ( parent : & File , name : & [ u16 ] ) -> Result < Option < File > , WinError > {
131
+ fn open_dir ( parent : & File , name : UnicodeStrRef < ' _ > ) -> Result < Option < File > , WinError > {
133
132
// Open the directory for synchronous directory listing.
134
133
open_link_no_reparse (
135
134
parent,
@@ -140,7 +139,7 @@ fn open_dir(parent: &File, name: &[u16]) -> Result<Option<File>, WinError> {
140
139
)
141
140
}
142
141
143
- fn delete ( parent : & File , name : & [ u16 ] ) -> Result < ( ) , WinError > {
142
+ fn delete ( parent : & File , name : UnicodeStrRef < ' _ > ) -> Result < ( ) , WinError > {
144
143
// Note that the `delete` function consumes the opened file to ensure it's
145
144
// dropped immediately. See module comments for why this is important.
146
145
match open_link_no_reparse ( parent, name, c:: DELETE , 0 ) {
@@ -179,16 +178,17 @@ pub fn remove_dir_all_iterative(dir: File) -> Result<(), WinError> {
179
178
' outer: while let Some ( dir) = dirlist. pop ( ) {
180
179
let more_data = dir. fill_dir_buff ( & mut buffer, restart) ?;
181
180
for ( name, is_directory) in buffer. iter ( ) {
181
+ let name = unicode_str ! ( & name) ;
182
182
if is_directory {
183
- let Some ( subdir) = open_dir ( & dir, & name) ? else { continue } ;
183
+ let Some ( subdir) = open_dir ( & dir, name) ? else { continue } ;
184
184
dirlist. push ( dir) ;
185
185
dirlist. push ( subdir) ;
186
186
continue ' outer;
187
187
} else {
188
188
// Attempt to delete, retrying on sharing violation errors as these
189
189
// can often be very temporary. E.g. if something takes just a
190
190
// bit longer than expected to release a file handle.
191
- retry ( || delete ( & dir, & name) , WinError :: SHARING_VIOLATION ) ?;
191
+ retry ( || delete ( & dir, name) , WinError :: SHARING_VIOLATION ) ?;
192
192
}
193
193
}
194
194
if more_data {
@@ -197,7 +197,8 @@ pub fn remove_dir_all_iterative(dir: File) -> Result<(), WinError> {
197
197
} else {
198
198
// Attempt to delete, retrying on not empty errors because we may
199
199
// need to wait some time for files to be removed from the filesystem.
200
- retry ( || delete ( & dir, & [ ] ) , WinError :: DIR_NOT_EMPTY ) ?;
200
+ let name = unicode_str ! ( "" ) ;
201
+ retry ( || delete ( & dir, name) , WinError :: DIR_NOT_EMPTY ) ?;
201
202
restart = true ;
202
203
}
203
204
}
0 commit comments