From 98b7665249c6d669a0a8b887a8155e3c0f4567bd Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Wed, 22 Feb 2023 12:04:56 -0800 Subject: [PATCH] Update based on reviewer comments --- .../graph_connector_onedrive_test.go | 14 +++--------- .../connector/onedrive/collections.go | 22 ++++++++++++------- src/internal/connector/onedrive/restore.go | 5 ++++- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/internal/connector/graph_connector_onedrive_test.go b/src/internal/connector/graph_connector_onedrive_test.go index dc8d5169c..7959632ec 100644 --- a/src/internal/connector/graph_connector_onedrive_test.go +++ b/src/internal/connector/graph_connector_onedrive_test.go @@ -175,11 +175,7 @@ func (c *onedriveCollection) withFile( name+onedrive.DataFileSuffix, fileData)) - case 1: - fallthrough - case 2: - fallthrough - case 3: + case 1, 2, 3: c.items = append(c.items, onedriveItemWithData( c.t, name+onedrive.DataFileSuffix, @@ -208,14 +204,10 @@ func (c *onedriveCollection) withFolder( roles []string, ) *onedriveCollection { switch c.backupVersion { - case 0: - fallthrough - case 3: + case 0, 3: return c - case 1: - fallthrough - case 2: + case 1, 2: c.items = append( c.items, onedriveMetadata( diff --git a/src/internal/connector/onedrive/collections.go b/src/internal/connector/onedrive/collections.go index df8106f86..e82fbd645 100644 --- a/src/internal/connector/onedrive/collections.go +++ b/src/internal/connector/onedrive/collections.go @@ -13,6 +13,7 @@ import ( "github.com/pkg/errors" "golang.org/x/exp/maps" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -563,19 +564,24 @@ func (c *Collections) UpdateCollections( } var ( - folderPath path.Path - isFolder = item.GetFolder() != nil || item.GetPackage() != nil + itemPath path.Path + isFolder = item.GetFolder() != nil || item.GetPackage() != nil ) - if item.GetName() != nil { - folderPath, err = collectionPath.Append(*item.GetName(), !isFolder) + if item.GetDeleted() == nil { + name := ptr.Val(item.GetName()) + if len(name) == 0 { + return clues.New("non-deleted item with empty name").With("item_id", name) + } + + itemPath, err = collectionPath.Append(name, !isFolder) if err != nil { return err } } // Skip items that don't match the folder selectors we were given. - if shouldSkipDrive(ctx, folderPath, c.matcher, driveName) && + if shouldSkipDrive(ctx, itemPath, c.matcher, driveName) && shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) { logger.Ctx(ctx).Infof("Skipping path %s", collectionPath.String()) continue @@ -625,9 +631,9 @@ func (c *Collections) UpdateCollections( // Moved folders don't cause delta results for any subfolders nested in // them. We need to go through and update paths to handle that. We only // update newPaths so we don't accidentally clobber previous deletes. - updatePath(newPaths, *item.GetId(), folderPath.String()) + updatePath(newPaths, *item.GetId(), itemPath.String()) - found, err := updateCollectionPaths(*item.GetId(), c.CollectionMap, folderPath) + found, err := updateCollectionPaths(*item.GetId(), c.CollectionMap, itemPath) if err != nil { return err } @@ -635,7 +641,7 @@ func (c *Collections) UpdateCollections( if !found { col := NewCollection( c.itemClient, - folderPath, + itemPath, prevPath, driveID, c.service, diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 367812e73..50a5d8a2c 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -41,7 +41,10 @@ const ( // name. // TODO(ashmrtn): Update this to a real value when we merge the file name // change. Set to MAXINT for now to keep the if-check using it working. - versionWithNameInMeta = math.MaxInt + versionWithNameInMeta = math.MaxInt + // versionWithDataAndMetaFilesInDir moves the .dirmeta entries to the + // directory they belong to instead of being in the parent of the directory + // they belong to. versionWithDataAndMetaFilesInDir = 3 )