Skip to content
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

Use lstat() semantics for URL directory detection #1204

Merged
merged 4 commits into from
Mar 7, 2025

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Mar 6, 2025

Historically, NS/URL checks if a path is a directory using getattrlist with FSOPT_NOFOLLOW. This is equivalent to lstat() in the sense that it won't follow a symlink at the end of the path, and it will report information about the symlink itself.

In the Swift URL implementation, I called into FileManager to check if a path is a directory, but FileManager uses stat() for this purpose (and historically always has).

Since URL historically doesn't follow a symlink at the end of the path, this PR switches to using lstat() on UNIX-like platforms instead of calling into FileManager.

On Windows, we can create the file handle with FILE_FLAG_OPEN_REPARSE_POINT and check for the flag to achieve the same semantics.

@jrflat
Copy link
Contributor Author

jrflat commented Mar 6, 2025

@swift-ci please test

@jrflat
Copy link
Contributor Author

jrflat commented Mar 6, 2025

@swift-ci please test

@jrflat
Copy link
Contributor Author

jrflat commented Mar 6, 2025

@swift-ci please test

@jrflat jrflat requested review from compnerd and jmschonfeld March 7, 2025 19:22
@jrflat
Copy link
Contributor Author

jrflat commented Mar 7, 2025

@swift-ci please test

@jrflat jrflat merged commit f751db3 into swiftlang:main Mar 7, 2025
3 checks passed
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.

3 participants