diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-26 20:46:21 +0000 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-26 20:46:33 +0000 |
commit | 0877a5500cca4f3aa85da4fff4225b154a159a09 (patch) | |
tree | cb7d7cc1b2d9815161296c46a7d7b1e7378ce7c3 /src/api/s3_put.rs | |
parent | 81ecc4999e16c58ce6d0e97501f7b6b1497f6cf6 (diff) | |
download | garage-0877a5500cca4f3aa85da4fff4225b154a159a09.tar.gz garage-0877a5500cca4f3aa85da4fff4225b154a159a09.zip |
Abort multipart upload
Diffstat (limited to 'src/api/s3_put.rs')
-rw-r--r-- | src/api/s3_put.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index f1755c17..70a467a8 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -333,6 +333,38 @@ pub async fn handle_complete_multipart_upload( Ok(Response::new(Box::new(BytesBody::from(xml.into_bytes())))) } +pub async fn handle_abort_multipart_upload( + garage: Arc<Garage>, + bucket: &str, + key: &str, + upload_id: &str, +) -> Result<Response<BodyType>, Error> { + let version_uuid = uuid_from_str(upload_id).map_err(|_| Error::BadRequest(format!("Invalid upload ID")))?; + + let object = garage.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_version = object.versions().iter().find(|v| { + v.uuid == version_uuid + && v.state == ObjectVersionState::Uploading + && v.data == ObjectVersionData::Uploading + }); + let mut object_version = match object_version { + None => return Err(Error::BadRequest(format!( + "Multipart upload does not exist or has already been completed" + ))), + Some(x) => x.clone(), + }; + + object_version.state = ObjectVersionState::Aborted; + let final_object = Object::new(bucket.to_string(), key.to_string(), vec![object_version]); + garage.object_table.insert(&final_object).await?; + + Ok(Response::new(Box::new(BytesBody::from(vec![])))) +} + fn get_mime_type(req: &Request<Body>) -> Result<String, Error> { Ok(req .headers() |