Scripts: refuse read-only export files, hidden rasterize sources and capture over write-only documents

- A multi-file export checks every destination before writing and refuses an
  existing read-only file, as save does, so no file is written.
- object.rasterize and Document.rasterize refuse an id that is hidden or in a
  hidden layer or group, as they refuse locked ones.
- imageCapture compares open documents and linked files that only a write root
  covers, so it no longer replaces such a document's file.
- The blank-capture test also checks the pixel count, as test-lint asks.
This commit is contained in:
dotCooCoo committed 2026-12-02 13:56:42 -08:00
1 parent b14d841476
commit b91beb68fd
6 files changed
+89 -17

No files matched your search

+24 -9
View File
@@ -299,8 +299,13 @@ fn sources_on_disk(h: &Host) -> Vec<Placed> {
paths.iter().filter_map(|p| source_place(p)).collect()
}
/// An open document or linked file inside the automation read or write roots: one that only a write
/// root covers is compared too, since a capture may write there. A path outside both is left out
/// before it is looked up, as no capture can write it; the refusal names only the requested path.
fn source_place(path: &str) -> Option<Placed> {
crate::file_access::check_read(path).ok()?;
if crate::file_access::check_read(path).is_err() && crate::file_access::check_write_unrecorded(path).is_err() {
return None;
}
placed(std::path::Path::new(path))
}
@@ -507,18 +512,28 @@ mod source_tests {
use super::*;
#[test]
fn capture_sources_exclude_files_outside_automation_roots() {
fn capture_sources_keep_files_outside_automation_read_roots() {
let dir = vectorcraft_testkit::TempDir::new("capture-source-roots");
let allowed = dir.join("allowed");
std::fs::create_dir(&allowed).unwrap();
let inside = allowed.join("doc.vectorcraft");
let outside = dir.join("linked.png");
let readable = dir.join("readable");
let writable = dir.join("writable");
std::fs::create_dir(&readable).unwrap();
std::fs::create_dir(&writable).unwrap();
let inside = readable.join("doc.vectorcraft");
// An open document that only a write root covers: a capture to its path must still be
// refused.
let outside = writable.join("other.vectorcraft");
// Outside every root: no capture can write it, so it is not looked up.
let elsewhere = dir.join("linked.png");
std::fs::write(&inside, b"document").unwrap();
std::fs::write(&outside, b"linked").unwrap();
let roots = crate::file_access::AutomationRoots::new(&[&allowed], &[&allowed]).unwrap();
std::fs::write(&outside, b"document").unwrap();
std::fs::write(&elsewhere, b"linked").unwrap();
let roots = crate::file_access::AutomationRoots::new(&[&readable], &[&writable]).unwrap();
crate::file_access::confine(roots.as_ref(), || {
assert!(source_place(&inside.to_string_lossy()).is_some());
assert!(source_place(&outside.to_string_lossy()).is_none());
assert!(source_place(&elsewhere.to_string_lossy()).is_none());
let source = source_place(&outside.to_string_lossy()).expect("a source outside the read roots is still compared");
let target = placed(&outside).unwrap();
assert!(same_file(&target, &source));
});
}
}