-
Notifications
You must be signed in to change notification settings - Fork 190
Transparently add the \\?\ prefix to Win32 calls for extended length path handling #1257
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
Transparently add the \\?\ prefix to Win32 calls for extended length path handling #1257
Conversation
@swift-ci test |
0a01e82
to
98a23cf
Compare
@swift-ci test |
98a23cf
to
423c2f4
Compare
@swift-ci test |
423c2f4
to
08b6fbe
Compare
@swift-ci test |
08b6fbe
to
85ab72d
Compare
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the labelling, LGTM
Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
Outdated
Show resolved
Hide resolved
Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
Outdated
Show resolved
Hide resolved
Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments on the unit test, but overall this looks good - thanks for putting this together! Added @jrflat as a reviewer as well just for another perspective from the URL
side of things in case there's any considerations/impact there.
…path handling On Windows, there is a built-in maximum path limitation of 260 characters under most conditions. This can be extended to 32767 characters under either of the following two conditions: - Adding the longPathAware attribute to the executable's manifest AND enabling the LongPathsEnabled system-wide registry key or group policy. - Ensuring fully qualified paths passed to Win32 APIs are prefixed with \?\ Unfortunately, the former is not realistic for the Swift ecosystem, since it requires developers to have awareness of this specific Windows limitation, AND set longPathAware in their apps' manifest AND expect end users of those apps to change their system configuration. Instead, this patch transparently prefixes all eligible paths in calls to Win32 APIs with the \?\ prefix to allow them to work with paths longer than 260 characters without requiring the caller of Foundation to manually prefix the paths. See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation for more info.
85ab72d
to
64763e2
Compare
@swift-ci test |
Thanks @jmschonfeld and @compnerd; I've addressed all your feedback so far. |
@jakepetroules any chance that we might be able to pull this into 6.2 as well? 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all good for URL
's use-case, thanks!
Happy to -- @jmschonfeld / @parkera, is your team doing regular merges from main to 6.2 or should I manually bring it over? |
// 1. Normalize the path first. | ||
// Contrary to the documentation, this works on long paths independently | ||
// of the registry or process setting to enable long paths (but it will also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it states the truth on this page instead of the docs for GetFullPathName itself:
You can pass paths of more than
MAX_PATH
characters to GetFullPathName without\\?\
. It supports arbitrary length paths up to the maximum string size that Windows can handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
@parkera / @itingliu can confirm but I believe our plan is to have periodic merges from |
…path handling This simply updates the implementation of withNTPathRepresentation with what's about to be merged into Foundation via swiftlang/swift-foundation#1257
On Windows, there is a built-in maximum path limitation of 260 characters under most conditions. This can be extended to 32767 characters under either of the following two conditions:
Unfortunately, the former is not realistic for the Swift ecosystem, since it requires developers to have awareness of this specific Windows limitation, AND set longPathAware in their apps' manifest AND expect end users of those apps to change their system configuration.
Instead, this patch transparently prefixes all eligible paths in calls to Win32 APIs with the ?\ prefix to allow them to work with paths longer than 260 characters without requiring the caller of Foundation to manually prefix the paths.
See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation for more info.