Skip to content

Commit 08f2025

Browse files
authored
FileManager: correct API misuse on Windows (#3049)
`GetVolumeInformationW` is documented as taking the root directory of the volume to describe as `lpRootPathName`. We attempt to compute the location by determining the volume mount point where the specified path is mounted. However, `GetVolumePathNameW` does always return the path to the volume mount point, which is the root of the volume where the specified path. With a path substitution that is not rooted at a volume root, the volume root with a relative path. As we need to get to the root, force the stripping to the root via `PathCchStripToRoot`. This should repair the TestFoundation.TestFileManager/test_filesystemAttributes on Windows.
1 parent 97da7f6 commit 08f2025

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Sources/Foundation/FileManager+Win32.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ extension FileManager {
269269
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [path])
270270
}
271271

272+
let hr: HRESULT = PathCchStripToRoot(&szVolumePath, szVolumePath.count)
273+
guard hr == S_OK || hr == S_FALSE else {
274+
throw _NSErrorWithWindowsError(DWORD(hr & 0xffff), reading: true, paths: [path])
275+
}
276+
272277
var volumeSerialNumber: DWORD = 0
273278
guard GetVolumeInformationW(&szVolumePath, nil, 0, &volumeSerialNumber, nil, nil, nil, 0) else {
274279
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [path])

0 commit comments

Comments
 (0)