diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-19 14:39:30 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-19 14:39:30 +0100 |
commit | fc427b0b66241785ecd3fe23ec3e4ac72aaed1da (patch) | |
tree | ea406de04a7a11c09c6d758ca97ba53fc2bdfbe4 /src/api/s3_copy.rs | |
parent | 6076d869b14aa38059d54a2dece222ad7b9da3bc (diff) | |
parent | 044d7988779aadac9290b58ceb077c1211670aed (diff) | |
download | garage-fc427b0b66241785ecd3fe23ec3e4ac72aaed1da.tar.gz garage-fc427b0b66241785ecd3fe23ec3e4ac72aaed1da.zip |
Merge branch 'master' into feature/website
Diffstat (limited to 'src/api/s3_copy.rs')
-rw-r--r-- | src/api/s3_copy.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs index db790d95..5997e4fe 100644 --- a/src/api/s3_copy.rs +++ b/src/api/s3_copy.rs @@ -6,13 +6,14 @@ use hyper::{Body, Response}; use garage_table::*; use garage_util::data::*; -use garage_util::error::Error; use garage_model::block_ref_table::*; use garage_model::garage::Garage; use garage_model::object_table::*; use garage_model::version_table::*; +use crate::error::*; + pub async fn handle_copy( garage: Arc<Garage>, dest_bucket: &str, @@ -20,25 +21,20 @@ pub async fn handle_copy( source_bucket: &str, source_key: &str, ) -> Result<Response<Body>, Error> { - let source_object = match garage + let source_object = garage .object_table .get(&source_bucket.to_string(), &source_key.to_string()) .await? - { - None => return Err(Error::NotFound), - Some(o) => o, - }; + .ok_or(Error::NotFound)?; - let source_last_v = match source_object + let source_last_v = source_object .versions() .iter() .rev() .filter(|v| v.is_complete()) .next() - { - Some(v) => v, - None => return Err(Error::NotFound), - }; + .ok_or(Error::NotFound)?; + let source_last_state = match &source_last_v.state { ObjectVersionState::Complete(x) => x, _ => unreachable!(), @@ -68,10 +64,7 @@ pub async fn handle_copy( .version_table .get(&source_last_v.uuid, &EmptyKey) .await?; - let source_version = match source_version { - Some(v) => v, - None => return Err(Error::NotFound), - }; + let source_version = source_version.ok_or(Error::NotFound)?; let dest_version = Version::new( new_uuid, |