Skip to content

Commit 70390e7

Browse files
committed
Actually use the atomic rename.
Also fix a bug in rename for the fs store.
1 parent 9c08813 commit 70390e7

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/rpc/client/tags.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use std::ops::{Bound, RangeBounds};
2424

2525
use anyhow::Result;
26-
use futures_lite::{io, Stream, StreamExt};
26+
use futures_lite::{Stream, StreamExt};
2727
use quic_rpc::{client::BoxedConnector, Connector, RpcClient};
2828
use serde::{Deserialize, Serialize};
2929

3030
use crate::{
3131
rpc::proto::{
32-
tags::{DeleteRequest, ListRequest, SetRequest, SyncMode},
32+
tags::{DeleteRequest, ListRequest, RenameRequest, SetRequest, SyncMode},
3333
RpcService,
3434
},
3535
BlobFormat, Hash, HashAndFormat, Tag,
@@ -235,13 +235,12 @@ where
235235
///
236236
/// If the tag does not exist, this will return an error.
237237
pub async fn rename(&self, from: impl AsRef<[u8]>, to: impl AsRef<[u8]>) -> Result<()> {
238-
let from = from.as_ref();
239-
let to = to.as_ref();
240-
let Some(old) = self.get(from.as_ref()).await? else {
241-
return Err(io::Error::new(io::ErrorKind::NotFound, "Tag not found").into());
242-
};
243-
self.set(to.as_ref(), old.hash_and_format()).await?;
244-
self.delete(from.as_ref()).await?;
238+
self.rpc
239+
.rpc(RenameRequest {
240+
from: Tag::from(from.as_ref()),
241+
to: Tag::from(to.as_ref()),
242+
})
243+
.await??;
245244
Ok(())
246245
}
247246

src/store/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ impl ActorState {
20432043
fn rename_tag(&mut self, tables: &mut Tables, from: Tag, to: Tag) -> ActorResult<()> {
20442044
let value = tables
20452045
.tags
2046-
.get(from)?
2046+
.remove(from)?
20472047
.ok_or_else(|| {
20482048
ActorError::Io(io::Error::new(io::ErrorKind::NotFound, "tag not found"))
20492049
})?

0 commit comments

Comments
 (0)