api2/admin/datastore: log stream error during file download

the client cannot get an error during an chunked http transfer, so at
least log it server side

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-06-18 13:55:20 +02:00 committed by Dietmar Maurer
parent bde8e243cf
commit ba694720fc
1 changed files with 6 additions and 2 deletions

View File

@ -743,12 +743,16 @@ fn download_file(
path.push(backup_dir.relative_path());
path.push(&file_name);
let file = tokio::fs::File::open(path)
let file = tokio::fs::File::open(&path)
.map_err(|err| http_err!(BAD_REQUEST, format!("File open failed: {}", err)))
.await?;
let payload = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new())
.map_ok(|bytes| hyper::body::Bytes::from(bytes.freeze()));
.map_ok(|bytes| hyper::body::Bytes::from(bytes.freeze()))
.map_err(move |err| {
eprintln!("error during streaming of '{:?}' - {}", &path, err);
err
});
let body = Body::wrap_stream(payload);
// fixme: set other headers ?