Skip to content

Add fs::try_exists #4299

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

Merged
merged 9 commits into from
Feb 21, 2023
Merged

Add fs::try_exists #4299

merged 9 commits into from
Feb 21, 2023

Conversation

kevinkassimo
Copy link
Contributor

@kevinkassimo kevinkassimo commented Dec 4, 2021

Motivation

std has added Path::exists and (unstable) fs::try_exists. Adding try_exists to tokio::fs based on prior discussions in #3375 (which has not been updated for a while)

Solution

Add fs::try_exists function.
Fixes: #3373

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-fs Module: tokio/fs labels Dec 10, 2021
@Darksonn
Copy link
Contributor

Let's wait for std to stabilize try_exists. I'd rather not stabilize this, then see std change the signature of theirs so we don't match.

@isikkema
Copy link
Contributor

try_exists has now been stabilized in std rust-lang/rust#97912.
Perhaps this should be revisited?

@Darksonn
Copy link
Contributor

Sure! I see that it hasn't been released yet, but I would be happy to include our own version of it when that happens.

@just-chillin
Copy link

just-chillin commented Feb 20, 2023

Unless I'm misunderstanding looks like std::path::try_exists has been stabilized? rust-lang/rust@77316a4

Would you folks find it helpful if I contributed a version using Path::try_exists?

@Darksonn
Copy link
Contributor

Well, the documentation for fs::try_exists still says "This is a nightly-only experimental API". Once that changes, I would be happy with adding it to Tokio.

@kevinkassimo
Copy link
Contributor Author

Didn't realize there are more updates on this PR after 2 years. I can still update this PR to make it work with the latest Tokio version once the API is stablized.

@Darksonn
Copy link
Contributor

Ah, I see. It's been stabilized as Path::try_exists. That's an interesting situation because we don't have a Path type in Tokio. In that case, I am ok with adding an tokio::fs::try_exists as a replacement, since we cannot mirror what std is doing.

@kevinkassimo
Copy link
Contributor Author

kevinkassimo commented Feb 20, 2023

It seems that minrust is installing Rust 1.49.0 which is too hold for the feature? (at 1.63.0, already >= 6 months old) Can I update it in the ci.yml file?

@brody4hire
Copy link
Contributor

As an outside contributor, I would personally consider that to be a breaking change and vote for something that will work with Rust 1.49, if possible. From a quick search I found this: https://stackoverflow.com/questions/32384594/how-to-check-whether-a-path-exists

But some may not agree with me.

See https://doc.rust-lang.org/cargo/reference/semver.html#env-new-rust

@kevinkassimo
Copy link
Contributor Author

https://stackoverflow.com/questions/32384594/how-to-check-whether-a-path-exists

The was actually originally used in the implementation (before my recent sync). I can consider reverting it back if deemed better to use fs::metadata

@Darksonn
Copy link
Contributor

Ah, yes, we need to use an implementation that will work on 1.49. Sorry if that was unclear. My main concern was matching the API in std, but it turns out that they have chosen an API we cannot match, so I am ok with moving forward with an fs::try_exists instead.

@kevinkassimo
Copy link
Contributor Author

Updated implementation to use the exact fs::try_exists impl from std

@brody4hire
Copy link
Contributor

brody4hire commented Feb 20, 2023

Updated implementation to use the exact fs::try_exists impl from std

Another outsider comment I would kinda favor adding a comment with this info.


P.S. +1 on the explanatory comment added thanks!

@just-chillin
Copy link

Looks great! Thanks so much!

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@Darksonn Darksonn merged commit 12f81ff into tokio-rs:master Feb 21, 2023
@just-chillin
Copy link

🙌🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-fs Module: tokio/fs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tokio::fs::exists
5 participants