@@ -67,6 +67,7 @@ use std::{
6767 collections:: { BTreeMap , BTreeSet } ,
6868 future:: Future ,
6969 io,
70+ ops:: Bound ,
7071 path:: { Path , PathBuf } ,
7172 sync:: { Arc , RwLock } ,
7273 time:: { Duration , SystemTime } ,
@@ -608,10 +609,16 @@ pub(crate) enum ActorMessage {
608609 ActorResult < Vec < std:: result:: Result < ( Tag , HashAndFormat ) , StorageError > > > ,
609610 > ,
610611 } ,
611- /// Modification method: set a tag to a value, or remove it .
612+ /// Modification method: set a tag to a value.
612613 SetTag {
613614 tag : Tag ,
614- value : Option < HashAndFormat > ,
615+ value : HashAndFormat ,
616+ tx : oneshot:: Sender < ActorResult < ( ) > > ,
617+ } ,
618+ /// Modification method: set a tag to a value.
619+ DeleteTags {
620+ from : Option < Tag > ,
621+ to : Option < Tag > ,
615622 tx : oneshot:: Sender < ActorResult < ( ) > > ,
616623 } ,
617624 /// Modification method: create a new unique tag and set it to a value.
@@ -673,6 +680,7 @@ impl ActorMessage {
673680 | Self :: CreateTag { .. }
674681 | Self :: SetFullEntryState { .. }
675682 | Self :: Delete { .. }
683+ | Self :: DeleteTags { .. }
676684 | Self :: GcDelete { .. } => MessageCategory :: ReadWrite ,
677685 Self :: UpdateInlineOptions { .. }
678686 | Self :: Sync { .. }
@@ -870,14 +878,22 @@ impl StoreInner {
870878 Ok ( tags)
871879 }
872880
873- async fn set_tag ( & self , tag : Tag , value : Option < HashAndFormat > ) -> OuterResult < ( ) > {
881+ async fn set_tag ( & self , tag : Tag , value : HashAndFormat ) -> OuterResult < ( ) > {
874882 let ( tx, rx) = oneshot:: channel ( ) ;
875883 self . tx
876884 . send ( ActorMessage :: SetTag { tag, value, tx } )
877885 . await ?;
878886 Ok ( rx. await ??)
879887 }
880888
889+ async fn delete_tags ( & self , from : Option < Tag > , to : Option < Tag > ) -> OuterResult < ( ) > {
890+ let ( tx, rx) = oneshot:: channel ( ) ;
891+ self . tx
892+ . send ( ActorMessage :: DeleteTags { from, to, tx } )
893+ . await ?;
894+ Ok ( rx. await ??)
895+ }
896+
881897 async fn create_tag ( & self , hash : HashAndFormat ) -> OuterResult < Tag > {
882898 let ( tx, rx) = oneshot:: channel ( ) ;
883899 self . tx . send ( ActorMessage :: CreateTag { hash, tx } ) . await ?;
@@ -1371,10 +1387,14 @@ impl super::Store for Store {
13711387 . await ??)
13721388 }
13731389
1374- async fn set_tag ( & self , name : Tag , hash : Option < HashAndFormat > ) -> io:: Result < ( ) > {
1390+ async fn set_tag ( & self , name : Tag , hash : HashAndFormat ) -> io:: Result < ( ) > {
13751391 Ok ( self . 0 . set_tag ( name, hash) . await ?)
13761392 }
13771393
1394+ async fn delete_tags ( & self , from : Option < Tag > , to : Option < Tag > ) -> io:: Result < ( ) > {
1395+ Ok ( self . 0 . delete_tags ( from, to) . await ?)
1396+ }
1397+
13781398 async fn create_tag ( & self , hash : HashAndFormat ) -> io:: Result < Tag > {
13791399 Ok ( self . 0 . create_tag ( hash) . await ?)
13801400 }
@@ -1998,19 +2018,23 @@ impl ActorState {
19982018 Ok ( tag)
19992019 }
20002020
2001- fn set_tag (
2021+ fn set_tag ( & self , tables : & mut Tables , tag : Tag , value : HashAndFormat ) -> ActorResult < ( ) > {
2022+ tables. tags . insert ( tag, value) ?;
2023+ Ok ( ( ) )
2024+ }
2025+
2026+ fn delete_tags (
20022027 & self ,
20032028 tables : & mut Tables ,
2004- tag : Tag ,
2005- value : Option < HashAndFormat > ,
2029+ from : Option < Tag > ,
2030+ to : Option < Tag > ,
20062031 ) -> ActorResult < ( ) > {
2007- match value {
2008- Some ( value) => {
2009- tables. tags . insert ( tag, value) ?;
2010- }
2011- None => {
2012- tables. tags . remove ( tag) ?;
2013- }
2032+ let from = from. map ( Bound :: Included ) . unwrap_or ( Bound :: Unbounded ) ;
2033+ let to = to. map ( Bound :: Excluded ) . unwrap_or ( Bound :: Unbounded ) ;
2034+ let removing = tables. tags . extract_from_if ( ( from, to) , |_, _| true ) ?;
2035+ // drain the iterator to actually remove the tags
2036+ for res in removing {
2037+ res?;
20142038 }
20152039 Ok ( ( ) )
20162040 }
@@ -2358,6 +2382,10 @@ impl ActorState {
23582382 let res = self . set_tag ( tables, tag, value) ;
23592383 tx. send ( res) . ok ( ) ;
23602384 }
2385+ ActorMessage :: DeleteTags { from, to, tx } => {
2386+ let res = self . delete_tags ( tables, from, to) ;
2387+ tx. send ( res) . ok ( ) ;
2388+ }
23612389 ActorMessage :: CreateTag { hash, tx } => {
23622390 let res = self . create_tag ( tables, hash) ;
23632391 tx. send ( res) . ok ( ) ;
0 commit comments