@@ -422,6 +422,14 @@ extension FileManager {
422
422
let fsrPath = String ( utf16CodeUnits: & fsrBuf, count: length)
423
423
424
424
let faAttributes = try windowsFileAttributes ( atPath: fsrPath)
425
+
426
+ if faAttributes. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY {
427
+ let readableAttributes = faAttributes. dwFileAttributes & DWORD ( bitPattern: ~ FILE_ATTRIBUTE_READONLY)
428
+ guard fsrPath. withCString ( encodedAs: UTF16 . self, { SetFileAttributesW ( $0, readableAttributes) } ) else {
429
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
430
+ }
431
+ }
432
+
425
433
if faAttributes. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) == 0 {
426
434
if !fsrPath. withCString ( encodedAs: UTF16 . self, DeleteFileW) {
427
435
throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
@@ -458,6 +466,14 @@ extension FileManager {
458
466
count: MemoryLayout . size ( ofValue: ffd. cFileName) ) )
459
467
let file = String ( decodingCString: fileArr, as: UTF16 . self)
460
468
itemPath = " \( currentDir) \\ \( file) "
469
+
470
+ if ffd. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY {
471
+ let readableAttributes = ffd. dwFileAttributes & DWORD ( bitPattern: ~ FILE_ATTRIBUTE_READONLY)
472
+ guard file. withCString ( encodedAs: UTF16 . self, { SetFileAttributesW ( $0, readableAttributes) } ) else {
473
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
474
+ }
475
+ }
476
+
461
477
if ( ffd. dwFileAttributes & DWORD ( FILE_ATTRIBUTE_DIRECTORY) != 0 ) {
462
478
if file != " . " && file != " .. " {
463
479
dirStack. append ( itemPath)
0 commit comments