-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Observe close(2) errors for std::fs::{copy, write}
#149834
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
|
rustbot has assigned @Mark-Simulacrum. Use |
ab5eab8 to
38e2c5b
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
||
| io::copy(&mut reader, &mut writer) | ||
| let ret = io::copy(&mut reader, &mut writer)?; | ||
| writer.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.
Even though this can't fail, I copied it for symmetry with the other implementations.
This comment has been minimized.
This comment has been minimized.
38e2c5b to
cac4eb5
Compare
This comment has been minimized.
This comment has been minimized.
Adds a (private to `std`) `File::close` method and uses it in `std::fs::write` and `std::fs::copy`. This is a lighter version of rust-lang/libs-team#705 that can be added even if that ACP isn't accepted, as this is purely a quality of implementation thing that could be reverted at any time. External libraries and applications can use external crates like https://crates.io/crates/close-err to achieve the same with the files they own. CC rust-lang/libs-team#705.
cac4eb5 to
f7e0a04
Compare
|
So I don't see why these practically least-effort methods are the ones that would warrant extra care. Such a PR might be more appropriate to atomic write crates... except that they already do fsync, which subsumes this. |
|
We're just returning the error from |
|
Well, I both do not like the precedent, and I also think that if anything really needs to do this then these are the methods where it's the least necessary, which makes the first point worse "look, even these simple, least-defensive std methods do it!" |
|
I'm personally not a huge fan of incrementally doing this in semi-random places in the standard library that operate on files internally and happen to already handle some errors. At minimum, it makes it harder to read code by adding extra operations. I'm going to mark this waiting on T-libs. I think it makes sense for T-libs and T-libs-api to discuss what we want as policy here for internal implementations and external implementations before we land changes either way. |
I tried to not make it "semi-random places in the standard library", but "all places in the standard library that drop a file after writing to it", i.e. all the places where the calling code can't close the file itself. |
Why does this need T-libs/T-libs-api decisions on policy? This looks like a simple quality of implementation thing. It does not regress any use cases. It improves some (see rust-lang/libs-team#705). It doesn't do anything special a normal rust crate couldn't do. It can be reverted if it causes problems. It's not a huge diff, so it's not hard to maintain. |
Adds a (private to
std)File::closemethod and uses it instd::fs::writeandstd::fs::copy.This is a lighter version of rust-lang/libs-team#705 that can be added even if that ACP isn't accepted, as this is purely a quality of implementation thing that could be reverted at any time. External libraries and applications can use external crates like https://crates.io/crates/close-err to achieve the same with the files they own.
CC rust-lang/libs-team#705.