Create and use generic tombstone collection (#4339)

Incremental backups requires us to mark some
folders as deleted by creating a collection
with state `data.DeletedState`

This PR creates a simple, generic "tombstone"
collection that does just that

The PR additionally uses the tombstone
collection in place of more complicated
implementations where any easy switch is
possible. Deleted collections in OneDrive
require more work since tests attempt to
cast to a concrete type

---

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

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #4191

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
ashmrtn 2023-09-21 18:22:53 -07:00 committed by GitHub
parent 6bc40ea2aa
commit 738693a1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 28 deletions

View File

@ -153,3 +153,17 @@ func (suite *CollectionSuite) TestNewBaseCollection() {
}) })
} }
} }
func (suite *CollectionSuite) TestNewTombstoneCollection() {
t := suite.T()
fooP, err := path.Build("t", "u", path.ExchangeService, path.EmailCategory, false, "foo")
require.NoError(t, err, clues.ToCore(err))
c := NewTombstoneCollection(fooP, control.Options{})
assert.Nil(t, c.FullPath(), "full path")
assert.Equal(t, fooP, c.PreviousPath(), "previous path")
assert.Nil(t, c.LocationPath(), "location path")
assert.Equal(t, DeletedState, c.State(), "state")
assert.False(t, c.DoNotMergeItems(), "do not merge")
}

View File

@ -6,6 +6,7 @@ import (
"github.com/alcionai/clues" "github.com/alcionai/clues"
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
@ -136,3 +137,30 @@ func (col BaseCollection) DoNotMergeItems() bool {
func (col BaseCollection) Opts() control.Options { func (col BaseCollection) Opts() control.Options {
return col.opts return col.opts
} }
// -----------------------------------------------------------------------------
// tombstoneCollection
// -----------------------------------------------------------------------------
func NewTombstoneCollection(
prev path.Path,
opts control.Options,
) *tombstoneCollection {
return &tombstoneCollection{
BaseCollection: NewBaseCollection(nil, prev, nil, opts, false),
}
}
// tombstoneCollection is a collection that marks a folder (and folders under it
// if they aren't explicitly noted in other collecteds) as deleted. It doesn't
// contain any items.
type tombstoneCollection struct {
BaseCollection
}
// Items never returns any data for tombstone collections because the collection
// only denotes the deletion of the current folder and possibly subfolders. All
// items contained in the deleted folder are also deleted.
func (col *tombstoneCollection) Items(context.Context, *fault.Bus) <-chan Item {
return nil
}

View File

@ -241,20 +241,7 @@ func populateCollections(
continue continue
} }
edc := NewCollection( collections[id] = data.NewTombstoneCollection(prevPath, ctrlOpts)
data.NewBaseCollection(
nil, // marks the collection as deleted
prevPath,
nil, // tombstones don't need a location
ctrlOpts,
false),
qp.ProtectedResource.ID(),
bh.itemHandler(),
nil,
nil,
false,
statusUpdater)
collections[id] = edc
} }
logger.Ctx(ctx).Infow( logger.Ctx(ctx).Infow(

View File

@ -233,20 +233,7 @@ func populateCollections(
continue continue
} }
edc := NewCollection( collections[id] = data.NewTombstoneCollection(prevPath, ctrlOpts)
data.NewBaseCollection(
nil, // marks the collection as deleted
prevPath,
nil, // tombstones don't need a location
ctrlOpts,
false),
bh,
qp.ProtectedResource.ID(),
nil, // no items added
nil, // this deletes a directory, so no items deleted either
statusUpdater)
collections[id] = &edc
} }
logger.Ctx(ctx).Infow( logger.Ctx(ctx).Infow(