Skip to content

Commit 79eb533

Browse files
committed
FileManager: use the proper FSR on Windows
This converts the previous re-encoding of the string to the file system representation instead.
1 parent 6167997 commit 79eb533

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Foundation/FileManager.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,17 +1285,21 @@ public struct FileAttributeType : RawRepresentable, Equatable, Hashable {
12851285
self = .typeCharacterSpecial
12861286
} else if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_REPARSE_POINT) == DWORD(FILE_ATTRIBUTE_REPARSE_POINT) {
12871287
// A reparse point may or may not actually be a symbolic link, we need to read the reparse tag
1288-
let handle = path.withCString(encodedAs: UTF16.self) {
1289-
CreateFileW($0, /*dwDesiredAccess=*/DWORD(0), DWORD(FILE_SHARE_READ | FILE_SHARE_WRITE), /*lpSecurityAttributes=*/nil,
1290-
DWORD(OPEN_EXISTING), DWORD(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS), /*hTemplateFile=*/nil)
1291-
}
1292-
guard handle != INVALID_HANDLE_VALUE else {
1288+
let handle: HANDLE = (try? FileManager.default._fileSystemRepresentation(withPath: path) {
1289+
CreateFileW($0, /*dwDesiredAccess=*/DWORD(0),
1290+
DWORD(FILE_SHARE_READ | FILE_SHARE_WRITE),
1291+
/*lpSecurityAttributes=*/nil, DWORD(OPEN_EXISTING),
1292+
DWORD(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS),
1293+
/*hTemplateFile=*/nil)
1294+
}) ?? INVALID_HANDLE_VALUE
1295+
if handle == INVALID_HANDLE_VALUE {
12931296
self = .typeUnknown
12941297
return
12951298
}
12961299
defer { CloseHandle(handle) }
12971300
var tagInfo = FILE_ATTRIBUTE_TAG_INFO()
1298-
guard GetFileInformationByHandleEx(handle, FileAttributeTagInfo, &tagInfo, DWORD(MemoryLayout<FILE_ATTRIBUTE_TAG_INFO>.size)) else {
1301+
if !GetFileInformationByHandleEx(handle, FileAttributeTagInfo, &tagInfo,
1302+
DWORD(MemoryLayout<FILE_ATTRIBUTE_TAG_INFO>.size)) {
12991303
self = .typeUnknown
13001304
return
13011305
}

0 commit comments

Comments
 (0)