]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/reader.rs: use tokio::fs::read() to read file async
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 7 Oct 2019 10:24:06 +0000 (12:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 7 Oct 2019 10:24:06 +0000 (12:24 +0200)
src/api2/reader.rs

index 0f721d97a0e16a72a2e319f1bff9f1d2a996183c..e93518fdef2198e26d165b6b9e9c863fd64f902e 100644 (file)
@@ -227,20 +227,25 @@ fn download_chunk(
     let digest = proxmox::tools::hex_to_digest(digest_str)?;
 
     let (path, _) = env.datastore.chunk_path(&digest);
+    let path2 = path.clone();
 
     env.debug(format!("download chunk {:?}", path));
 
-    let data = proxmox::tools::fs::file_get_contents(&path)?; // todo: blocking()
-    let body = Body::from(data);
-
-    // fixme: set other headers ?
-    Ok(Box::new(futures::future::ok(
-        Response::builder()
-            .status(StatusCode::OK)
-            .header(header::CONTENT_TYPE, "application/octet-stream")
-            .body(body)
-            .unwrap())
-    ))
+    let response_future = tokio::fs::read(path)
+        .map_err(move |err| http_err!(BAD_REQUEST, format!("redingfile {:?} failed: {}", path2, err)))
+        .and_then(move |data| {
+            let body = Body::from(data);
+
+            // fixme: set other headers ?
+            futures::future::ok(
+                Response::builder()
+                    .status(StatusCode::OK)
+                    .header(header::CONTENT_TYPE, "application/octet-stream")
+                    .body(body)
+                    .unwrap())
+        });
+
+    Ok(Box::new(response_future))
 }
 
 /* this is too slow