Update Exchange backup detail ParentPath when merging details (#2826)
Exchange now holds a reference to the parent folder so be sure to update that if needed when merging backup details Calendar is the only thing that populates location ref right now so this alone doesn't completely solve the issue --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [x] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change - [ ] 🌻 Feature - [x] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) * #2819 #### Test Plan - [x] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
17cb3db524
commit
dfceb79e0a
@ -577,7 +577,7 @@ func mergeDetails(
|
|||||||
|
|
||||||
// Fixup paths in the item.
|
// Fixup paths in the item.
|
||||||
item := entry.ItemInfo
|
item := entry.ItemInfo
|
||||||
if err := details.UpdateItem(&item, newPath); err != nil {
|
if err := details.UpdateItem(&item, newPath, newLoc); err != nil {
|
||||||
return clues.New("updating item details").WithClues(mctx)
|
return clues.New("updating item details").WithClues(mctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -292,6 +292,7 @@ func makeDetailsEntry(
|
|||||||
res.Exchange = &details.ExchangeInfo{
|
res.Exchange = &details.ExchangeInfo{
|
||||||
ItemType: details.ExchangeMail,
|
ItemType: details.ExchangeMail,
|
||||||
Size: int64(size),
|
Size: int64(size),
|
||||||
|
ParentPath: l.Folder(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
case path.OneDriveService:
|
case path.OneDriveService:
|
||||||
|
|||||||
@ -468,12 +468,14 @@ const (
|
|||||||
FolderItem ItemType = 306
|
FolderItem ItemType = 306
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateItem(item *ItemInfo, repoPath path.Path) error {
|
func UpdateItem(item *ItemInfo, repoPath, locPath path.Path) error {
|
||||||
// Only OneDrive and SharePoint have information about parent folders
|
// Only OneDrive and SharePoint have information about parent folders
|
||||||
// contained in them.
|
// contained in them.
|
||||||
var updatePath func(path.Path) error
|
var updatePath func(repo path.Path, location path.Path) error
|
||||||
|
|
||||||
switch item.infoType() {
|
switch item.infoType() {
|
||||||
|
case ExchangeContact, ExchangeEvent, ExchangeMail:
|
||||||
|
updatePath = item.Exchange.UpdateParentPath
|
||||||
case SharePointLibrary:
|
case SharePointLibrary:
|
||||||
updatePath = item.SharePoint.UpdateParentPath
|
updatePath = item.SharePoint.UpdateParentPath
|
||||||
case OneDriveItem:
|
case OneDriveItem:
|
||||||
@ -482,7 +484,7 @@ func UpdateItem(item *ItemInfo, repoPath path.Path) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return updatePath(repoPath)
|
return updatePath(repoPath, locPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemInfo is a oneOf that contains service specific
|
// ItemInfo is a oneOf that contains service specific
|
||||||
@ -630,6 +632,17 @@ func (i ExchangeInfo) Values() []string {
|
|||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *ExchangeInfo) UpdateParentPath(_, locPath path.Path) error {
|
||||||
|
// Not all data types have this set yet.
|
||||||
|
if locPath == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
i.ParentPath = locPath.Folder(true)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SharePointInfo describes a sharepoint item
|
// SharePointInfo describes a sharepoint item
|
||||||
type SharePointInfo struct {
|
type SharePointInfo struct {
|
||||||
Created time.Time `json:"created,omitempty"`
|
Created time.Time `json:"created,omitempty"`
|
||||||
@ -664,7 +677,7 @@ func (i SharePointInfo) Values() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *SharePointInfo) UpdateParentPath(newPath path.Path) error {
|
func (i *SharePointInfo) UpdateParentPath(newPath, _ path.Path) error {
|
||||||
newParent, err := path.GetDriveFolderPath(newPath)
|
newParent, err := path.GetDriveFolderPath(newPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return clues.Wrap(err, "making sharePoint path").With("path", newPath)
|
return clues.Wrap(err, "making sharePoint path").With("path", newPath)
|
||||||
@ -708,7 +721,7 @@ func (i OneDriveInfo) Values() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *OneDriveInfo) UpdateParentPath(newPath path.Path) error {
|
func (i *OneDriveInfo) UpdateParentPath(newPath, _ path.Path) error {
|
||||||
newParent, err := path.GetDriveFolderPath(newPath)
|
newParent, err := path.GetDriveFolderPath(newPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return clues.Wrap(err, "making oneDrive path").With("path", newPath)
|
return clues.Wrap(err, "making oneDrive path").With("path", newPath)
|
||||||
|
|||||||
@ -860,6 +860,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
driveID = "abcd"
|
driveID = "abcd"
|
||||||
folder1 = "f1"
|
folder1 = "f1"
|
||||||
folder2 = "f2"
|
folder2 = "f2"
|
||||||
|
folder3 = "f3"
|
||||||
item = "hello.txt"
|
item = "hello.txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -879,6 +880,17 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
item,
|
item,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
newExchangePath := makeItemPath(
|
||||||
|
suite.T(),
|
||||||
|
path.ExchangeService,
|
||||||
|
path.EmailCategory,
|
||||||
|
tenant,
|
||||||
|
resourceOwner,
|
||||||
|
[]string{
|
||||||
|
folder3,
|
||||||
|
item,
|
||||||
|
},
|
||||||
|
)
|
||||||
badOneDrivePath := makeItemPath(
|
badOneDrivePath := makeItemPath(
|
||||||
suite.T(),
|
suite.T(),
|
||||||
path.OneDriveService,
|
path.OneDriveService,
|
||||||
@ -897,44 +909,56 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
expectedItem ItemInfo
|
expectedItem ItemInfo
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "ExchangeEventNoChange",
|
name: "ExchangeEvent",
|
||||||
input: ItemInfo{
|
input: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeEvent,
|
ItemType: ExchangeEvent,
|
||||||
|
ParentPath: folder1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
repoPath: newOneDrivePath,
|
||||||
|
locPath: newExchangePath,
|
||||||
errCheck: assert.NoError,
|
errCheck: assert.NoError,
|
||||||
expectedItem: ItemInfo{
|
expectedItem: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeEvent,
|
ItemType: ExchangeEvent,
|
||||||
|
ParentPath: folder3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ExchangeContactNoChange",
|
name: "ExchangeContact",
|
||||||
input: ItemInfo{
|
input: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeContact,
|
ItemType: ExchangeContact,
|
||||||
|
ParentPath: folder1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
repoPath: newOneDrivePath,
|
||||||
|
locPath: newExchangePath,
|
||||||
errCheck: assert.NoError,
|
errCheck: assert.NoError,
|
||||||
expectedItem: ItemInfo{
|
expectedItem: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeContact,
|
ItemType: ExchangeContact,
|
||||||
|
ParentPath: folder3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ExchangeMailNoChange",
|
name: "ExchangeMail",
|
||||||
input: ItemInfo{
|
input: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeMail,
|
ItemType: ExchangeMail,
|
||||||
|
ParentPath: folder1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
repoPath: newOneDrivePath,
|
||||||
|
locPath: newExchangePath,
|
||||||
errCheck: assert.NoError,
|
errCheck: assert.NoError,
|
||||||
expectedItem: ItemInfo{
|
expectedItem: ItemInfo{
|
||||||
Exchange: &ExchangeInfo{
|
Exchange: &ExchangeInfo{
|
||||||
ItemType: ExchangeMail,
|
ItemType: ExchangeMail,
|
||||||
|
ParentPath: folder3,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -947,7 +971,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
repoPath: newOneDrivePath,
|
repoPath: newOneDrivePath,
|
||||||
locPath: newOneDrivePath,
|
locPath: newExchangePath,
|
||||||
errCheck: assert.NoError,
|
errCheck: assert.NoError,
|
||||||
expectedItem: ItemInfo{
|
expectedItem: ItemInfo{
|
||||||
OneDrive: &OneDriveInfo{
|
OneDrive: &OneDriveInfo{
|
||||||
@ -965,7 +989,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
repoPath: newOneDrivePath,
|
repoPath: newOneDrivePath,
|
||||||
locPath: newOneDrivePath,
|
locPath: newExchangePath,
|
||||||
errCheck: assert.NoError,
|
errCheck: assert.NoError,
|
||||||
expectedItem: ItemInfo{
|
expectedItem: ItemInfo{
|
||||||
SharePoint: &SharePointInfo{
|
SharePoint: &SharePointInfo{
|
||||||
@ -983,7 +1007,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
repoPath: badOneDrivePath,
|
repoPath: badOneDrivePath,
|
||||||
locPath: badOneDrivePath,
|
locPath: newExchangePath,
|
||||||
errCheck: assert.Error,
|
errCheck: assert.Error,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -995,7 +1019,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
repoPath: badOneDrivePath,
|
repoPath: badOneDrivePath,
|
||||||
locPath: badOneDrivePath,
|
locPath: newExchangePath,
|
||||||
errCheck: assert.Error,
|
errCheck: assert.Error,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1005,7 +1029,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() {
|
|||||||
t := suite.T()
|
t := suite.T()
|
||||||
item := test.input
|
item := test.input
|
||||||
|
|
||||||
err := UpdateItem(&item, test.repoPath)
|
err := UpdateItem(&item, test.repoPath, test.locPath)
|
||||||
test.errCheck(t, err, clues.ToCore(err))
|
test.errCheck(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user