From 6fe91e254a56e8845e6d925bddf2143f54db6e75 Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Tue, 21 Feb 2023 15:24:59 -0800 Subject: [PATCH] Expand set of folders selectors match on Expand the set of folders selectors match on so they match if either 1. the parent path matches (mostly for items using folder selection) 2. the folder path matches --- .../connector/onedrive/collections.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/internal/connector/onedrive/collections.go b/src/internal/connector/onedrive/collections.go index 2a1707a67..de9f63544 100644 --- a/src/internal/connector/onedrive/collections.go +++ b/src/internal/connector/onedrive/collections.go @@ -562,8 +562,21 @@ func (c *Collections) UpdateCollections( return err } + var ( + folderPath path.Path + isFolder = item.GetFolder() != nil || item.GetPackage() != nil + ) + + if item.GetName() != nil { + folderPath, err = collectionPath.Append(*item.GetName(), !isFolder) + if err != nil { + return err + } + } + // Skip items that don't match the folder selectors we were given. - if shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) { + if shouldSkipDrive(ctx, folderPath, c.matcher, driveName) && + shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) { logger.Ctx(ctx).Infof("Skipping path %s", collectionPath.String()) continue } @@ -616,15 +629,6 @@ func (c *Collections) UpdateCollections( break } - // Deletions of folders are handled in this case so we may as well start - // off by saving the path.Path of the item instead of just the OneDrive - // parentRef or such. - folderPath, err := collectionPath.Append(*item.GetName(), false) - if err != nil { - logger.Ctx(ctx).Errorw("failed building collection path", "error", err) - return err - } - // 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. @@ -770,6 +774,10 @@ func (c *Collections) UpdateCollections( } func shouldSkipDrive(ctx context.Context, drivePath path.Path, m folderMatcher, driveName string) bool { + if drivePath == nil { + return false + } + return !includePath(ctx, m, drivePath) || (drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName) }