tokio icon indicating copy to clipboard operation
tokio copied to clipboard

Add `fs::try_exists`

Open kevinkassimo opened this issue 3 years ago • 3 comments

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

kevinkassimo avatar Dec 04 '21 20:12 kevinkassimo

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.

Darksonn avatar Dec 10 '21 11:12 Darksonn

try_exists has now been stabilized in std https://github.com/rust-lang/rust/pull/97912. Perhaps this should be revisited?

isikkema avatar Aug 25 '22 14:08 isikkema

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.

Darksonn avatar Aug 26 '22 08:08 Darksonn

Unless I'm misunderstanding looks like std::path::try_exists has been stabilized? https://github.com/rust-lang/rust/commit/77316a4aaa0029481397ff2e43f57e60d5226569

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

just-chillin avatar Feb 20 '23 21:02 just-chillin

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.

Darksonn avatar Feb 20 '23 21:02 Darksonn

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.

kevinkassimo avatar Feb 20 '23 21:02 kevinkassimo

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.

Darksonn avatar Feb 20 '23 21:02 Darksonn

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?

kevinkassimo avatar Feb 20 '23 21:02 kevinkassimo

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

brody4hire avatar Feb 20 '23 22:02 brody4hire

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

kevinkassimo avatar Feb 20 '23 22:02 kevinkassimo

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.

Darksonn avatar Feb 20 '23 22:02 Darksonn

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

kevinkassimo avatar Feb 20 '23 23:02 kevinkassimo

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!

brody4hire avatar Feb 20 '23 23:02 brody4hire

Looks great! Thanks so much!

just-chillin avatar Feb 21 '23 00:02 just-chillin

🙌🏻

just-chillin avatar Feb 21 '23 14:02 just-chillin