@@ -405,30 +405,37 @@ extension FileManager {
405
405
guard alreadyConfirmed || shouldRemoveItemAtPath ( path, isURL: isURL) else {
406
406
return
407
407
}
408
- let faAttributes = try windowsFileAttributes ( atPath: path)
408
+ let url = URL ( fileURLWithPath: path)
409
+ var fsrBuf : UnsafeMutableBufferPointer < WCHAR > = UnsafeMutableBufferPointer . allocate ( capacity: path. length * 2 )
410
+ defer { fsrBuf. deallocate ( ) }
411
+ _CFURLGetWideFileSystemRepresentation ( url. _cfObject, false , fsrBuf. baseAddress, path. length * 2 )
412
+ let length = url. firstIndex ( where: { $0 == 0 } ) ?? ( path. length * 2 )
413
+ let fsrPath = String ( utf16CodeUnits: fsrBuf. baseAddress!, count: length)
414
+
415
+ let faAttributes = try windowsFileAttributes ( atPath: fsrPath)
409
416
if faAttributes. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) == 0 {
410
- if !path . withCString ( encodedAs: UTF16 . self, DeleteFileW) {
417
+ if !fsrPath . withCString ( encodedAs: UTF16 . self, DeleteFileW) {
411
418
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
412
419
}
413
420
return
414
421
}
415
- var dirStack = [ path ]
422
+ var dirStack = [ fsrPath ]
416
423
var itemPath = " "
417
424
while let currentDir = dirStack. popLast ( ) {
418
425
do {
419
426
itemPath = currentDir
420
427
guard alreadyConfirmed || shouldRemoveItemAtPath ( itemPath, isURL: isURL) else {
421
428
continue
422
429
}
423
- guard !path . withCString ( encodedAs: UTF16 . self, RemoveDirectoryW) else {
430
+ guard !itemPath . withCString ( encodedAs: UTF16 . self, RemoveDirectoryW) else {
424
431
continue
425
432
}
426
433
guard GetLastError ( ) == ERROR_DIR_NOT_EMPTY else {
427
434
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
428
435
}
429
- dirStack. append ( path )
436
+ dirStack. append ( itemPath )
430
437
var ffd : WIN32_FIND_DATAW = WIN32_FIND_DATAW ( )
431
- let h : HANDLE = ( path + " \\ * " ) . withCString ( encodedAs: UTF16 . self, {
438
+ let h : HANDLE = ( itemPath + " \\ * " ) . withCString ( encodedAs: UTF16 . self, {
432
439
FindFirstFileW ( $0, & ffd)
433
440
} )
434
441
guard h != INVALID_HANDLE_VALUE else {
0 commit comments