@@ -625,6 +625,12 @@ pub(crate) enum ActorMessage {
625625 hash : HashAndFormat ,
626626 tx : oneshot:: Sender < ActorResult < Tag > > ,
627627 } ,
628+ /// Modification method: rename a tag atomically.
629+ RenameTag {
630+ from : Tag ,
631+ to : Tag ,
632+ tx : oneshot:: Sender < ActorResult < ( ) > > ,
633+ } ,
628634 /// Modification method: unconditional delete the data for a number of hashes
629635 Delete {
630636 hashes : Vec < Hash > ,
@@ -680,6 +686,7 @@ impl ActorMessage {
680686 | Self :: SetFullEntryState { .. }
681687 | Self :: Delete { .. }
682688 | Self :: DeleteTags { .. }
689+ | Self :: RenameTag { .. }
683690 | Self :: GcDelete { .. } => MessageCategory :: ReadWrite ,
684691 Self :: UpdateInlineOptions { .. }
685692 | Self :: Sync { .. }
@@ -901,6 +908,14 @@ impl StoreInner {
901908 Ok ( rx. await ??)
902909 }
903910
911+ async fn rename_tag ( & self , from : Tag , to : Tag ) -> OuterResult < ( ) > {
912+ let ( tx, rx) = oneshot:: channel ( ) ;
913+ self . tx
914+ . send ( ActorMessage :: RenameTag { from, to, tx } )
915+ . await ?;
916+ Ok ( rx. await ??)
917+ }
918+
904919 async fn delete ( & self , hashes : Vec < Hash > ) -> OuterResult < ( ) > {
905920 let ( tx, rx) = oneshot:: channel ( ) ;
906921 self . tx . send ( ActorMessage :: Delete { hashes, tx } ) . await ?;
@@ -1404,6 +1419,10 @@ impl super::Store for Store {
14041419 Ok ( self . 0 . create_tag ( hash) . await ?)
14051420 }
14061421
1422+ async fn rename_tag ( & self , from : Tag , to : Tag ) -> io:: Result < ( ) > {
1423+ Ok ( self . 0 . rename_tag ( from, to) . await ?)
1424+ }
1425+
14071426 async fn delete ( & self , hashes : Vec < Hash > ) -> io:: Result < ( ) > {
14081427 Ok ( self . 0 . delete ( hashes) . await ?)
14091428 }
@@ -2021,6 +2040,18 @@ impl ActorState {
20212040 Ok ( tag)
20222041 }
20232042
2043+ fn rename_tag ( & mut self , tables : & mut Tables , from : Tag , to : Tag ) -> ActorResult < ( ) > {
2044+ let value = tables
2045+ . tags
2046+ . get ( from) ?
2047+ . ok_or_else ( || {
2048+ ActorError :: Io ( io:: Error :: new ( io:: ErrorKind :: NotFound , "tag not found" ) )
2049+ } ) ?
2050+ . value ( ) ;
2051+ tables. tags . insert ( to, value) ?;
2052+ Ok ( ( ) )
2053+ }
2054+
20242055 fn set_tag ( & self , tables : & mut Tables , tag : Tag , value : HashAndFormat ) -> ActorResult < ( ) > {
20252056 tables. tags . insert ( tag, value) ?;
20262057 Ok ( ( ) )
@@ -2393,6 +2424,10 @@ impl ActorState {
23932424 let res = self . create_tag ( tables, hash) ;
23942425 tx. send ( res) . ok ( ) ;
23952426 }
2427+ ActorMessage :: RenameTag { from, to, tx } => {
2428+ let res = self . rename_tag ( tables, from, to) ;
2429+ tx. send ( res) . ok ( ) ;
2430+ }
23962431 ActorMessage :: Delete { hashes, tx } => {
23972432 let res = self . delete ( tables, hashes, true ) ;
23982433 tx. send ( res) . ok ( ) ;
0 commit comments