fix up failures found when manually testing (#4825)

correct the tree post-process traversal, ensuring the root folder doesn't appear twice in the path.  And provide the drive name to the collection so that the backup details can utilize it.

---

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

- [x]  No

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #4689

#### Test Plan

- [x] 💪 Manual
- [x]  Unit test
This commit is contained in:
Keepers 2023-12-14 16:28:16 -07:00 committed by GitHub
parent 505c06441a
commit e3363aaa46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 63 deletions

View File

@ -111,7 +111,7 @@ func NewCollection(
resource idname.Provider, resource idname.Provider,
currPath path.Path, currPath path.Path,
prevPath path.Path, prevPath path.Path,
driveID string, driveID, driveName string,
statusUpdater support.StatusUpdater, statusUpdater support.StatusUpdater,
ctrlOpts control.Options, ctrlOpts control.Options,
isPackageOrChildOfPackage bool, isPackageOrChildOfPackage bool,
@ -139,6 +139,7 @@ func NewCollection(
currPath, currPath,
prevPath, prevPath,
driveID, driveID,
driveName,
statusUpdater, statusUpdater,
ctrlOpts, ctrlOpts,
isPackageOrChildOfPackage, isPackageOrChildOfPackage,
@ -157,7 +158,7 @@ func newColl(
resource idname.Provider, resource idname.Provider,
currPath path.Path, currPath path.Path,
prevPath path.Path, prevPath path.Path,
driveID string, driveID, driveName string,
statusUpdater support.StatusUpdater, statusUpdater support.StatusUpdater,
ctrlOpts control.Options, ctrlOpts control.Options,
isPackageOrChildOfPackage bool, isPackageOrChildOfPackage bool,
@ -174,6 +175,7 @@ func newColl(
prevPath: prevPath, prevPath: prevPath,
driveItems: map[string]*custom.DriveItem{}, driveItems: map[string]*custom.DriveItem{},
driveID: driveID, driveID: driveID,
driveName: driveName,
data: dataCh, data: dataCh,
statusUpdater: statusUpdater, statusUpdater: statusUpdater,
ctrl: ctrlOpts, ctrl: ctrlOpts,

View File

@ -211,7 +211,8 @@ func (suite *CollectionUnitSuite) TestCollection() {
mbh.ProtectedResource, mbh.ProtectedResource,
folderPath, folderPath,
nil, nil,
"drive-id", id(drivePfx),
name(drivePfx),
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
control.Options{ToggleFeatures: control.Toggles{}}, control.Options{ToggleFeatures: control.Toggles{}},
false, false,
@ -303,7 +304,6 @@ func (suite *CollectionUnitSuite) TestCollectionReadError() {
stubItemID = "fakeItemID" stubItemID = "fakeItemID"
collStatus = support.ControllerOperationStatus{} collStatus = support.ControllerOperationStatus{}
wg = sync.WaitGroup{} wg = sync.WaitGroup{}
name = "name"
size = defaultFileSize size = defaultFileSize
now = time.Now() now = time.Now()
) )
@ -334,7 +334,8 @@ func (suite *CollectionUnitSuite) TestCollectionReadError() {
mbh.ProtectedResource, mbh.ProtectedResource,
folderPath, folderPath,
nil, nil,
"fakeDriveID", id(drivePfx),
name(drivePfx),
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
control.Options{ToggleFeatures: control.Toggles{}}, control.Options{ToggleFeatures: control.Toggles{}},
false, false,
@ -345,7 +346,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadError() {
stubItem := odTD.NewStubDriveItem( stubItem := odTD.NewStubDriveItem(
stubItemID, stubItemID,
name, name(drivePfx),
size, size,
now, now,
now, now,
@ -373,7 +374,6 @@ func (suite *CollectionUnitSuite) TestCollectionReadUnauthorizedErrorRetry() {
stubItemID = "fakeItemID" stubItemID = "fakeItemID"
collStatus = support.ControllerOperationStatus{} collStatus = support.ControllerOperationStatus{}
wg = sync.WaitGroup{} wg = sync.WaitGroup{}
name = "name"
size = defaultFileSize size = defaultFileSize
now = time.Now() now = time.Now()
) )
@ -385,7 +385,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadUnauthorizedErrorRetry() {
stubItem := odTD.NewStubDriveItem( stubItem := odTD.NewStubDriveItem(
stubItemID, stubItemID,
name, name(drivePfx),
size, size,
now, now,
now, now,
@ -413,7 +413,8 @@ func (suite *CollectionUnitSuite) TestCollectionReadUnauthorizedErrorRetry() {
mbh.ProtectedResource, mbh.ProtectedResource,
folderPath, folderPath,
nil, nil,
"fakeDriveID", id(drivePfx),
name(drivePfx),
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
control.Options{ToggleFeatures: control.Toggles{}}, control.Options{ToggleFeatures: control.Toggles{}},
false, false,
@ -470,7 +471,8 @@ func (suite *CollectionUnitSuite) TestCollectionPermissionBackupLatestModTime()
mbh.ProtectedResource, mbh.ProtectedResource,
folderPath, folderPath,
nil, nil,
"drive-id", id(drivePfx),
name(drivePfx),
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
control.Options{ToggleFeatures: control.Toggles{}}, control.Options{ToggleFeatures: control.Toggles{}},
false, false,
@ -837,7 +839,6 @@ func (suite *CollectionUnitSuite) TestItemExtensions() {
t = suite.T() t = suite.T()
stubItemID = "itemID" stubItemID = "itemID"
stubItemName = "name" stubItemName = "name"
driveID = "driveID"
collStatus = support.ControllerOperationStatus{} collStatus = support.ControllerOperationStatus{}
wg = sync.WaitGroup{} wg = sync.WaitGroup{}
now = time.Now() now = time.Now()
@ -1002,7 +1003,8 @@ func (suite *CollectionUnitSuite) TestItemExtensions() {
mbh.ProtectedResource, mbh.ProtectedResource,
folderPath, folderPath,
nil, nil,
driveID, id(drivePfx),
name(drivePfx),
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
opts, opts,
false, false,

View File

@ -489,6 +489,7 @@ func (c *Collections) Get(
nil, // delete the folder nil, // delete the folder
prevPath, prevPath,
driveID, driveID,
driveName,
c.statusUpdater, c.statusUpdater,
c.ctrl, c.ctrl,
false, false,
@ -527,6 +528,7 @@ func (c *Collections) Get(
nil, // delete the drive nil, // delete the drive
prevDrivePath, prevDrivePath,
driveID, driveID,
"",
c.statusUpdater, c.statusUpdater,
c.ctrl, c.ctrl,
false, false,
@ -698,6 +700,7 @@ func (c *Collections) handleDelete(
nil, // deletes the collection nil, // deletes the collection
prevPath, prevPath,
driveID, driveID,
"",
c.statusUpdater, c.statusUpdater,
c.ctrl, c.ctrl,
false, false,
@ -706,7 +709,7 @@ func (c *Collections) handleDelete(
nil, nil,
counter.Local()) counter.Local())
if err != nil { if err != nil {
return clues.Wrap(err, "making collection").With( return clues.WrapWC(ctx, err, "making collection").With(
"drive_id", driveID, "drive_id", driveID,
"item_id", itemID, "item_id", itemID,
"path_string", prevPathStr) "path_string", prevPathStr)
@ -1089,6 +1092,7 @@ func (c *Collections) processItem(
collectionPath, collectionPath,
prevPath, prevPath,
driveID, driveID,
driveName,
c.statusUpdater, c.statusUpdater,
c.ctrl, c.ctrl,
isPackage || childOfPackage, isPackage || childOfPackage,

View File

@ -220,7 +220,7 @@ func (c *Collections) makeDriveCollections(
collections, newPrevs, excludedItemIDs, err := c.turnTreeIntoCollections( collections, newPrevs, excludedItemIDs, err := c.turnTreeIntoCollections(
ctx, ctx,
tree, tree,
driveID, drv,
prevDeltaLink, prevDeltaLink,
countPagesInDelta, countPagesInDelta,
errs) errs)
@ -775,7 +775,7 @@ func addPrevPathsToTree(
func (c *Collections) turnTreeIntoCollections( func (c *Collections) turnTreeIntoCollections(
ctx context.Context, ctx context.Context,
tree *folderyMcFolderFace, tree *folderyMcFolderFace,
driveID string, drv models.Driveable,
prevDeltaLink string, prevDeltaLink string,
countPagesInDelta int, countPagesInDelta int,
errs *fault.Bus, errs *fault.Bus,
@ -796,6 +796,8 @@ func (c *Collections) turnTreeIntoCollections(
newPrevPaths = map[string]string{} newPrevPaths = map[string]string{}
uc *urlCache uc *urlCache
el = errs.Local() el = errs.Local()
driveID = ptr.Val(drv.GetId())
driveName = ptr.Val(drv.GetName())
) )
// Attach an url cache to the drive if the number of discovered items is // Attach an url cache to the drive if the number of discovered items is
@ -838,6 +840,7 @@ func (c *Collections) turnTreeIntoCollections(
cbl.currPath, cbl.currPath,
cbl.prevPath, cbl.prevPath,
driveID, driveID,
driveName,
c.statusUpdater, c.statusUpdater,
c.ctrl, c.ctrl,
cbl.isPackageOrChildOfPackage, cbl.isPackageOrChildOfPackage,

View File

@ -655,7 +655,7 @@ func (suite *CollectionsTreeUnitSuite) TestCollections_TurnTreeIntoCollections()
colls, newPrevPaths, excluded, err := c.turnTreeIntoCollections( colls, newPrevPaths, excluded, err := c.turnTreeIntoCollections(
ctx, ctx,
tree, tree,
d.id, d.able,
deltaURL, deltaURL,
countPages, countPages,
fault.New(true)) fault.New(true))

View File

@ -381,16 +381,15 @@ type collectable struct {
files map[string]*custom.DriveItem files map[string]*custom.DriveItem
folderID string folderID string
isPackageOrChildOfPackage bool isPackageOrChildOfPackage bool
loc path.Elements
prevPath path.Path prevPath path.Path
} }
// produces a map of folderID -> collectable // produces a map of folderID -> collectable
func (face *folderyMcFolderFace) generateCollectables() (map[string]collectable, error) { func (face *folderyMcFolderFace) generateCollectables() (map[string]collectable, error) {
result := map[string]collectable{} result := map[string]collectable{}
err := walkTreeAndBuildCollections(
err := face.walkTreeAndBuildCollections(
face.root, face.root,
face.prefix,
&path.Builder{}, &path.Builder{},
false, false,
result) result)
@ -410,10 +409,9 @@ func (face *folderyMcFolderFace) generateCollectables() (map[string]collectable,
return result, clues.Stack(err).OrNil() return result, clues.Stack(err).OrNil()
} }
func walkTreeAndBuildCollections( func (face *folderyMcFolderFace) walkTreeAndBuildCollections(
node *nodeyMcNodeFace, node *nodeyMcNodeFace,
pathPfx path.Path, location *path.Builder,
parentPath *path.Builder,
isChildOfPackage bool, isChildOfPackage bool,
result map[string]collectable, result map[string]collectable,
) error { ) error {
@ -421,14 +419,16 @@ func walkTreeAndBuildCollections(
return nil return nil
} }
parentLocation := parentPath.Elements() isRoot := node == face.root
currentLocation := parentPath.Append(node.name)
if !isRoot {
location = location.Append(node.name)
}
for _, child := range node.children { for _, child := range node.children {
err := walkTreeAndBuildCollections( err := face.walkTreeAndBuildCollections(
child, child,
pathPfx, location,
currentLocation,
node.isPackage || isChildOfPackage, node.isPackage || isChildOfPackage,
result) result)
if err != nil { if err != nil {
@ -436,12 +436,12 @@ func walkTreeAndBuildCollections(
} }
} }
collectionPath, err := pathPfx.Append(false, currentLocation.Elements()...) collectionPath, err := face.prefix.Append(false, location.Elements()...)
if err != nil { if err != nil {
return clues.Wrap(err, "building collection path"). return clues.Wrap(err, "building collection path").
With( With(
"path_prefix", pathPfx, "path_prefix", face.prefix,
"path_suffix", currentLocation.Elements()) "path_suffix", location.Elements())
} }
cbl := collectable{ cbl := collectable{
@ -449,7 +449,6 @@ func walkTreeAndBuildCollections(
files: node.files, files: node.files,
folderID: node.id, folderID: node.id,
isPackageOrChildOfPackage: node.isPackage || isChildOfPackage, isPackageOrChildOfPackage: node.isPackage || isChildOfPackage,
loc: parentLocation,
prevPath: node.prev, prevPath: node.prev,
} }

View File

@ -1021,7 +1021,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
}, },
}, },
}, },
@ -1037,7 +1036,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
}, },
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
}, },
}, },
}, },
@ -1051,14 +1049,12 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
}, },
folderID("parent"): { folderID("parent"): {
currPath: d.fullPath(t, folderName("parent")), currPath: d.fullPath(t, folderName("parent")),
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: folderID("parent"), folderID: folderID("parent"),
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{rootName},
}, },
folderID(): { folderID(): {
currPath: d.fullPath(t, folderName("parent"), folderName()), currPath: d.fullPath(t, folderName("parent"), folderName()),
@ -1067,7 +1063,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
}, },
folderID: folderID(), folderID: folderID(),
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{rootName, folderName("parent")},
}, },
}, },
}, },
@ -1093,21 +1088,18 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
}, },
id(pkg): { id(pkg): {
currPath: d.fullPath(t, name(pkg)), currPath: d.fullPath(t, name(pkg)),
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: id(pkg), folderID: id(pkg),
isPackageOrChildOfPackage: true, isPackageOrChildOfPackage: true,
loc: path.Elements{rootName},
}, },
folderID(): { folderID(): {
currPath: d.fullPath(t, name(pkg), folderName()), currPath: d.fullPath(t, name(pkg), folderName()),
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: folderID(), folderID: folderID(),
isPackageOrChildOfPackage: true, isPackageOrChildOfPackage: true,
loc: path.Elements{rootName, name(pkg)},
}, },
}, },
}, },
@ -1126,7 +1118,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
prevPath: d.fullPath(t), prevPath: d.fullPath(t),
}, },
folderID("parent"): { folderID("parent"): {
@ -1134,7 +1125,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: folderID("parent"), folderID: folderID("parent"),
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{rootName},
prevPath: d.fullPath(t, folderName("parent-prev")), prevPath: d.fullPath(t, folderName("parent-prev")),
}, },
folderID(): { folderID(): {
@ -1144,7 +1134,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{ files: map[string]*custom.DriveItem{
fileID(): custom.ToCustomDriveItem(d.fileAt("parent")), fileID(): custom.ToCustomDriveItem(d.fileAt("parent")),
}, },
loc: path.Elements{rootName, folderName("parent")},
prevPath: d.fullPath(t, folderName("parent-prev"), folderName()), prevPath: d.fullPath(t, folderName("parent-prev"), folderName()),
}, },
}, },
@ -1163,7 +1152,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
files: map[string]*custom.DriveItem{}, files: map[string]*custom.DriveItem{},
folderID: rootID, folderID: rootID,
isPackageOrChildOfPackage: false, isPackageOrChildOfPackage: false,
loc: path.Elements{},
prevPath: d.fullPath(t), prevPath: d.fullPath(t),
}, },
folderID(): { folderID(): {
@ -1212,12 +1200,6 @@ func (suite *DeltaTreeUnitSuite) TestFolderyMcFolderFace_GenerateCollectables()
assert.Equal(t, expect.prevPath.String(), result.prevPath.String()) assert.Equal(t, expect.prevPath.String(), result.prevPath.String())
} }
if expect.loc == nil {
assert.Nil(t, result.loc)
} else {
assert.Equal(t, expect.loc.PlainString(), result.loc.PlainString())
}
assert.ElementsMatch(t, maps.Keys(expect.files), maps.Keys(result.files)) assert.ElementsMatch(t, maps.Keys(expect.files), maps.Keys(result.files))
} }
}) })

View File

@ -440,20 +440,7 @@ func (ecs expectedCollections) requireNoUnseenCollections(t *testing.T) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
func defaultTreePfx(t *testing.T, d *deltaDrive) path.Path { func defaultTreePfx(t *testing.T, d *deltaDrive) path.Path {
fpb := d.fullPath(t).ToBuilder() return d.fullPath(t)
fpe := fpb.Elements()
fpe = fpe[:len(fpe)-1]
fpb = path.Builder{}.Append(fpe...)
p, err := path.FromDataLayerPath(fpb.String(), false)
require.NoErrorf(
t,
err,
"err processing path:\n\terr %+v\n\tpath %q",
clues.ToCore(err),
fpb)
return p
} }
func defaultLoc() path.Elements { func defaultLoc() path.Elements {