aboutsummaryrefslogtreecommitdiff
path: root/src/api_server.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-21 14:33:12 +0000
committerAlex Auvolat <alex@adnab.me>2020-04-21 14:33:12 +0000
commit0226561035bc90dbf45b993f755b1eee47c8a790 (patch)
tree0e16b7408e70ba1a0f461f8b47821588b3907181 /src/api_server.rs
parentbe0a2bae8112de1d4674767c5c60e296c28e8532 (diff)
downloadgarage-0226561035bc90dbf45b993f755b1eee47c8a790.tar.gz
garage-0226561035bc90dbf45b993f755b1eee47c8a790.zip
Do not insert deletion marker if there is no object to delete
Diffstat (limited to 'src/api_server.rs')
-rw-r--r--src/api_server.rs33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/api_server.rs b/src/api_server.rs
index 6487d5fe..4ee28f57 100644
--- a/src/api_server.rs
+++ b/src/api_server.rs
@@ -90,15 +90,13 @@ async fn handler_inner(
.to_string();
let version_uuid =
handle_put(garage, &mime_type, &bucket, &key, req.into_body()).await?;
- Ok(Response::new(Box::new(BytesBody::from(hex::encode(
- version_uuid,
- )))))
+ let response = format!("{}\n", hex::encode(version_uuid,));
+ Ok(Response::new(Box::new(BytesBody::from(response))))
}
&Method::DELETE => {
let version_uuid = handle_delete(garage, &bucket, &key).await?;
- Ok(Response::new(Box::new(BytesBody::from(hex::encode(
- version_uuid,
- )))))
+ let response = format!("{}\n", hex::encode(version_uuid,));
+ Ok(Response::new(Box::new(BytesBody::from(response))))
}
_ => Err(Error::BadRequest(format!("Invalid method"))),
}
@@ -250,6 +248,29 @@ impl BodyChunker {
}
async fn handle_delete(garage: Arc<Garage>, bucket: &str, key: &str) -> Result<UUID, Error> {
+ let exists = match garage
+ .object_table
+ .get(&bucket.to_string(), &key.to_string())
+ .await?
+ {
+ None => false,
+ Some(o) => {
+ let mut has_active_version = false;
+ for v in o.versions.iter() {
+ if v.data != ObjectVersionData::DeleteMarker {
+ has_active_version = true;
+ break;
+ }
+ }
+ has_active_version
+ }
+ };
+
+ if !exists {
+ // No need to delete
+ return Ok([0u8; 32].into());
+ }
+
let version_uuid = gen_uuid();
let mut object = Object {