From 8ff7f772672b51dcedd9668b16c19083aae3ca60 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Sun, 3 Dec 2023 22:46:07 -0800 Subject: [PATCH] Move conversion up in the func --- src/internal/m365/collection/drive/collection.go | 11 ++++------- src/internal/m365/collection/drive/collection_test.go | 10 +++++----- src/internal/m365/collection/drive/collections.go | 9 ++++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/internal/m365/collection/drive/collection.go b/src/internal/m365/collection/drive/collection.go index 16f0ff065..b49b039b0 100644 --- a/src/internal/m365/collection/drive/collection.go +++ b/src/internal/m365/collection/drive/collection.go @@ -10,7 +10,6 @@ import ( "time" "github.com/alcionai/clues" - "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/spatialcurrent/go-lazy/pkg/lazy" "github.com/alcionai/corso/src/internal/common/idname" @@ -191,11 +190,9 @@ func newColl( // Adds an itemID to the collection. This will make it eligible to be // populated. The return values denotes if the item was previously // present or is new one. -func (oc *Collection) Add(item models.DriveItemable) bool { - liteItem := custom.ToLiteDriveItemable(item) - - _, found := oc.driveItems[ptr.Val(liteItem.GetId())] - oc.driveItems[ptr.Val(liteItem.GetId())] = liteItem +func (oc *Collection) Add(item custom.LiteDriveItemable) bool { + _, found := oc.driveItems[ptr.Val(item.GetId())] + oc.driveItems[ptr.Val(item.GetId())] = item // if !found, it's a new addition return !found @@ -220,7 +217,7 @@ func (oc *Collection) IsEmpty() bool { // ContainsItem returns true if the collection has the given item as one of its // children. -func (oc Collection) ContainsItem(item models.DriveItemable) bool { +func (oc Collection) ContainsItem(item custom.LiteDriveItemable) bool { _, ok := oc.driveItems[ptr.Val(item.GetId())] return ok } diff --git a/src/internal/m365/collection/drive/collection_test.go b/src/internal/m365/collection/drive/collection_test.go index 8d66e5145..09e2ee845 100644 --- a/src/internal/m365/collection/drive/collection_test.go +++ b/src/internal/m365/collection/drive/collection_test.go @@ -233,7 +233,7 @@ func (suite *CollectionUnitSuite) TestCollection() { true) for i := 0; i < test.numInstances; i++ { - coll.Add(stubItem) + coll.Add(custom.ToLiteDriveItemable(stubItem)) } // Read items from the collection @@ -353,7 +353,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadError() { true, false) - coll.Add(stubItem) + coll.Add(custom.ToLiteDriveItemable(stubItem)) collItem, ok := <-coll.Items(ctx, fault.New(true)) assert.True(t, ok) @@ -423,7 +423,7 @@ func (suite *CollectionUnitSuite) TestCollectionReadUnauthorizedErrorRetry() { count.New()) require.NoError(t, err, clues.ToCore(err)) - coll.Add(stubItem) + coll.Add(custom.ToLiteDriveItemable(stubItem)) collItem, ok := <-coll.Items(ctx, fault.New(true)) assert.True(t, ok) @@ -491,7 +491,7 @@ func (suite *CollectionUnitSuite) TestCollectionPermissionBackupLatestModTime() true, false) - coll.Add(stubItem) + coll.Add(custom.ToLiteDriveItemable(stubItem)) coll.handler = mbh @@ -1021,7 +1021,7 @@ func (suite *CollectionUnitSuite) TestItemExtensions() { true, false) - coll.Add(stubItem) + coll.Add(custom.ToLiteDriveItemable(stubItem)) collItem, ok := <-coll.Items(ctx, fault.New(true)) assert.True(t, ok) diff --git a/src/internal/m365/collection/drive/collections.go b/src/internal/m365/collection/drive/collections.go index 2d6236a9a..d56590a6b 100644 --- a/src/internal/m365/collection/drive/collections.go +++ b/src/internal/m365/collection/drive/collections.go @@ -716,7 +716,7 @@ func (c *Collections) handleDelete( func (c *Collections) getCollectionPath( driveID string, - item models.DriveItemable, + item custom.LiteDriveItemable, ) (path.Path, error) { var ( pb = odConsts.DriveFolderPrefixBuilder(driveID) @@ -931,7 +931,7 @@ func (c *Collections) PopulateDriveCollections( func (c *Collections) processItem( ctx context.Context, - item models.DriveItemable, + di models.DriveItemable, driveID, driveName string, oldPrevPaths, currPrevPaths, newPrevPaths map[string]string, seenFolders map[string]string, @@ -944,6 +944,7 @@ func (c *Collections) processItem( skipper fault.AddSkipper, ) error { var ( + item = custom.ToLiteDriveItemable(di) itemID = ptr.Val(item.GetId()) itemName = ptr.Val(item.GetName()) isFolder = item.GetFolder() != nil || item.GetPackageEscaped() != nil @@ -956,9 +957,7 @@ func (c *Collections) processItem( "item_is_folder", isFolder) if item.GetMalware() != nil { - // TODO(pandeyabs): Fix this after we move the ToLiteDriveItemable call - // to the beginning of this func. - addtl := graph.ItemInfo(custom.ToLiteDriveItemable(item)) + addtl := graph.ItemInfo(item) skip := fault.FileSkip(fault.SkipMalware, driveID, itemID, itemName, addtl) if isFolder {