Skip to content

Foundation: support file system representation for long paths #4746

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
Jun 4, 2023

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Jun 4, 2023

This adjusts the file system representation accessor for a URL to support paths beyond MAX_PATH. We do not know what the use of the file system representation is, so we cannot provide the NT style path (\\?\-prefixed). Rather than using the filled in buffer, resolve the URL and then build the complete path copying that into a newly allocated buffer. This ensures that we always have sufficient space for the path without having to grow the buffer.

Linux gets away with the current implementation by setting the PATH_MAX to page size (4096). There may be some value in using the single implementation across the different platforms, but this will allow the Windows path to make progress even if it diverges from the reference implementation.

The issue was identified by the DocC test suite which quickly exceeds the length.

This adjusts the file system representation accessor for a URL to
support paths beyond `MAX_PATH`.  We do not know what the use of the
file system representation is, so we cannot provide the NT style path
(`\\?\`-prefixed).  Rather than using the filled in buffer, resolve the
URL and then build the complete path copying that into a newly allocated
buffer.  This ensures that we always have sufficient space for the path
without having to grow the buffer.

Linux gets away with the current implementation by setting the
`PATH_MAX` to page size (4096).  There may be some value in using the
single implementation across the different platforms, but this will
allow the Windows path to make progress even if it diverges from the
reference implementation.

The issue was identified by the DocC test suite which quickly exceeds
the length.
@compnerd
Copy link
Member Author

compnerd commented Jun 4, 2023

@swift-ci please test

#if os(Windows)
let bufSize = Int(MAX_PATH + 1)
if let resolved = CFURLCopyAbsoluteURL(_cfObject),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment here explaining why the Windows behavior needs to be different here but not in _wideFileSystemRepresentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that the `_wideFileSystemRepresentation will need to change. At that point, I'm more tempted to remove that function. Having different variants of the functions makes things more difficult to correctly refactor. That is, this is far more surgical than ideal. I can add a note on the wide variant that it needs to be updated and ideally removed.

The honest answer is: fixing a bug at a time. The reality is that most of the file system access routines for Windows need to be adjusted to use the NT path spelling, but that is also a good time to clean up some of the implementation to make it a bit less egregiously pessimistic (e.g. reusing encoded file paths, reusing stat information, etc).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this offline - I'll add the comment in a follow up. This is the first step towards fixing all the various cases in this file. The work is going to enable DocC and should also help potentially help make SPM and driver more reliable on Windows with extended paths.

@compnerd compnerd merged commit 11b0dbc into swiftlang:main Jun 4, 2023
@compnerd compnerd deleted the extensions branch June 4, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants