Fix File.exists? for special devices on Windows#15587
Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom Mar 24, 2025
Merged
Fix File.exists? for special devices on Windows#15587straight-shoota merged 2 commits intocrystal-lang:masterfrom
File.exists? for special devices on Windows#15587straight-shoota merged 2 commits intocrystal-lang:masterfrom
Conversation
File.exists?(File::NULL) on WindowsFile.exists? for special devices on Windows
straight-shoota
approved these changes
Mar 22, 2025
1 task
straight-shoota
pushed a commit
that referenced
this pull request
Apr 18, 2025
There are [7 types of user-space paths on Win32](https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html): * Drive-absolute (`C:\foo`) * Drive-relative (`C:foo`) * Rooted (`\foo`) * Relative (`foo`) * UNC absolute (`\\server\share\foo`) * Local device (`\\.\NUL`, `\\?\C:\foo`) * Root local device (`\\.`, `\\?`) Local device paths starting with exactly `\\?\` are also known as raw local device paths. Other than this prefix, all forward and backward slashes are interchangeable. `Path` already recognizes the first 5 of them; this PR adds the remaining 2. As noted in #15587, the `\\.\` prefix appears when dealing with special devices, such as `\\.\NUL` and `\\.\COM15`, as well as named pipes. The `\\?\` prefix is useful when passing paths to Win32 functions that are already normalized, or if the path exceeds 260 UTF-16 code units (see also #13420). This does not cover NT paths of the form `\??\...`. They appear in the reparse data area of Windows symbolic links.
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.
Fixes #15019.
Note that
File.realpath("nul")will now correctly return\\.\NUL. Support inPathwill be added shortly.