chiark / gitweb /
bundles download: Use Namedfile
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 May 2021 02:37:23 +0000 (03:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 May 2021 11:28:51 +0000 (12:28 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/main.rs

index 03a39249f5fc25d700845aeac481c5cd3766268f..54d9c5adb841f5ace0012d4bc0c49829fb4f50f5 100644 (file)
@@ -247,12 +247,16 @@ fn bundle<'r>(instance: Parse<InstanceName>,
     let ig = ig.by_ref(Authorisation::authorise_any());
     ig.asset_url_key.check("bundle", &(instance, id), &token)?
   }.map(|(_,id)| id);
-  let f = id.open_by_name(instance, auth).map_err(IE::from)?;
+  let path = id.path(&ig, auth);
+  let f = match rocket::response::NamedFile::open(&path) {
+    Err(e) if e.kind() == ErrorKind::NotFound => throw!(BDE::NotFound),
+    Err(e) => throw!(IE::from(AE::from(e).context(path).context("bundle"))),
+    Ok(y) => y,
+  };
   let ctype = match id.kind {
     bundles::Kind::Zip => ContentType::ZIP,
   };
-  if_let!{ Some(f) = f; else throw!(BundleDownloadError::NotFound) }
-  Content(ctype, rocket::response::Stream::from(f))
+  Content(ctype, f)
 }
 
 #[derive(Debug,Copy,Clone)]