-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Path still exists after remove successful on windows7 SP1 #112139
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
Comments
Would you be able to see what Btw, have you confirmed that 1.68.2 still works (to rule out CI changes)? |
Yes, I have confirmed that 1.68.2 still works. |
I made this little test program: use std::env;
use std::fs::File;
use std::path::Path;
fn main() {
let path = env::temp_dir().join("tempfile.txt");
let f = File::create(&path);
std::fs::remove_file(&path).unwrap();
println!("exists = {:?}", path.exists());
println!("metadata = {:?}", path.metadata());
println!("try_exists = {:?}", path.try_exists());
} 1.68.0 output:
1.69.0 output:
This seems to be caused by #107985, which seems to try getting file information using I'm not sure if this is really a bug now. From fiddling with the test a bit more, I was able to determine that the cause of the issue is keeping a file handle on the file being deleted. If I |
Ah yeah, that's how Windows 7 file deletion works. The delete only occurs when all file handles are closed. So it seems previously checking if the file exists was causing an ACCESS_DENIED error an the exists function interpreted any and all errors as the file not existing. The bug fix made it so that e.g. permission errors may not cause metadata to fail but also made it so that it will succeed even if a delete is pending. Windows 10 uses "POSIX semantics" under the hood so that the file is actually deleted right away. |
Per roblabla's remarks:
So I do not think this is a high priority bug in the absolute sense unless something else unexpected-yet-not-described is also a consequence of this, and it is also technically not a break of any semantic promise (we don't explicitly say "if you remove this file, then call In fact, if we consult
So perhaps we are obligated to close this as "wontfix"? Or perhaps there is some improvement or difference you would like to see? I will leave this open, as I am interested in what else people think. |
After sleeping on it, I'm going to boldly close this as "working as intended" but feel free to object and I'll (or someone else will) reopen. The bug here was actually the old versions of Rust that reported the file didn't exist when it absolutely still did. According to the previous Windows implementation of Of course the other view is that the behaviour of In short, this is just how Windows 7 works. In a way the unit test was always broken but the error was invisible because stdlib was lying to you. |
The Rust 1.69 update broke some fairly simple unit tests we have that runs on Windows7 SP1. Removing a file using
std::fs::remove_file
, and subsequently checking if it exists usingPath::exists
, will inexplicably return that the path still exists, instead of returning false.Note that this behavior is not reproduced on Windows10, only on Windows7.
Code
I expected to see this happen: The assertion succeeds, and "Path does not exist anymore" is printed.
Instead, this happened: The assertion fails, rust believes that the path still exists.
Version it worked on
It most recently worked on Rust 1.68.2
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
The text was updated successfully, but these errors were encountered: