diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 16:12:42 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-11-11 16:12:42 +0100 |
commit | 5a5592c176c7a17f143d0f221b6495808b7f4054 (patch) | |
tree | e368b58121f4ae5822528e54d4d8ded8c2eb2dba /src/api/s3_delete.rs | |
parent | 045009da9b7ac4198574bd5aa256c11cfe4ae469 (diff) | |
download | garage-5a5592c176c7a17f143d0f221b6495808b7f4054.tar.gz garage-5a5592c176c7a17f143d0f221b6495808b7f4054.zip |
Replace with option syntaxic sugar
Diffstat (limited to 'src/api/s3_delete.rs')
-rw-r--r-- | src/api/s3_delete.rs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/api/s3_delete.rs b/src/api/s3_delete.rs index 33e47c17..f46bfcfe 100644 --- a/src/api/s3_delete.rs +++ b/src/api/s3_delete.rs @@ -16,17 +16,11 @@ async fn handle_delete_internal( bucket: &str, key: &str, ) -> Result<(UUID, UUID), Error> { - let object = match garage + let object = garage .object_table .get(&bucket.to_string(), &key.to_string()) .await? - { - None => { - // No need to delete - return Err(Error::NotFound); - } - Some(o) => o, - }; + .ok_or(Error::NotFound)?; // No need to delete let interesting_versions = object.versions().iter().filter(|v| match v.state { ObjectVersionState::Aborted => false, @@ -43,10 +37,7 @@ async fn handle_delete_internal( timestamp = std::cmp::max(timestamp, v.timestamp + 1); } - let deleted_version = match must_delete { - None => return Err(Error::NotFound), - Some(v) => v, - }; + let deleted_version = must_delete.ok_or(Error::NotFound)?; let version_uuid = gen_uuid(); @@ -142,10 +133,8 @@ fn parse_delete_objects_xml(xml: &roxmltree::Document) -> Result<DeleteRequest, let mut ret = DeleteRequest { objects: vec![] }; let root = xml.root(); - let delete = match root.first_child() { - Some(del) => del, - None => return Err(format!("Delete tag not found")), - }; + let delete = root.first_child().ok_or(format!("Delete tag not found"))?; + if !delete.has_tag_name("Delete") { return Err(format!("Invalid root tag: {:?}", root)); } |