Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub enum Request {
ListTags(ListTagsRequest),
#[rpc(tx = oneshot::Sender<super::Result<()>>)]
SetTag(SetTagRequest),
#[rpc(tx = oneshot::Sender<super::Result<()>>)]
#[rpc(tx = oneshot::Sender<super::Result<u64>>)]
DeleteTags(DeleteTagsRequest),
#[rpc(tx = oneshot::Sender<super::Result<()>>)]
RenameTag(RenameTagRequest),
Expand Down
27 changes: 19 additions & 8 deletions src/api/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,28 @@ impl Tags {
self.list_with_opts(ListOptions::hash_seq()).await
}

/// Deletes a tag.
pub async fn delete_with_opts(&self, options: DeleteOptions) -> super::RequestResult<()> {
/// Deletes a tag, with full control over options. All other delete methods
/// wrap this.
///
/// Returns the number of tags actually removed. Attempting to delete a non-existent tag will *not* fail.
pub async fn delete_with_opts(&self, options: DeleteOptions) -> super::RequestResult<u64> {
trace!("{:?}", options);
self.client.rpc(options).await??;
Ok(())
let deleted = self.client.rpc(options).await??;
Ok(deleted)
}

/// Deletes a tag.
pub async fn delete(&self, name: impl AsRef<[u8]>) -> super::RequestResult<()> {
///
/// Returns the number of tags actually removed. Attempting to delete a non-existent tag will *not* fail.
pub async fn delete(&self, name: impl AsRef<[u8]>) -> super::RequestResult<u64> {
self.delete_with_opts(DeleteOptions::single(name.as_ref()))
.await
}

/// Deletes a range of tags.
pub async fn delete_range<R, E>(&self, range: R) -> super::RequestResult<()>
///
/// Returns the number of tags actually removed. Attempting to delete a non-existent tag will *not* fail.
pub async fn delete_range<R, E>(&self, range: R) -> super::RequestResult<u64>
where
R: RangeBounds<E>,
E: AsRef<[u8]>,
Expand All @@ -130,13 +137,17 @@ impl Tags {
}

/// Delete all tags with the given prefix.
pub async fn delete_prefix(&self, prefix: impl AsRef<[u8]>) -> super::RequestResult<()> {
///
/// Returns the number of tags actually removed. Attempting to delete a non-existent tag will *not* fail.
pub async fn delete_prefix(&self, prefix: impl AsRef<[u8]>) -> super::RequestResult<u64> {
self.delete_with_opts(DeleteOptions::prefix(prefix.as_ref()))
.await
}

/// Delete all tags. Use with care. After this, all data will be garbage collected.
pub async fn delete_all(&self) -> super::RequestResult<()> {
///
/// Returns the number of tags actually removed. Attempting to delete a non-existent tag will *not* fail.
pub async fn delete_all(&self) -> super::RequestResult<u64> {
self.delete_with_opts(DeleteOptions {
from: None,
to: None,
Expand Down
4 changes: 3 additions & 1 deletion src/store/fs/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,12 @@ impl Actor {
.extract_from_if((from, to), |_, _| true)
.context(StorageSnafu)?;
// drain the iterator to actually remove the tags
let mut deleted = 0;
for res in removing {
res.context(StorageSnafu)?;
deleted += 1;
}
tx.send(Ok(())).await.ok();
tx.send(Ok(deleted)).await.ok();
Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion src/store/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl Actor {
info!("deleting tags from {:?} to {:?}", from, to);
// state.tags.remove(&from.unwrap());
// todo: more efficient impl
let mut deleted = 0;
self.state.tags.retain(|tag, _| {
if let Some(from) = &from {
if tag < from {
Expand All @@ -239,9 +240,10 @@ impl Actor {
}
}
info!(" removing {:?}", tag);
deleted += 1;
false
});
tx.send(Ok(())).await.ok();
tx.send(Ok(deleted)).await.ok();
}
Command::RenameTag(cmd) => {
let RenameTagMsg {
Expand Down
Loading