@@ -33,7 +33,7 @@ use core::sync::atomic::{Atomic, AtomicU32, Ordering};
3333
3434use super :: { AsRawHandle , DirBuff , File , FromRawHandle } ;
3535use crate :: sys:: c;
36- use crate :: sys:: pal:: api:: WinError ;
36+ use crate :: sys:: pal:: api:: { UnicodeStrRef , WinError , unicode_str } ;
3737use crate :: thread;
3838
3939// The maximum number of times to spin when waiting for deletes to complete.
@@ -74,7 +74,7 @@ unsafe fn nt_open_file(
7474/// `options` will be OR'd with `FILE_OPEN_REPARSE_POINT`.
7575fn open_link_no_reparse (
7676 parent : & File ,
77- path : & [ u16 ] ,
77+ path : UnicodeStrRef < ' _ > ,
7878 access : u32 ,
7979 options : u32 ,
8080) -> Result < Option < File > , WinError > {
@@ -90,9 +90,8 @@ fn open_link_no_reparse(
9090 static ATTRIBUTES : Atomic < u32 > = AtomicU32 :: new ( c:: OBJ_DONT_REPARSE ) ;
9191
9292 let result = unsafe {
93- let mut path_str = c:: UNICODE_STRING :: from_ref ( path) ;
9493 let mut object = c:: OBJECT_ATTRIBUTES {
95- ObjectName : & mut path_str ,
94+ ObjectName : path . as_ptr ( ) ,
9695 RootDirectory : parent. as_raw_handle ( ) ,
9796 Attributes : ATTRIBUTES . load ( Ordering :: Relaxed ) ,
9897 ..c:: OBJECT_ATTRIBUTES :: with_length ( )
@@ -129,7 +128,7 @@ fn open_link_no_reparse(
129128 }
130129}
131130
132- fn open_dir ( parent : & File , name : & [ u16 ] ) -> Result < Option < File > , WinError > {
131+ fn open_dir ( parent : & File , name : UnicodeStrRef < ' _ > ) -> Result < Option < File > , WinError > {
133132 // Open the directory for synchronous directory listing.
134133 open_link_no_reparse (
135134 parent,
@@ -140,7 +139,7 @@ fn open_dir(parent: &File, name: &[u16]) -> Result<Option<File>, WinError> {
140139 )
141140}
142141
143- fn delete ( parent : & File , name : & [ u16 ] ) -> Result < ( ) , WinError > {
142+ fn delete ( parent : & File , name : UnicodeStrRef < ' _ > ) -> Result < ( ) , WinError > {
144143 // Note that the `delete` function consumes the opened file to ensure it's
145144 // dropped immediately. See module comments for why this is important.
146145 match open_link_no_reparse ( parent, name, c:: DELETE , 0 ) {
@@ -179,16 +178,17 @@ pub fn remove_dir_all_iterative(dir: File) -> Result<(), WinError> {
179178 ' outer: while let Some ( dir) = dirlist. pop ( ) {
180179 let more_data = dir. fill_dir_buff ( & mut buffer, restart) ?;
181180 for ( name, is_directory) in buffer. iter ( ) {
181+ let name = unicode_str ! ( & name) ;
182182 if is_directory {
183- let Some ( subdir) = open_dir ( & dir, & name) ? else { continue } ;
183+ let Some ( subdir) = open_dir ( & dir, name) ? else { continue } ;
184184 dirlist. push ( dir) ;
185185 dirlist. push ( subdir) ;
186186 continue ' outer;
187187 } else {
188188 // Attempt to delete, retrying on sharing violation errors as these
189189 // can often be very temporary. E.g. if something takes just a
190190 // 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 ) ?;
192192 }
193193 }
194194 if more_data {
@@ -197,7 +197,8 @@ pub fn remove_dir_all_iterative(dir: File) -> Result<(), WinError> {
197197 } else {
198198 // Attempt to delete, retrying on not empty errors because we may
199199 // 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 ) ?;
201202 restart = true ;
202203 }
203204 }
0 commit comments