diff --git a/src/cli/utils/sharepoint.go b/src/cli/utils/sharepoint.go index 5c2960f71..c3fdd69a7 100644 --- a/src/cli/utils/sharepoint.go +++ b/src/cli/utils/sharepoint.go @@ -54,48 +54,47 @@ func IncludeSharePointRestoreDataSelectors( sel *selectors.SharePointRestore, opts SharePointOpts, ) { - lp, ln, lwu := len(opts.LibraryPaths), len(opts.LibraryItems), len(opts.WebURLs) + lp, li := len(opts.LibraryPaths), len(opts.LibraryItems) + ls, lwu := len(opts.Sites), len(opts.WebURLs) - // only use the inclusion if either a path or item name - // is specified - if lp+ln == 0 { - return - } - - if len(opts.Sites) == 0 { + if ls == 0 { opts.Sites = selectors.Any() } - if lp+ln+lwu == 0 { + if lp+li+lwu == 0 { sel.Include(sel.Sites(opts.Sites)) return } - opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths) + if lp+li > 0 { + if li == 0 { + opts.LibraryItems = selectors.Any() + } - if ln == 0 { - opts.LibraryItems = selectors.Any() + opts.LibraryPaths = trimFolderSlash(opts.LibraryPaths) + containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths) + + if len(containsFolders) > 0 { + sel.Include(sel.LibraryItems(opts.Sites, containsFolders, opts.LibraryItems)) + } + + if len(prefixFolders) > 0 { + sel.Include(sel.LibraryItems(opts.Sites, prefixFolders, opts.LibraryItems, selectors.PrefixMatch())) + } } - containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs) + if lwu > 0 { + opts.WebURLs = trimFolderSlash(opts.WebURLs) + containsURLs, suffixURLs := splitFoldersIntoContainsAndPrefix(opts.WebURLs) - if len(containsURLs) > 0 { - sel.Include(sel.WebURL(containsURLs)) - } + if len(containsURLs) > 0 { + sel.Include(sel.WebURL(containsURLs)) + } - if len(suffixURLs) > 0 { - sel.Include(sel.WebURL(suffixURLs, selectors.SuffixMatch())) - } - - containsFolders, prefixFolders := splitFoldersIntoContainsAndPrefix(opts.LibraryPaths) - - if len(containsFolders) > 0 { - sel.Include(sel.LibraryItems(opts.Sites, containsFolders, opts.LibraryItems)) - } - - if len(prefixFolders) > 0 { - sel.Include(sel.LibraryItems(opts.Sites, prefixFolders, opts.LibraryItems, selectors.PrefixMatch())) + if len(suffixURLs) > 0 { + sel.Include(sel.WebURL(suffixURLs, selectors.SuffixMatch())) + } } } diff --git a/src/cli/utils/sharepoint_test.go b/src/cli/utils/sharepoint_test.go index e6fdea1ac..d00aae671 100644 --- a/src/cli/utils/sharepoint_test.go +++ b/src/cli/utils/sharepoint_test.go @@ -19,8 +19,6 @@ func TestSharePointUtilsSuite(t *testing.T) { } func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { - suite.T().Skip("just until next PR") - var ( empty = []string{} single = []string{"single"} @@ -43,7 +41,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { Sites: empty, WebURLs: empty, }, - expectIncludeLen: 0, + expectIncludeLen: 1, }, { name: "single inputs", @@ -53,7 +51,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { Sites: single, WebURLs: single, }, - expectIncludeLen: 1, + expectIncludeLen: 2, }, { name: "multi inputs", @@ -63,7 +61,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { Sites: multi, WebURLs: multi, }, - expectIncludeLen: 1, + expectIncludeLen: 2, }, { name: "library contains", diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index a0ec1c34e..4053bc879 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -355,7 +355,7 @@ type SharePointInfo struct { ItemType ItemType `json:"itemType,omitempty"` Modified time.Time `josn:"modified,omitempty"` Owner string `json:"owner,omitempty"` - ParentPath string `json:"parentPath"` + ParentPath string `json:"parentPath,omitempty"` Size int64 `json:"size,omitempty"` WebURL string `json:"webUrl,omitempty"` } @@ -363,13 +363,20 @@ type SharePointInfo struct { // Headers returns the human-readable names of properties in a SharePointInfo // for printing out to a terminal in a columnar display. func (i SharePointInfo) Headers() []string { - return []string{} + return []string{"ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"} } // Values returns the values matching the Headers list for printing // out to a terminal in a columnar display. func (i SharePointInfo) Values() []string { - return []string{} + return []string{ + i.ItemName, + i.ParentPath, + humanize.Bytes(uint64(i.Size)), + i.WebURL, + common.FormatTabularDisplayTime(i.Created), + common.FormatTabularDisplayTime(i.Modified), + } } // OneDriveInfo describes a oneDrive item @@ -393,7 +400,11 @@ func (i OneDriveInfo) Headers() []string { // out to a terminal in a columnar display. func (i OneDriveInfo) Values() []string { return []string{ - i.ItemName, i.ParentPath, humanize.Bytes(uint64(i.Size)), i.Owner, - common.FormatTabularDisplayTime(i.Created), common.FormatTabularDisplayTime(i.Modified), + i.ItemName, + i.ParentPath, + humanize.Bytes(uint64(i.Size)), + i.Owner, + common.FormatTabularDisplayTime(i.Created), + common.FormatTabularDisplayTime(i.Modified), } } diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index f007fd63c..093eeb886 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -102,11 +102,18 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { RepoRef: "reporef", ShortRef: "deadbeef", ItemInfo: details.ItemInfo{ - SharePoint: &details.SharePointInfo{}, + SharePoint: &details.SharePointInfo{ + ItemName: "itemName", + ParentPath: "parentPath", + Size: 1000, + WebURL: "https://not.a.real/url", + Created: now, + Modified: now, + }, }, }, - expectHs: []string{"ID"}, - expectVs: []string{"deadbeef"}, + expectHs: []string{"ID", "ItemName", "ParentPath", "Size", "WebURL", "Created", "Modified"}, + expectVs: []string{"deadbeef", "itemName", "parentPath", "1.0 kB", "https://not.a.real/url", nowStr, nowStr}, }, { name: "oneDrive info",