Remove panics
This commit is contained in:
parent
e67f476ca4
commit
d363c00347
2 changed files with 29 additions and 8 deletions
|
|
@ -56,14 +56,26 @@ pub async fn run(args: &Args, dry_run: bool) {
|
||||||
let mut errors = 0;
|
let mut errors = 0;
|
||||||
|
|
||||||
for m in &moves {
|
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;
|
let mut copy_ok = true;
|
||||||
|
|
||||||
for dst in &m.to_add {
|
for dst in &m.to_add {
|
||||||
let src_url = format!("{src}/{}", m.key);
|
let src_url = format!("{src}/{}", m.key);
|
||||||
match client.get(&src_url).send().await {
|
match client.get(&src_url).send().await {
|
||||||
Ok(resp) if resp.status().is_success() => {
|
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);
|
let dst_url = format!("{dst}/{}", m.key);
|
||||||
if let Err(e) = client.put(&dst_url).body(data).send().await {
|
if let Err(e) = client.put(&dst_url).body(data).send().await {
|
||||||
eprintln!(" ERROR copy {} to {}: {}", m.key, dst, e);
|
eprintln!(" ERROR copy {} to {}: {}", m.key, dst, e);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ pub async fn get_key(
|
||||||
Path(key): Path<String>,
|
Path(key): Path<String>,
|
||||||
) -> Result<Response, AppError> {
|
) -> Result<Response, AppError> {
|
||||||
let record = state.db.get(&key).await?;
|
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}");
|
let location = format!("{vol}/{key}");
|
||||||
Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, location)]).into_response())
|
Ok((StatusCode::FOUND, [(axum::http::header::LOCATION, location)]).into_response())
|
||||||
}
|
}
|
||||||
|
|
@ -60,10 +60,17 @@ pub async fn put_key(
|
||||||
|
|
||||||
let mut failed = false;
|
let mut failed = false;
|
||||||
for handle in handles {
|
for handle in handles {
|
||||||
if let Err(e) = handle.await.unwrap() {
|
match handle.await {
|
||||||
|
Ok(Err(e)) => {
|
||||||
tracing::error!("{e}");
|
tracing::error!("{e}");
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("volume write task failed: {e}");
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
Ok(Ok(())) => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if failed {
|
if failed {
|
||||||
|
|
@ -92,8 +99,10 @@ pub async fn delete_key(
|
||||||
handles.push(tokio::spawn(async move { client.delete(&url).send().await }));
|
handles.push(tokio::spawn(async move { client.delete(&url).send().await }));
|
||||||
}
|
}
|
||||||
for handle in handles {
|
for handle in handles {
|
||||||
if let Err(e) = handle.await.unwrap() {
|
match handle.await {
|
||||||
tracing::error!("DELETE from volume failed: {e}");
|
Ok(Err(e)) => tracing::error!("DELETE from volume failed: {e}"),
|
||||||
|
Err(e) => tracing::error!("volume delete task failed: {e}"),
|
||||||
|
Ok(Ok(_)) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue