mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-19 02:26:48 +00:00
M12: a signed file that can't be written leaves the preSign step pending, or takes it back
This commit is contained in:
1 parent
2c64968411
commit
a756832dd5
3 files changed
+30
-2
No files matched your search
@@ -307,7 +307,14 @@ impl Automation {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
write_atomic(&out, &signed)?;
|
||||
if let Err(e) = write_atomic(&out, &signed) {
|
||||
// Not saved, so not signed: what the preSign scripts did is taken back too.
|
||||
if before {
|
||||
let _ = self.session.undo(doc_id);
|
||||
let _ = self.session.take_js_output(doc_id);
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
let path = out.to_string_lossy().into_owned();
|
||||
self.session.mark_signed(doc_id, signed.clone(), Some(path.clone())).map_err(failed)?;
|
||||
// Then its postSign scripts; what they change is a change after signing, not saved yet.
|
||||
|
||||
@@ -5804,6 +5804,23 @@ fn signing_an_xfa_box_runs_its_signing_scripts_through_tools() {
|
||||
"{unasked}"
|
||||
);
|
||||
let doc = ok(&mut a, "doc_open", json!({ "path": "form.pdf" }))["doc"].as_u64().unwrap();
|
||||
// A signed file that can't be written (`out` is a folder): not signed, and what preSign did
|
||||
// is taken back.
|
||||
std::fs::create_dir_all(dir.join("taken")).unwrap();
|
||||
let failed = a.call(
|
||||
"sign_document",
|
||||
&json!({ "doc": doc, "id": "ada.p12", "password": "secret12", "field": name("sign"), "out": "taken", "run_form_scripts": true }),
|
||||
);
|
||||
assert!(failed.is_err(), "{failed:?}");
|
||||
let now = ok(&mut a, "form_fields", json!({ "doc": doc }));
|
||||
assert!(
|
||||
now["fields"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|f| f["name"].as_str().is_some_and(|n| n == "when" || n.ends_with(".when[0]")) && f["value"].is_null()),
|
||||
"{now}"
|
||||
);
|
||||
let r = ok(
|
||||
&mut a,
|
||||
"sign_document",
|
||||
|
||||
@@ -520,7 +520,11 @@ impl PdfCraftApp {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
};
|
||||
crate::editing::write_atomically(&path.to_string_lossy(), signed.as_slice()).map_err(|e| format!("Could not save: {e}"))?;
|
||||
if let Err(e) = crate::editing::write_atomically(&path.to_string_lossy(), signed.as_slice()) {
|
||||
// Not saved, so not signed: the preSign step stays pending as well.
|
||||
app.presign = pending;
|
||||
return Err(format!("Could not save: {e}"));
|
||||
}
|
||||
// Our own write is not a change on disk to reload (#431).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
app.watch.known_now(doc_id, &path.to_string_lossy());
|
||||
|
||||
Reference in new issue
Block a user