Scripts: a renamed file's old path is named in the report's written

rename named only the new path in written, so a run that renamed a file an earlier run wrote did not name the path it emptied. It now names both, as remove names the path it deletes.
This commit is contained in:
dotCooCoo
2026-11-13 15:06:11 -08:00
parent 0300f70950
commit fb12ddb759
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -1763,6 +1763,8 @@ fn rename(host: &Host, a: &[Data]) -> Result<Data, HostError> {
file.target = Some(if rest.as_os_str().is_empty() { to.clone() } else { to.join(rest) });
}
}
// The old path no longer holds the file, so the report names it as well as the new one.
disk.wrote(&from);
disk.wrote(&to);
Ok(Data::Object(vec![("fs".into(), Data::String(new))]))
}
+23
View File
@@ -513,6 +513,29 @@ fn script_files_write_in_the_temporary_and_data_folders() {
let _ = std::fs::remove_dir_all(base);
}
/// `rename` of a file an earlier run wrote names both its old and its new path in `written`.
#[test]
fn a_renamed_file_names_its_old_and_new_paths_in_written() {
let base = folder("renamed");
let mut s = with_data(&base);
let first = run_in(&mut s, &base, "var u = new File(Folder.userData.fsName + '/old.txt'); u.open('w'); u.write('x'); vc.log(u.close());");
assert_eq!(first.unwrap()["log"], json!([true]));
let r = run_in(
&mut s,
&base,
"var u = new File(Folder.userData.fsName + '/old.txt'); var before = u.fsName;\n\
vc.log(u.rename('new.txt')); vc.log(before); vc.log(u.fsName);",
)
.unwrap();
assert_eq!(r["log"][0], json!(true));
let written: Vec<&str> = r["written"].as_array().unwrap().iter().filter_map(Value::as_str).collect();
for at in [1, 2] {
let path = r["log"][at].as_str().unwrap();
assert!(written.contains(&path), "{path} in {written:?}");
}
let _ = std::fs::remove_dir_all(base);
}
/// The open modes, the encodings that cannot hold a character, `copy` over a file, `remove` of a
/// folder only when it is empty, `rename` refusing a name in use, `create`, and setting `length` and
/// `readonly`.