diff --git a/src/internal/connector/graph/collections.go b/src/internal/connector/graph/collections.go index ce93aa6c9..ee941f81c 100644 --- a/src/internal/connector/graph/collections.go +++ b/src/internal/connector/graph/collections.go @@ -11,14 +11,19 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -var _ data.BackupCollection = emptyCollection{} +var _ data.BackupCollection = prefixCollection{} -type emptyCollection struct { - p path.Path - su support.StatusUpdater +// TODO: move this out of graph. /data would be a much better owner +// for a generic struct like this. However, support.StatusUpdater makes +// it difficult to extract from this package in a generic way. +type prefixCollection struct { + full path.Path + prev path.Path + su support.StatusUpdater + state data.CollectionState } -func (c emptyCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream { +func (c prefixCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream { res := make(chan data.Stream) close(res) @@ -28,21 +33,19 @@ func (c emptyCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.St return res } -func (c emptyCollection) FullPath() path.Path { - return c.p +func (c prefixCollection) FullPath() path.Path { + return c.full } -func (c emptyCollection) PreviousPath() path.Path { - return c.p +func (c prefixCollection) PreviousPath() path.Path { + return c.prev } -func (c emptyCollection) State() data.CollectionState { - // This assumes we won't change the prefix path. Could probably use MovedState - // as well if we do need to change things around. - return data.NotMovedState +func (c prefixCollection) State() data.CollectionState { + return c.state } -func (c emptyCollection) DoNotMergeItems() bool { +func (c prefixCollection) DoNotMergeItems() bool { return false } @@ -76,7 +79,7 @@ func BaseCollections( for cat := range categories { ictx := clues.Add(ctx, "base_service", service, "base_category", cat) - p, err := path.ServicePrefix(tenant, rOwner, service, cat) + full, err := path.ServicePrefix(tenant, rOwner, service, cat) if err != nil { // Shouldn't happen. err = clues.Wrap(err, "making path").WithClues(ictx) @@ -87,8 +90,13 @@ func BaseCollections( } // only add this collection if it doesn't already exist in the set. - if _, ok := collKeys[p.String()]; !ok { - res = append(res, emptyCollection{p: p, su: su}) + if _, ok := collKeys[full.String()]; !ok { + res = append(res, &prefixCollection{ + prev: full, + full: full, + su: su, + state: data.StateOf(full, full), + }) } } @@ -99,45 +107,11 @@ func BaseCollections( // prefix migration // --------------------------------------------------------------------------- -var _ data.BackupCollection = prefixCollection{} - -// TODO: move this out of graph. /data would be a much better owner -// for a generic struct like this. However, support.StatusUpdater makes -// it difficult to extract from this package in a generic way. -type prefixCollection struct { - full, prev path.Path - su support.StatusUpdater - state data.CollectionState -} - -func (c prefixCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream { - res := make(chan data.Stream) - close(res) - - s := support.CreateStatus(ctx, support.Backup, 0, support.CollectionMetrics{}, "") - c.su(s) - - return res -} - -func (c prefixCollection) FullPath() path.Path { - return c.full -} - -func (c prefixCollection) PreviousPath() path.Path { - return c.prev -} - -func (c prefixCollection) State() data.CollectionState { - return c.state -} - -func (c prefixCollection) DoNotMergeItems() bool { - return false -} - // Creates a new collection that only handles prefix pathing. -func NewPrefixCollection(prev, full path.Path, su support.StatusUpdater) (*prefixCollection, error) { +func NewPrefixCollection( + prev, full path.Path, + su support.StatusUpdater, +) (*prefixCollection, error) { if prev != nil { if len(prev.Item()) > 0 { return nil, clues.New("prefix collection previous path contains an item")