ensure invalid deltas result in new state collections (#4623)
#### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🐛 Bugfix #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
e9118abe9f
commit
80feeace3b
@ -335,7 +335,7 @@ func (c *Collections) Get(
|
|||||||
|
|
||||||
logger.Ctx(ictx).Infow(
|
logger.Ctx(ictx).Infow(
|
||||||
"previous metadata for drive",
|
"previous metadata for drive",
|
||||||
"num_paths_entries", len(oldPrevPaths))
|
"count_old_prev_paths", len(oldPrevPaths))
|
||||||
|
|
||||||
du, newPrevPaths, err := c.PopulateDriveCollections(
|
du, newPrevPaths, err := c.PopulateDriveCollections(
|
||||||
ctx,
|
ctx,
|
||||||
@ -368,7 +368,7 @@ func (c *Collections) Get(
|
|||||||
|
|
||||||
logger.Ctx(ictx).Infow(
|
logger.Ctx(ictx).Infow(
|
||||||
"persisted metadata for drive",
|
"persisted metadata for drive",
|
||||||
"num_new_paths_entries", len(newPrevPaths),
|
"count_new_prev_paths", len(newPrevPaths),
|
||||||
"delta_reset", du.Reset)
|
"delta_reset", du.Reset)
|
||||||
|
|
||||||
numDriveItems := c.NumItems - numPrevItems
|
numDriveItems := c.NumItems - numPrevItems
|
||||||
@ -762,6 +762,7 @@ func (c *Collections) PopulateDriveCollections(
|
|||||||
ctx = clues.Add(ctx, "delta_reset_occurred", true)
|
ctx = clues.Add(ctx, "delta_reset_occurred", true)
|
||||||
newPrevPaths = map[string]string{}
|
newPrevPaths = map[string]string{}
|
||||||
currPrevPaths = map[string]string{}
|
currPrevPaths = map[string]string{}
|
||||||
|
seenFolders = map[string]string{}
|
||||||
c.CollectionMap[driveID] = map[string]*Collection{}
|
c.CollectionMap[driveID] = map[string]*Collection{}
|
||||||
invalidPrevDelta = true
|
invalidPrevDelta = true
|
||||||
}
|
}
|
||||||
@ -929,6 +930,10 @@ func (c *Collections) processItem(
|
|||||||
delete(newPrevPaths, alreadyHandledFolderID)
|
delete(newPrevPaths, alreadyHandledFolderID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if invalidPrevDelta {
|
||||||
|
prevPath = nil
|
||||||
|
}
|
||||||
|
|
||||||
seenFolders[collectionPath.String()] = itemID
|
seenFolders[collectionPath.String()] = itemID
|
||||||
|
|
||||||
col, err := NewCollection(
|
col, err := NewCollection(
|
||||||
|
|||||||
@ -2403,6 +2403,118 @@ func (suite *CollectionsUnitSuite) TestGet() {
|
|||||||
fullPath(1, name(folder)): true,
|
fullPath(1, name(folder)): true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "OneDrive_OneItemPage_InvalidPrevDelta_AnotherFolderAtExistingLocation",
|
||||||
|
drives: []models.Driveable{drive1},
|
||||||
|
enumerator: mock.EnumerateItemsDeltaByDrive{
|
||||||
|
DrivePagers: map[string]*mock.DriveItemsDeltaPager{
|
||||||
|
idx(drive, 1): {
|
||||||
|
Pages: []mock.NextPage{
|
||||||
|
{
|
||||||
|
Items: []models.DriveItemable{
|
||||||
|
driveRootItem(rootID),
|
||||||
|
driveItem(id(folder), name(folder), parent(1), rootID, isFolder),
|
||||||
|
driveItem(id(file), name(file), parent(1, name(folder)), id(folder), isFile),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Items: []models.DriveItemable{},
|
||||||
|
Reset: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Items: []models.DriveItemable{
|
||||||
|
driveRootItem(rootID),
|
||||||
|
driveItem(id(folder), name(folder), parent(1), rootID, isFolder),
|
||||||
|
driveItem(id(file), name(file), parent(1, name(folder)), id(folder), isFile),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DeltaUpdate: pagers.DeltaUpdate{URL: delta, Reset: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
canUsePreviousBackup: true,
|
||||||
|
errCheck: assert.NoError,
|
||||||
|
previousPaths: map[string]map[string]string{
|
||||||
|
idx(drive, 1): {
|
||||||
|
rootID: fullPath(1),
|
||||||
|
id(folder): fullPath(1, name(folder)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||||
|
fullPath(1): {data.NewState: {}},
|
||||||
|
fullPath(1, name(folder)): {
|
||||||
|
data.NewState: {id(folder), id(file)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedDeltaURLs: map[string]string{
|
||||||
|
idx(drive, 1): delta,
|
||||||
|
},
|
||||||
|
expectedPreviousPaths: map[string]map[string]string{
|
||||||
|
idx(drive, 1): {
|
||||||
|
rootID: fullPath(1),
|
||||||
|
id(folder): fullPath(1, name(folder)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedDelList: pmMock.NewPrefixMap(map[string]map[string]struct{}{}),
|
||||||
|
doNotMergeItems: map[string]bool{
|
||||||
|
fullPath(1): true,
|
||||||
|
fullPath(1, name(folder)): true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "OneDrive_OneItemPage_ImmediateInvalidPrevDelta_MoveFolderToPreviouslyExistingPath",
|
||||||
|
drives: []models.Driveable{drive1},
|
||||||
|
enumerator: mock.EnumerateItemsDeltaByDrive{
|
||||||
|
DrivePagers: map[string]*mock.DriveItemsDeltaPager{
|
||||||
|
idx(drive, 1): {
|
||||||
|
Pages: []mock.NextPage{
|
||||||
|
{
|
||||||
|
Items: []models.DriveItemable{},
|
||||||
|
Reset: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Items: []models.DriveItemable{
|
||||||
|
driveRootItem(rootID),
|
||||||
|
driveItem(idx(folder, 2), name(folder), parent(1), rootID, isFolder),
|
||||||
|
driveItem(idx(file, 2), name(file), parent(1, name(folder)), idx(folder, 2), isFile),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DeltaUpdate: pagers.DeltaUpdate{URL: delta, Reset: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
canUsePreviousBackup: true,
|
||||||
|
errCheck: assert.NoError,
|
||||||
|
previousPaths: map[string]map[string]string{
|
||||||
|
idx(drive, 1): {
|
||||||
|
rootID: fullPath(1),
|
||||||
|
id(folder): fullPath(1, name(folder)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||||
|
fullPath(1): {data.NewState: {}},
|
||||||
|
fullPath(1, name(folder)): {
|
||||||
|
data.DeletedState: {},
|
||||||
|
data.NewState: {idx(folder, 2), idx(file, 2)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedDeltaURLs: map[string]string{
|
||||||
|
idx(drive, 1): delta,
|
||||||
|
},
|
||||||
|
expectedPreviousPaths: map[string]map[string]string{
|
||||||
|
idx(drive, 1): {
|
||||||
|
rootID: fullPath(1),
|
||||||
|
idx(folder, 2): fullPath(1, name(folder)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedDelList: pmMock.NewPrefixMap(map[string]map[string]struct{}{}),
|
||||||
|
doNotMergeItems: map[string]bool{
|
||||||
|
fullPath(1): true,
|
||||||
|
fullPath(1, name(folder)): true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "OneDrive_OneItemPage_InvalidPrevDelta_AnotherFolderAtDeletedLocation",
|
name: "OneDrive_OneItemPage_InvalidPrevDelta_AnotherFolderAtDeletedLocation",
|
||||||
drives: []models.Driveable{drive1},
|
drives: []models.Driveable{drive1},
|
||||||
@ -2555,7 +2667,7 @@ func (suite *CollectionsUnitSuite) TestGet() {
|
|||||||
},
|
},
|
||||||
expectedCollections: map[string]map[data.CollectionState][]string{
|
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||||
fullPath(1): {data.NewState: {}},
|
fullPath(1): {data.NewState: {}},
|
||||||
fullPath(1, name(folder)): {data.NotMovedState: {id(folder), id(file)}},
|
fullPath(1, name(folder)): {data.NewState: {id(folder), id(file)}},
|
||||||
fullPath(1, namex(folder, 2)): {data.DeletedState: {}},
|
fullPath(1, namex(folder, 2)): {data.DeletedState: {}},
|
||||||
},
|
},
|
||||||
expectedDeltaURLs: map[string]string{
|
expectedDeltaURLs: map[string]string{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user