From 245d3ee089e974c392e74c2374719effc1988246 Mon Sep 17 00:00:00 2001 From: neha_gupta Date: Thu, 11 May 2023 11:04:13 +0530 Subject: [PATCH] treat / as root for restore of onedrive and sharepoint (#3328) passing '/' will select anything for backup details and restore for onedrive and sharepoint #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * #https://github.com/alcionai/corso/issues/3252 #### Test Plan - [x] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/cli/utils/flags.go | 6 ++++++ src/cli/utils/onedrive_test.go | 11 +++++++++++ src/cli/utils/sharepoint_test.go | 9 +++++++++ src/cli/utils/testdata/opts.go | 14 ++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/cli/utils/flags.go b/src/cli/utils/flags.go index b03fe2e06..3ca50d93e 100644 --- a/src/cli/utils/flags.go +++ b/src/cli/utils/flags.go @@ -10,6 +10,7 @@ import ( "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/pkg/path" + "github.com/alcionai/corso/src/pkg/selectors" ) // common flag vars (eg: FV) @@ -215,6 +216,11 @@ func trimFolderSlash(folders []string) []string { res := make([]string, 0, len(folders)) for _, p := range folders { + if p == string(path.PathSeparator) { + res = selectors.Any() + break + } + // Use path package because it has logic to handle escaping already. res = append(res, path.TrimTrailingSlash(p)) } diff --git a/src/cli/utils/onedrive_test.go b/src/cli/utils/onedrive_test.go index 43c0507c0..61653045f 100644 --- a/src/cli/utils/onedrive_test.go +++ b/src/cli/utils/onedrive_test.go @@ -8,6 +8,7 @@ import ( "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/path" ) type OneDriveUtilsSuite struct { @@ -26,6 +27,7 @@ func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() { containsOnly = []string{"contains"} prefixOnly = []string{"/prefix"} containsAndPrefix = []string{"contains", "/prefix"} + onlySlash = []string{string(path.PathSeparator)} ) table := []struct { @@ -87,6 +89,15 @@ func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() { }, expectIncludeLen: 2, }, + { + name: "folder with just /", + opts: utils.OneDriveOpts{ + Users: empty, + FileName: empty, + FolderPath: onlySlash, + }, + expectIncludeLen: 1, + }, } for _, test := range table { suite.Run(test.name, func() { diff --git a/src/cli/utils/sharepoint_test.go b/src/cli/utils/sharepoint_test.go index 41bb87e10..0201ab29e 100644 --- a/src/cli/utils/sharepoint_test.go +++ b/src/cli/utils/sharepoint_test.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/selectors" ) @@ -30,6 +31,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { containsOnly = []string{"contains"} prefixOnly = []string{"/prefix"} containsAndPrefix = []string{"contains", "/prefix"} + onlySlash = []string{string(path.PathSeparator)} ) table := []struct { @@ -182,6 +184,13 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { }, expectIncludeLen: 2, }, + { + name: "folder with just /", + opts: utils.SharePointOpts{ + FolderPath: onlySlash, + }, + expectIncludeLen: 1, + }, } for _, test := range table { suite.Run(test.name, func() { diff --git a/src/cli/utils/testdata/opts.go b/src/cli/utils/testdata/opts.go index cde3023fd..8bbb35a58 100644 --- a/src/cli/utils/testdata/opts.go +++ b/src/cli/utils/testdata/opts.go @@ -356,6 +356,13 @@ var ( FolderPath: selectors.Any(), }, }, + { + Name: "FilesWithSingleSlash", + Expected: testdata.OneDriveItems, + Opts: utils.OneDriveOpts{ + FolderPath: []string{"/"}, + }, + }, { Name: "FolderPrefixMatch", Expected: testdata.OneDriveItems, @@ -482,6 +489,13 @@ var ( FolderPath: selectors.Any(), }, }, + { + Name: "LibraryItemsWithSingleSlash", + Expected: testdata.SharePointLibraryItems, + Opts: utils.SharePointOpts{ + FolderPath: []string{"/"}, + }, + }, { Name: "FolderPrefixMatch", Expected: testdata.SharePointLibraryItems,