fix: support paths longer than MAX_PATH on Windows - #446
Open
abhijeet117 wants to merge 1 commit into
Open
abhijeet117 wants to merge 1 commit into
abhijeet117 wants to merge 1 commit into
Conversation
Creating a NamedTempFile in a directory whose path exceeds the legacy MAX_PATH limit works because std converts paths to extended-length form internally, but keep() and persist() pass raw paths to SetFileAttributesW and MoveFileExW, which then fail with ERROR_PATH_NOT_FOUND (os error 3). Resolve the path against the current directory and convert it to the extended-length \\?\ form (UNC paths to \\?\UNC\server\share) before calling into Win32, falling back to the plain encoding if the conversion fails. Fixes Stebalien#444
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows, creating a
NamedTempFileat a path beyond the legacy MAX_PATH limit (260 characters) succeeds becausestdconverts paths to extended-length (\\?\) form internally, butkeep()andpersist()then fail with ERROR_PATH_NOT_FOUND (os error 3): they pass raw paths toSetFileAttributesWandMoveFileExW. This resolves the path against the current directory and converts it to extended-length form before those Win32 calls (UNC paths become\\?\UNC\...), falling back to the raw encoding if conversion fails.Testing
Reproduced on Windows with a nested temp directory tree over 260 characters: creation succeeded while
keep()and bothpersist()arms returned os error 3; all pass after the fix. Addedtest_windows_long_paths, which fails without the fix and passes with it. Fullcargo test --workspacegreen; clippy and fmt clean.Checklist