-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add an exists method to FileSystem #271
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
base: main
Are you sure you want to change the base?
Conversation
This change adds an `exists` method to the `FileSystem` class, along with implementations for POSIX and Windows. The POSIX implementation uses `lstat` to check for the existence of a file system object. The Windows implementation uses `CreateFile`. Tests have been added to cover files, directories, links (including broken ones), and non-existent paths. I was unable to run the tests locally due to issues with the test environment, so I am relying on the CI to validate these changes.
/// If `path` is a symbolic link, `exists` returns `false` if the link is | ||
/// broken (i.e. the target of the link does not exist). | ||
/// | ||
/// On Windows, calling `exists` on a named pipe may cause the server to close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds unexpected: it is surprising that exists
can cause change to any state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exists
call CreateFile
, which opens the file. dart:io
(sometimes) has the same behavior (and so does Python, Rust, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about making exists
not follow the symlink so that it doesn't need to open the file. But that does against the current behavior of dart:io
(and Python and Rust...)
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.