From fd636cb34894f49d21023c1ef916e0f3a91ee2fc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 May 2021 01:12:00 +0100 Subject: [PATCH] bundles: Actually create the directory, on upload Signed-off-by: Ian Jackson --- src/bundles.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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(); -- 2.30.2