diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index 3517fc2d8..7a8fce3f3 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -275,7 +275,7 @@ func GetAllFolders( return nil, errors.Wrap(err, "getting OneDrive folders") } - res := []*Displayable{} + folders := map[string]*Displayable{} for _, d := range drives { err = collectItems( @@ -294,13 +294,18 @@ func GetAllFolders( continue } + if item.GetId() == nil || len(*item.GetId()) == 0 { + logger.Ctx(ctx).Warn("folder without ID") + continue + } + if !strings.HasPrefix(*item.GetName(), prefix) { continue } // Add the item instead of the folder because the item has more // functionality. - res = append(res, &Displayable{item}) + folders[*item.GetId()] = &Displayable{item} } return nil @@ -311,6 +316,12 @@ func GetAllFolders( } } + res := make([]*Displayable, 0, len(folders)) + + for _, f := range folders { + res = append(res, f) + } + return res, nil } diff --git a/src/internal/kopia/snapshot_manager_test.go b/src/internal/kopia/snapshot_manager_test.go index cfd046f01..015c000e6 100644 --- a/src/internal/kopia/snapshot_manager_test.go +++ b/src/internal/kopia/snapshot_manager_test.go @@ -526,8 +526,6 @@ func (suite *SnapshotFetchUnitSuite) TestFetchPrevSnapshotsWorksWithErrors() { ), } - expected := []*snapshot.Manifest{mockData[2].man} - msm := &mockErrorSnapshotManager{ sm: &mockSnapshotManager{ data: mockData, @@ -536,5 +534,7 @@ func (suite *SnapshotFetchUnitSuite) TestFetchPrevSnapshotsWorksWithErrors() { snaps := fetchPrevSnapshotManifests(ctx, msm, input) - assert.ElementsMatch(t, expected, snaps) + // Only 1 snapshot should be chosen because the other two attempts fail. + // However, which one is returned is non-deterministic because maps are used. + assert.Len(t, snaps, 1) }