Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brianquinlan
Copy link
Contributor

@brianquinlan brianquinlan commented Aug 15, 2025

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

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.
@brianquinlan brianquinlan requested a review from aam August 15, 2025 19:10
/// 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
Copy link

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.

Copy link
Contributor Author

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.)

Copy link
Contributor Author

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...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants