diff options
author | Alex Auvolat <alex@adnab.me> | 2020-07-08 17:34:37 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-07-08 17:34:37 +0200 |
commit | 44dba0e53c7bae0fa16bf48e6022faa95d1159aa (patch) | |
tree | 24bd564e6030f82c1ddad7602c12d12a71c0ed8a /src/api/s3_put.rs | |
parent | 64a6eda0d2bb6aae6a6eef60032ab24ae3c37a88 (diff) | |
download | garage-44dba0e53c7bae0fa16bf48e6022faa95d1159aa.tar.gz garage-44dba0e53c7bae0fa16bf48e6022faa95d1159aa.zip |
cargo fmt
Diffstat (limited to 'src/api/s3_put.rs')
-rw-r--r-- | src/api/s3_put.rs | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index 75622168..9ac7dafd 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -1,4 +1,4 @@ -use std::collections::{VecDeque, BTreeMap}; +use std::collections::{BTreeMap, VecDeque}; use std::fmt::Write; use std::sync::Arc; @@ -24,10 +24,10 @@ pub async fn handle_put( key: &str, ) -> Result<Response<Body>, Error> { let version_uuid = gen_uuid(); - let headers = ObjectVersionHeaders{ - content_type: get_mime_type(&req)?, - other: BTreeMap::new(), // TODO - }; + let headers = ObjectVersionHeaders { + content_type: get_mime_type(&req)?, + other: BTreeMap::new(), // TODO + }; let body = req.into_body(); @@ -44,13 +44,14 @@ pub async fn handle_put( }; if first_block.len() < INLINE_THRESHOLD { - object_version.state = ObjectVersionState::Complete(ObjectVersionData::Inline( - ObjectVersionMeta{ - headers, - size: first_block.len() as u64, - etag: "".to_string(), // TODO - }, - first_block)); + object_version.state = ObjectVersionState::Complete(ObjectVersionData::Inline( + ObjectVersionMeta { + headers, + size: first_block.len() as u64, + etag: "".to_string(), // TODO + }, + first_block, + )); let object = Object::new(bucket.into(), key.into(), vec![object_version]); garage.object_table.insert(&object).await?; @@ -76,12 +77,13 @@ pub async fn handle_put( // TODO: if at any step we have an error, we should undo everything we did object_version.state = ObjectVersionState::Complete(ObjectVersionData::FirstBlock( - ObjectVersionMeta{ - headers, - size: total_size, - etag: "".to_string(), // TODO - }, - first_block_hash)); + ObjectVersionMeta { + headers, + size: total_size, + etag: "".to_string(), // TODO + }, + first_block_hash, + )); let object = Object::new(bucket.into(), key.into(), vec![object_version]); garage.object_table.insert(&object).await?; @@ -207,7 +209,7 @@ impl BodyChunker { pub fn put_response(version_uuid: UUID) -> Response<Body> { Response::builder() .header("x-amz-version-id", hex::encode(version_uuid)) - // TODO ETag + // TODO ETag .body(Body::from(vec![])) .unwrap() } @@ -219,10 +221,10 @@ pub async fn handle_create_multipart_upload( key: &str, ) -> Result<Response<Body>, Error> { let version_uuid = gen_uuid(); - let headers = ObjectVersionHeaders{ - content_type: get_mime_type(&req)?, - other: BTreeMap::new(), // TODO - }; + let headers = ObjectVersionHeaders { + content_type: get_mime_type(&req)?, + other: BTreeMap::new(), // TODO + }; let object_version = ObjectVersion { uuid: version_uuid, @@ -286,9 +288,11 @@ pub async fn handle_put_part( None => return Err(Error::BadRequest(format!("Object not found"))), Some(x) => x, }; - if !object.versions().iter().any(|v| { - v.uuid == version_uuid && v.is_uploading() - }) { + if !object + .versions() + .iter() + .any(|v| v.uuid == version_uuid && v.is_uploading()) + { return Err(Error::BadRequest(format!( "Multipart upload does not exist or is otherwise invalid" ))); @@ -330,9 +334,10 @@ pub async fn handle_complete_multipart_upload( 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.is_uploading() - }); + let object_version = object + .versions() + .iter() + .find(|v| v.uuid == version_uuid && v.is_uploading()); let mut object_version = match object_version { None => { return Err(Error::BadRequest(format!( @@ -348,10 +353,10 @@ pub async fn handle_complete_multipart_upload( if version.blocks().len() == 0 { return Err(Error::BadRequest(format!("No data was uploaded"))); } - let headers = match object_version.state { - ObjectVersionState::Uploading(headers) => headers.clone(), - _ => unreachable!(), - }; + let headers = match object_version.state { + ObjectVersionState::Uploading(headers) => headers.clone(), + _ => unreachable!(), + }; // TODO: check that all the parts that they pretend they gave us are indeed there // TODO: check MD5 sum of all uploaded parts? but that would mean we have to store them somewhere... @@ -361,15 +366,14 @@ pub async fn handle_complete_multipart_upload( .iter() .map(|x| x.size) .fold(0, |x, y| x + y); - object_version.state = ObjectVersionState::Complete( - ObjectVersionData::FirstBlock( - ObjectVersionMeta{ - headers, - size: total_size, - etag: "".to_string(),// TODO - }, - version.blocks()[0].hash) - ); + object_version.state = ObjectVersionState::Complete(ObjectVersionData::FirstBlock( + ObjectVersionMeta { + headers, + size: total_size, + etag: "".to_string(), // TODO + }, + version.blocks()[0].hash, + )); let final_object = Object::new(bucket.clone(), key.clone(), vec![object_version]); garage.object_table.insert(&final_object).await?; @@ -411,9 +415,10 @@ pub async fn handle_abort_multipart_upload( 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.is_uploading() - }); + let object_version = object + .versions() + .iter() + .find(|v| v.uuid == version_uuid && v.is_uploading()); let mut object_version = match object_version { None => { return Err(Error::BadRequest(format!( |