Remove panics

This commit is contained in:
Silas Brack 2026-03-07 16:06:51 +01:00
parent e67f476ca4
commit d363c00347
2 changed files with 29 additions and 8 deletions

View file

@ -56,14 +56,26 @@ pub async fn run(args: &Args, dry_run: bool) {
let mut errors = 0;
for m in &moves {
let src = &m.current_volumes[0];
let Some(src) = m.current_volumes.first() else {
eprintln!(" SKIP {} : no source volume", m.key);
errors += 1;
continue;
};
let mut copy_ok = true;
for dst in &m.to_add {
let src_url = format!("{src}/{}", m.key);
match client.get(&src_url).send().await {
Ok(resp) if resp.status().is_success() => {
let data = resp.bytes().await.unwrap();
let data = match resp.bytes().await {
Ok(b) => b,
Err(e) => {
eprintln!(" ERROR read body {} from {}: {}", m.key, src, e);
copy_ok = false;
errors += 1;
break;
}
};
let dst_url = format!("{dst}/{}", m.key);
if let Err(e) = client.put(&dst_url).body(data).send().await {
eprintln!(" ERROR copy {} to {}: {}", m.key, dst, e);

View file

@ -20,7 +20,7 @@ pub async fn get_key(
Path(key): Path<String>,
) -> Result<Response, AppError> {
let record = state.db.get(&key).await?;
let vol = &record.volumes[0];
let vol = record.volumes.first().ok_or(AppError::NotFound)?;
let location = format!("{vol}/{key}");
Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, location)]).into_response())
}
@ -60,10 +60,17 @@ pub async fn put_key(
let mut failed = false;
for handle in handles {
if let Err(e) = handle.await.unwrap() {
match handle.await {
Ok(Err(e)) => {
tracing::error!("{e}");
failed = true;
}
Err(e) => {
tracing::error!("volume write task failed: {e}");
failed = true;
}
Ok(Ok(())) => {}
}
}
if failed {
@ -92,8 +99,10 @@ pub async fn delete_key(
handles.push(tokio::spawn(async move { client.delete(&url).send().await }));
}
for handle in handles {
if let Err(e) = handle.await.unwrap() {
tracing::error!("DELETE from volume failed: {e}");
match handle.await {
Ok(Err(e)) => tracing::error!("DELETE from volume failed: {e}"),
Err(e) => tracing::error!("volume delete task failed: {e}"),
Ok(Ok(_)) => {}
}
}