Skip to content

FileManager: correct symbolic link handling on Windows #2660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,17 @@ extension FileManager {
}

let substituteNameBuff = Data(bytes: pathBufferPtr + substituteNameOffset, count: substituteNameBytes)
guard let substitutePath = String(data: substituteNameBuff, encoding: .utf16LittleEndian) else {
guard var substitutePath = String(data: substituteNameBuff, encoding: .utf16LittleEndian) else {
throw _NSErrorWithWindowsError(DWORD(ERROR_INVALID_DATA), reading: false)
}

// Canonicalize the NT Object Manager Path to the DOS style path
// instead. Unfortunately, there is no nice API which can allow us to
// do this in a guranteed way.
let kObjectManagerPrefix = "\\??\\"
if substitutePath.hasPrefix(kObjectManagerPrefix) {
substitutePath = String(substitutePath.dropFirst(kObjectManagerPrefix.count))
}
return substitutePath
}

Expand Down