corso/src/internal/connector/graph/collections.go
Keepers b82c994b91
Always make empty collections for prefix directories (#2929)
Use empty collections to ensure the prefix directories are available in
kopia no matter what user data we find.

This helps ensure we have some set of things we can assume about
non-failed backups including:

    They have a valid snapshot ID for data
    They have a valid snapshot ID for backup details

Eventually, this will allow us to say that backups using a base that
doesn't have a prefix directory is invalid in some way

SharePoint tests are disabled because lists and pages ignore the none
target in selectors

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #2550

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
2023-03-24 00:04:03 +00:00

92 lines
2.0 KiB
Go

package graph
import (
"context"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/connector/support"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
)
var _ data.BackupCollection = emptyCollection{}
type emptyCollection struct {
p path.Path
su support.StatusUpdater
}
func (c emptyCollection) 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 emptyCollection) FullPath() path.Path {
return c.p
}
func (c emptyCollection) PreviousPath() path.Path {
return c.p
}
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 emptyCollection) DoNotMergeItems() bool {
return false
}
func BaseCollections(
ctx context.Context,
tenant, rOwner string,
service path.ServiceType,
categories map[path.CategoryType]struct{},
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, error) {
var (
res = []data.BackupCollection{}
el = errs.Local()
lastErr error
)
for cat := range categories {
ictx := clues.Add(ctx, "base_service", service, "base_category", cat)
p, err := path.Build(tenant, rOwner, service, cat, false, "tmp")
if err != nil {
// Shouldn't happen.
err = clues.Wrap(err, "making path").WithClues(ictx)
el.AddRecoverable(err)
lastErr = err
continue
}
// Pop off the last path element because we just want the prefix.
p, err = p.Dir()
if err != nil {
// Shouldn't happen.
err = clues.Wrap(err, "getting base prefix").WithClues(ictx)
el.AddRecoverable(err)
lastErr = err
continue
}
res = append(res, emptyCollection{p: p, su: su})
}
return res, lastErr
}