@@ -625,6 +625,12 @@ pub(crate) enum ActorMessage {
625
625
hash : HashAndFormat ,
626
626
tx : oneshot:: Sender < ActorResult < Tag > > ,
627
627
} ,
628
+ /// Modification method: rename a tag atomically.
629
+ RenameTag {
630
+ from : Tag ,
631
+ to : Tag ,
632
+ tx : oneshot:: Sender < ActorResult < ( ) > > ,
633
+ } ,
628
634
/// Modification method: unconditional delete the data for a number of hashes
629
635
Delete {
630
636
hashes : Vec < Hash > ,
@@ -680,6 +686,7 @@ impl ActorMessage {
680
686
| Self :: SetFullEntryState { .. }
681
687
| Self :: Delete { .. }
682
688
| Self :: DeleteTags { .. }
689
+ | Self :: RenameTag { .. }
683
690
| Self :: GcDelete { .. } => MessageCategory :: ReadWrite ,
684
691
Self :: UpdateInlineOptions { .. }
685
692
| Self :: Sync { .. }
@@ -901,6 +908,14 @@ impl StoreInner {
901
908
Ok ( rx. await ??)
902
909
}
903
910
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
+
904
919
async fn delete ( & self , hashes : Vec < Hash > ) -> OuterResult < ( ) > {
905
920
let ( tx, rx) = oneshot:: channel ( ) ;
906
921
self . tx . send ( ActorMessage :: Delete { hashes, tx } ) . await ?;
@@ -1404,6 +1419,10 @@ impl super::Store for Store {
1404
1419
Ok ( self . 0 . create_tag ( hash) . await ?)
1405
1420
}
1406
1421
1422
+ async fn rename_tag ( & self , from : Tag , to : Tag ) -> io:: Result < ( ) > {
1423
+ Ok ( self . 0 . rename_tag ( from, to) . await ?)
1424
+ }
1425
+
1407
1426
async fn delete ( & self , hashes : Vec < Hash > ) -> io:: Result < ( ) > {
1408
1427
Ok ( self . 0 . delete ( hashes) . await ?)
1409
1428
}
@@ -2021,6 +2040,18 @@ impl ActorState {
2021
2040
Ok ( tag)
2022
2041
}
2023
2042
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
+
2024
2055
fn set_tag ( & self , tables : & mut Tables , tag : Tag , value : HashAndFormat ) -> ActorResult < ( ) > {
2025
2056
tables. tags . insert ( tag, value) ?;
2026
2057
Ok ( ( ) )
@@ -2393,6 +2424,10 @@ impl ActorState {
2393
2424
let res = self . create_tag ( tables, hash) ;
2394
2425
tx. send ( res) . ok ( ) ;
2395
2426
}
2427
+ ActorMessage :: RenameTag { from, to, tx } => {
2428
+ let res = self . rename_tag ( tables, from, to) ;
2429
+ tx. send ( res) . ok ( ) ;
2430
+ }
2396
2431
ActorMessage :: Delete { hashes, tx } => {
2397
2432
let res = self . delete ( tables, hashes, true ) ;
2398
2433
tx. send ( res) . ok ( ) ;
0 commit comments