aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_put.rs
diff options
context:
space:
mode:
authorQuentin <quentin@deuxfleurs.fr>2020-11-11 16:12:42 +0100
committerQuentin <quentin@deuxfleurs.fr>2020-11-11 16:12:42 +0100
commit5a5592c176c7a17f143d0f221b6495808b7f4054 (patch)
treee368b58121f4ae5822528e54d4d8ded8c2eb2dba /src/api/s3_put.rs
parent045009da9b7ac4198574bd5aa256c11cfe4ae469 (diff)
downloadgarage-5a5592c176c7a17f143d0f221b6495808b7f4054.tar.gz
garage-5a5592c176c7a17f143d0f221b6495808b7f4054.zip
Replace with option syntaxic sugar
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()