Save: a refused file in a save of several files is not given to the writer

When the file access in force refuses one of the files a save writes, the
save returns the access error before calling the writer, so a writer that
does not check the file access itself writes none of the files.
This commit is contained in:
dotCooCoo committed 2026-11-25 14:20:32 -08:00
1 parent bc99687e5e
commit 70e6f4e797
2 files changed
+6 -8

No files matched your search

+4 -6
View File
@@ -1071,15 +1071,13 @@ impl SaveJob {
return Ok(stopped);
}
// Every path is checked against the file access in force before the first file is
// written. A refused file goes to `write` first, which refuses it with the error the
// caller gives (naming the path as the caller does), so none of the files is written.
// written. When one is refused, the save returns that error and `write` is not called, so
// none of the files is written, also by a writer that does not check the file access.
#[cfg(not(target_arch = "wasm32"))]
if files.len() > 1
&& let Some((p, bytes)) = files.iter().find(|(p, _)| super::may_write(p).is_err())
&& let Some(e) = files.iter().find_map(|(p, _)| super::may_write(p).err())
{
write(p, bytes)?;
// A writer that does not check the file access writes none of the others.
return Err(super::may_write(p).err().unwrap_or_else(|| crate::EngineError::Other(format!("file access denied: {p}"))));
return Err(e);
}
for (i, (p, bytes)) in files.iter().enumerate() {
if i == 0 {
+2 -2
View File
@@ -208,7 +208,7 @@ fn a_save_writes_nothing_when_one_of_its_files_is_refused() {
}
/// When the writer a save is given does not check the file access itself, a save of several files
/// still writes none of them after the refused one.
/// with a refused one gives none of them to the writer.
#[test]
fn a_refused_file_stops_a_save_whose_writer_does_not_check() {
use crate::cmd::fileio::{SaveMode, save_job, save_plan};
@@ -247,7 +247,7 @@ fn a_refused_file_stops_a_save_whose_writer_does_not_check() {
});
assert!(r.is_err(), "{r:?}");
let refused = refused.unwrap();
assert_eq!(written, std::slice::from_ref(&refused), "only the refused file went to the writer");
assert!(written.is_empty(), "no file went to the writer: {written:?}");
let mut perms = std::fs::metadata(&refused).unwrap().permissions();
#[allow(clippy::permissions_set_readonly_false)]
perms.set_readonly(false);