chiark / gitweb /
bundles: Actually create the directory, on upload
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 May 2021 00:12:00 +0000 (01:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 May 2021 00:12:00 +0000 (01:12 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bundles.rs

index 154c409db296756af74656f71ac163c1fd96b557..a8a02253f1c0f9a02a3919709d431465dd980c6c 100644 (file)
@@ -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();