aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_put.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_put.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_put.rs')
-rw-r--r--src/api/s3_put.rs34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs
index ea09524c..72613323 100644
--- a/src/api/s3_put.rs
+++ b/src/api/s3_put.rs
@@ -37,10 +37,7 @@ pub async fn handle_put(
let body = req.into_body();
let mut chunker = BodyChunker::new(body, garage.config.block_size);
- let first_block = match chunker.next().await? {
- Some(x) => x,
- None => vec![],
- };
+ let first_block = chunker.next().await?.unwrap_or(vec![]);
let mut object_version = ObjectVersion {
uuid: version_uuid,
@@ -325,14 +322,9 @@ pub async fn handle_put_part(
let (object, first_block) = futures::try_join!(get_object_fut, get_first_block_fut)?;
// Check object is valid and multipart block can be accepted
- let first_block = match first_block {
- None => return Err(Error::BadRequest(format!("Empty body"))),
- Some(x) => x,
- };
- let object = match object {
- None => return Err(Error::BadRequest(format!("Object not found"))),
- Some(x) => x,
- };
+ let first_block = first_block.ok_or(Error::BadRequest(format!("Empty body")))?;
+ let object = object.ok_or(Error::BadRequest(format!("Object not found")))?;
+
if !object
.versions()
.iter()
@@ -392,10 +384,8 @@ pub async fn handle_complete_multipart_upload(
garage.object_table.get(&bucket, &key),
garage.version_table.get(&version_uuid, &EmptyKey),
)?;
- let object = match object {
- None => return Err(Error::BadRequest(format!("Object not found"))),
- Some(x) => x,
- };
+ let object = object.ok_or(Error::BadRequest(format!("Object not found")))?;
+
let object_version = object
.versions()
.iter()
@@ -408,10 +398,8 @@ pub async fn handle_complete_multipart_upload(
}
Some(x) => x.clone(),
};
- let version = match version {
- None => return Err(Error::BadRequest(format!("Version not found"))),
- Some(x) => x,
- };
+ let version = version.ok_or(Error::BadRequest(format!("Version not found")))?;
+
if version.blocks().len() == 0 {
return Err(Error::BadRequest(format!("No data was uploaded")));
}
@@ -474,10 +462,8 @@ pub async fn handle_abort_multipart_upload(
.object_table
.get(&bucket.to_string(), &key.to_string())
.await?;
- let object = match object {
- None => return Err(Error::BadRequest(format!("Object not found"))),
- Some(x) => x,
- };
+ let object = object.ok_or(Error::BadRequest(format!("Object not found")))?;
+
let object_version = object
.versions()
.iter()