@@ -11,14 +11,15 @@ import (
1111 "github.com/sdcio/data-server/pkg/tree/importer"
1212 "github.com/sdcio/data-server/pkg/tree/tree_persist"
1313 "github.com/sdcio/data-server/pkg/tree/types"
14+ "github.com/sdcio/data-server/pkg/utils"
1415 sdcpb "github.com/sdcio/sdc-protos/sdcpb"
1516 log "github.com/sirupsen/logrus"
1617)
1718
1819// RootEntry the root of the cache.Update tree
1920type RootEntry struct {
2021 * sharedEntryAttributes
21- explicitDeletes * DeletePaths
22+ explicitDeletes * DeletePathSet
2223}
2324
2425var (
@@ -89,11 +90,15 @@ func (r *RootEntry) ImportConfig(ctx context.Context, basePath types.PathSlice,
8990 return err
9091 }
9192
92- r .explicitDeletes .Add (intentName , importer .GetDeletes ())
93+ r .explicitDeletes .Add (intentName , intentPrio , importer .GetDeletes ())
9394
9495 return e .ImportConfig (ctx , importer , intentName , intentPrio , flags )
9596}
9697
98+ func (r * RootEntry ) AddExplicitDeletes (intentName string , priority int32 , pathset * sdcpb.PathSet ) {
99+ r .explicitDeletes .Add (intentName , priority , pathset )
100+ }
101+
97102func (r * RootEntry ) Validate (ctx context.Context , vCfg * config.Validation ) (types.ValidationResults , * types.ValidationStatOverall ) {
98103 // perform validation
99104 // we use a channel and cumulate all the errors
@@ -235,18 +240,31 @@ func (r *RootEntry) DeleteSubtreePaths(deletes types.DeleteEntriesList, intentNa
235240}
236241
237242func (r * RootEntry ) FinishInsertionPhase (ctx context.Context ) error {
243+ edvs := ExplicitDeleteVisitors {}
244+
238245 // apply the explicit deletes
239- edv := NewExplicitDeleteVisitor ()
240- for path := range r .explicitDeletes .Items () {
241- entry , err := r .NavigateSdcpbPath (ctx , path .Elem , true )
242- if err != nil {
243- log .Warnf ("Applying explicit delete: path %s not found, skipping" , path .ToXPath (false ))
244- }
245- err = entry .Walk (ctx , edv )
246- if err != nil {
247- return err
246+ for deletePathPrio := range r .explicitDeletes .Items () {
247+ edv := NewExplicitDeleteVisitor (deletePathPrio .GetOwner (), deletePathPrio .GetPrio ())
248+
249+ for path := range deletePathPrio .PathItems () {
250+ // set the priority
251+ // navigate to the stated path
252+ entry , err := r .NavigateSdcpbPath (ctx , path .GetElem (), true )
253+ if err != nil {
254+ log .Warnf ("Applying explicit delete: path %s not found, skipping" , path .ToXPath (false ))
255+ }
256+
257+ // walk the whole branch adding the explicit delete leafvariant
258+ err = entry .Walk (ctx , edv )
259+ if err != nil {
260+ return err
261+ }
262+ edvs [deletePathPrio .GetOwner ()] = edv
248263 }
249264 }
265+ log .Debugf ("ExplicitDeletes added: %s" , utils .MapToString (edvs .Stats (), ", " , func (k string , v int ) string {
266+ return fmt .Sprintf ("%s=%d" , k , v )
267+ }))
250268
251269 return r .sharedEntryAttributes .FinishInsertionPhase (ctx )
252270}
0 commit comments