Scripts: a file whose close could not write it stays open, so a later close tries again

This commit is contained in:
dotCooCoo
2026-11-13 10:31:59 -08:00
parent dbfffc8ecb
commit b153a3d7a6
3 changed files with 22 additions and 3 deletions
+15
View File
@@ -730,6 +730,21 @@ fn script_file_copy_of_an_open_file_has_its_changes() {
let _ = std::fs::remove_dir_all(base);
}
/// A file whose `close` could not write it stays open, so a later `close` writes it.
#[test]
fn script_file_close_that_fails_can_be_tried_again() {
let base = folder("closeagain");
let r = run(
&base,
"var d = Folder.temp.fsName, f = new File(d + '/f.txt'); f.open('w'); f.write('kept');\n\
new File(f.fsName).readonly = true; var out = [f.close(), f.error];\n\
new File(f.fsName).readonly = false; out.push(f.close());\n\
var g = new File(f.fsName); g.open('r'); out.push(g.read()); g.close(); vc.log(out);",
);
assert_eq!(r["log"], json!([[false, "Script file could not be written", true, "kept"]]));
let _ = std::fs::remove_dir_all(base);
}
/// `copy` gives the copy the source's permissions: the copy of a read-only file is read-only.
#[test]
fn script_file_copy_keeps_the_source_read_only() {
+5 -2
View File
@@ -220,14 +220,17 @@ fn is_open(i: &Interp, o: ObjId) -> JsResult<Option<Value>> {
}
/// Closes the object's open file, if it has one, which writes what the script wrote to it. → false
/// after setting `error` when that could not be written.
/// after setting `error` when that could not be written; the file then stays open, so a later
/// `close` tries again.
fn close_open(i: &mut Interp, o: ObjId) -> JsResult<bool> {
let mut written = true;
if let Some(h) = is_open(i, o)? {
let r = host(i, "close", &[h])?;
written = outcome(i, o, &r)?;
}
set_slot(i, o, HANDLE, Value::Number(-1.0))?;
if written {
set_slot(i, o, HANDLE, Value::Number(-1.0))?;
}
Ok(written)
}
+2 -1
View File
@@ -2300,7 +2300,8 @@ VectorCraft writes files by these rules of its own:
`Script file access denied`.
- What a script writes is written when it closes the file or when the run ends, also when the run fails. At the
run's end the files left open are written in the order they were opened. A file
that `close` could not write is written again when the run ends, and a `write` that would pass the run's limit
that `close` could not write stays open, so a later `close` tries again, and is written again when the run ends; a
`write` that would pass the run's limit
is not written. A run that
would otherwise succeed fails when a changed file it left open cannot be written, with
`Error: the script left open files that could not be written` and the files' paths. One file