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
This commit is contained in:
Ashlie Martinez 2023-02-21 15:24:59 -08:00
parent 856c2130e5
commit 6fe91e254a

View File

@ -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)
}