From: Ian Jackson Date: Sun, 2 May 2021 00:12:00 +0000 (+0100) Subject: bundles: Actually create the directory, on upload X-Git-Tag: otter-0.6.0~478 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fd636cb34894f49d21023c1ef916e0f3a91ee2fc;p=otter.git bundles: Actually create the directory, on upload Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index 154c409d..a8a02253 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -184,8 +184,22 @@ impl InstanceBundles { self.bundles.push(slot); let id = Id { kind, index }; let tmp = id.path_tmp(&ig.name); - let file = fs::File::create(&tmp) - .with_context(|| tmp.clone()).context("create").map_err(IE::from)?; + + let file = (|| Ok::<_,AE>({ + let mkf = || fs::File::create(&tmp); + match mkf() { + Ok(f) => f, + Err(e) if e.kind() == ErrorKind::NotFound => { + let d = b_dir(&ig.name); + fs::create_dir(&d).context("create containing directory")?; + mkf().context("crate (after creating containing directory)")? + } + e@ Err(_) => e.context("create")?, + } + }))() + .with_context(|| tmp.to_owned()).context("upload file") + .map_err(IE::from)?; + let file = BufWriter::new(file); let file = DigestWrite::new(file); let instance = ig.name.clone();