aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_copy.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2020-11-11 16:38:56 +0100
committerAlex <alex@adnab.me>2020-11-11 16:38:56 +0100
commitb00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200 (patch)
treee0e8e02ddaed445ec331342c2b4328829accd889 /src/api/s3_copy.rs
parent045009da9b7ac4198574bd5aa256c11cfe4ae469 (diff)
parent7d7b9e95a9b7fe71e7bb42b08a22698475a9c78c (diff)
downloadgarage-b00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200.tar.gz
garage-b00e29f931dcfe79b766e2c5b2c9ddb5f6a2f200.zip
Merge pull request 'Option Type: replace pattern matching by the corresponding syntaxic sugar' (#13) from feature/syntaxic-sugar into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/13
Diffstat (limited to 'src/api/s3_copy.rs')
-rw-r--r--src/api/s3_copy.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/api/s3_copy.rs b/src/api/s3_copy.rs
index 4280f4bf..5997e4fe 100644
--- a/src/api/s3_copy.rs
+++ b/src/api/s3_copy.rs
@@ -21,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!(),
@@ -69,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,