From 67d5c53420df95f6dc78146c80b4893cb1e2c582 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Thu, 4 May 2023 10:35:12 -0700 Subject: [PATCH] Fix NPE in SharePoint incremental backup (#3307) Original code was switching based on the ItemType, but SharePoint historically used the OneDriveItem ItemType, making the system think it should be updating a OneDriveItemInfo struct instead of a SharePointItemInfo struct. Also add a regression test for older backup formats. --- #### Does this PR need a docs update or release note? - [x] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [ ] :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) * closes #3306 #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- CHANGELOG.md | 3 +++ src/pkg/backup/details/details.go | 17 ++++++++++++----- src/pkg/backup/details/details_test.go | 22 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b509c31a8..cc4a02acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] (beta) +### Fixed +- Fix nil pointer exception when running an incremental backup on SharePoint where the base backup used an older index data format. + ## [v0.7.0] (beta) - 2023-05-02 ### Added diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index b731d9bbe..a96045f9b 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -628,14 +628,21 @@ func UpdateItem(item *ItemInfo, newLocPath *path.Builder) { // contained in them. var updatePath func(newLocPath *path.Builder) - switch item.infoType() { - case ExchangeContact, ExchangeEvent, ExchangeMail: + // Can't switch based on infoType because that's been unstable. + if item.Exchange != nil { updatePath = item.Exchange.UpdateParentPath - case SharePointLibrary: + } else if item.SharePoint != nil { + // SharePoint used to store library items with the OneDriveItem ItemType. + // Start switching them over as we see them since there's no point in + // keeping the old format. + if item.SharePoint.ItemType == OneDriveItem { + item.SharePoint.ItemType = SharePointLibrary + } + updatePath = item.SharePoint.UpdateParentPath - case OneDriveItem: + } else if item.OneDrive != nil { updatePath = item.OneDrive.UpdateParentPath - default: + } else { return } diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index 1dafae0a9..7c6466d3c 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -1148,6 +1148,28 @@ func (suite *DetailsUnitSuite) TestUpdateItem() { }, }, }, + { + name: "SharePoint Old Format", + input: ItemInfo{ + SharePoint: &SharePointInfo{ + ItemType: OneDriveItem, + ParentPath: folder1, + }, + }, + locPath: newOneDrivePB, + expectedItem: ItemInfo{ + SharePoint: &SharePointInfo{ + ItemType: SharePointLibrary, + ParentPath: folder2, + }, + }, + }, + { + name: "Empty Item Doesn't Fail", + input: ItemInfo{}, + locPath: newOneDrivePB, + expectedItem: ItemInfo{}, + }, } for _, test := range table {