Skip to content

Commit 2b7fe7e

Browse files
committed
Make try_exists return Ok(true) for Windows UDS
`fs::try_exists` currently fails on Windows if encountering a Unix Domain Socket (UDS). Fix this by checking for an error code that's returned when there's a failure to use a reparse point. A reparse point is a way to invoke a filesystem filter on a file instead of the file being opened normally. This is used to implement symbolic links (by redirecting to a different path) but also to implement other types of special files such as Unix domain sockets. If the reparse point is not a link type then opening it with `CreateFileW` may fail with `ERROR_CANT_ACCESS_FILE` because the filesystem filter does not implement that operation. This differs from resolving links which may fail with errors such as `ERROR_FILE_NOT_FOUND` or `ERROR_CANT_RESOLVE_FILENAME`. So `ERROR_CANT_ACCESS_FILE` means that the file exists but that we can't open it normally. Still, the file does exist so `try_exists` should report that as `Ok(true)`.
1 parent 130ff8c commit 2b7fe7e

File tree

1 file changed

+7
-0
lines changed
  • library/std/src/sys/windows

1 file changed

+7
-0
lines changed

Diff for: library/std/src/sys/windows/fs.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,13 @@ pub fn try_exists(path: &Path) -> io::Result<bool> {
15151515
// as the file existing.
15161516
_ if e.raw_os_error() == Some(c::ERROR_SHARING_VIOLATION as i32) => Ok(true),
15171517

1518+
// `ERROR_CANT_ACCESS_FILE` means that a file exists but that the
1519+
// reparse point could not be handled by `CreateFile`.
1520+
// This can happen for special files such as:
1521+
// * Unix domain sockets which you need to `connect` to
1522+
// * App exec links which require using `CreateProcess`
1523+
_ if e.raw_os_error() == Some(c::ERROR_CANT_ACCESS_FILE as i32) => Ok(true),
1524+
15181525
// Other errors such as `ERROR_ACCESS_DENIED` may indicate that the
15191526
// file exists. However, these types of errors are usually more
15201527
// permanent so we report them here.

0 commit comments

Comments
 (0)