Only update env_universal self.last_read_file on success

I don't think the existing logic is correct, as the comment says, our internal
state is only matched if we *actually* wrote out the file. But if we ran into an
error, it doesn't match, does it?
This commit is contained in:
Mahmoud Al-Qudsi 2024-03-09 21:32:58 -06:00 committed by Johannes Altmanninger
parent 94477f3029
commit 3f6b009870

View File

@ -536,9 +536,14 @@ impl EnvUniversal {
fn write_to_fd(&mut self, fd: impl AsFd, path: &wstr) -> std::io::Result<usize> { fn write_to_fd(&mut self, fd: impl AsFd, path: &wstr) -> std::io::Result<usize> {
let fd = fd.as_fd(); let fd = fd.as_fd();
let contents = Self::serialize_with_vars(&self.vars); let contents = Self::serialize_with_vars(&self.vars);
let res = write_loop(&fd, &contents);
if let Err(err) = res.as_ref() { let res = write_loop(&fd, &contents);
match res.as_ref() {
Ok(_) => {
// Since we just wrote out this file, it matches our internal state; pretend we read from it.
self.last_read_file = file_id_for_fd(fd.as_raw_fd());
}
Err(err) => {
let error = Errno(err.raw_os_error().unwrap()); let error = Errno(err.raw_os_error().unwrap());
FLOG!( FLOG!(
error, error,
@ -549,9 +554,7 @@ impl EnvUniversal {
), ),
); );
} }
}
// Since we just wrote out this file, it matches our internal state; pretend we read from it.
self.last_read_file = file_id_for_fd(fd.as_raw_fd());
// We don't close the file. // We don't close the file.
res res