mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
Saves: a refused file of a save without a path is named by its file name
A save of several files without a path given (separateArtboards) refuses a file outside the write root before any file is written, and the error now names that file by its file name, as the error for the document's own file does. A path the client gives stays whole in the error.
This commit is contained in:
1 parent
fde921a744
commit
81a2dea0a4
1 file changed
+18
-6
@@ -602,6 +602,9 @@ pub struct SaveJob {
|
||||
stamped: Option<i64>,
|
||||
/// The artboards also saved to files of their own (`separateArtboards`).
|
||||
boards: Vec<usize>,
|
||||
/// Does a file the file access refuses before the first is written get named as
|
||||
/// [`super::access::naming_in_error`] names it (a save without a path given)?
|
||||
names_refused: bool,
|
||||
}
|
||||
|
||||
/// Writes the file at a path with what the filler it is given writes into it
|
||||
@@ -963,7 +966,7 @@ fn job_for_stamped(s: &Session, st: &DocState, plan: SavePlan, stamped: Option<i
|
||||
};
|
||||
super::check_linked_scripts(cmd, plan.format.id, st, &checked)?;
|
||||
super::access::check_native_images(cmd, plan.format.id, &st.doc, crate::cmd::links::LinkBase::of(st), &checked)?;
|
||||
Ok(SaveJob { plan, doc, params, snapshot, source: st.doc.clone(), stamped, boards })
|
||||
Ok(SaveJob { plan, doc, params, snapshot, source: st.doc.clone(), stamped, boards, names_refused: false })
|
||||
}
|
||||
|
||||
impl SaveJob {
|
||||
@@ -971,6 +974,13 @@ impl SaveJob {
|
||||
&self.plan
|
||||
}
|
||||
|
||||
/// The job, with a file the file access refuses before the first is written named in the
|
||||
/// error as [`super::access::naming_in_error`] names it: for a save without a path given.
|
||||
pub(crate) fn naming_refused_files(mut self) -> Self {
|
||||
self.names_refused = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// The document when the job was made (what counts as saved once the file is written).
|
||||
pub(crate) fn snapshot(&self) -> &Arc<Document> {
|
||||
&self.snapshot
|
||||
@@ -1072,12 +1082,13 @@ impl SaveJob {
|
||||
}
|
||||
// Every path is checked against the file access in force before the first file is
|
||||
// written. A refused file is refused here, so none of the files is written, also through
|
||||
// a `write` that does not check the file access itself.
|
||||
// a `write` that does not check the file access itself. The error names the file as the
|
||||
// job names refused files ([`SaveJob::naming_refused_files`]).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if files.len() > 1
|
||||
&& let Some(refused) = files.iter().find_map(|(p, _)| super::may_write(p).err())
|
||||
&& let Some((p, refused)) = files.iter().find_map(|(p, _)| super::may_write(p).err().map(|e| (p, e)))
|
||||
{
|
||||
return Err(refused);
|
||||
return Err(if self.names_refused { super::access::naming_in_error(refused, p) } else { refused });
|
||||
}
|
||||
for (i, (p, bytes)) in files.iter().enumerate() {
|
||||
if i == 0 {
|
||||
@@ -1235,9 +1246,10 @@ pub fn save_with(s: &mut Session, plan: SavePlan, write: impl FnMut(&str, &[u8])
|
||||
/// A save command: plan, then write with the file system (a native file as it is encoded).
|
||||
pub(crate) fn save(s: &mut Session, mode: SaveMode, p: &Value) -> Result<Value> {
|
||||
let plan = save_plan(s, mode, p)?;
|
||||
let job = save_job(s, plan)?;
|
||||
let uid = s.doc()?.uid;
|
||||
let given = str_param(p, "path").is_some_and(|g| !g.is_empty());
|
||||
let job = save_job(s, plan)?;
|
||||
let job = if given { job } else { job.naming_refused_files() };
|
||||
let uid = s.doc()?.uid;
|
||||
// Without a path, the files written are the document's own file and those beside it.
|
||||
let mut write = |path: &str, fill: &mut dyn FnMut(&mut dyn std::io::Write) -> std::io::Result<()>| {
|
||||
super::write_save_file_with(path, fill).map_err(|e| if given { e } else { super::access::naming_in_error(e, path) })
|
||||
|
||||
Reference in new issue
Block a user