Do not insert deletion marker if there is no object to delete
This commit is contained in:
parent
be0a2bae81
commit
0226561035
2 changed files with 29 additions and 8 deletions
|
@ -90,15 +90,13 @@ async fn handler_inner(
|
||||||
.to_string();
|
.to_string();
|
||||||
let version_uuid =
|
let version_uuid =
|
||||||
handle_put(garage, &mime_type, &bucket, &key, req.into_body()).await?;
|
handle_put(garage, &mime_type, &bucket, &key, req.into_body()).await?;
|
||||||
Ok(Response::new(Box::new(BytesBody::from(hex::encode(
|
let response = format!("{}\n", hex::encode(version_uuid,));
|
||||||
version_uuid,
|
Ok(Response::new(Box::new(BytesBody::from(response))))
|
||||||
)))))
|
|
||||||
}
|
}
|
||||||
&Method::DELETE => {
|
&Method::DELETE => {
|
||||||
let version_uuid = handle_delete(garage, &bucket, &key).await?;
|
let version_uuid = handle_delete(garage, &bucket, &key).await?;
|
||||||
Ok(Response::new(Box::new(BytesBody::from(hex::encode(
|
let response = format!("{}\n", hex::encode(version_uuid,));
|
||||||
version_uuid,
|
Ok(Response::new(Box::new(BytesBody::from(response))))
|
||||||
)))))
|
|
||||||
}
|
}
|
||||||
_ => Err(Error::BadRequest(format!("Invalid method"))),
|
_ => 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> {
|
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 version_uuid = gen_uuid();
|
||||||
|
|
||||||
let mut object = Object {
|
let mut object = Object {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
for FILE in $(find target/debug/deps); do
|
for FILE in $(find target); do
|
||||||
curl -v localhost:3900/$FILE -X DELETE -H 'Host: garage'
|
curl localhost:3900/$FILE -X DELETE -H 'Host: garage'
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue