From e09a98f46271dc1380dca79b61b159f6055ab932 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Thu, 23 Mar 2023 01:57:17 +0530 Subject: [PATCH] Fix permissions restore for version 6 (#2908) Paths were not properly augmented for newer versions which removed the name from the `.dirmeta` file. This fixes that. It also adds a tests to ensure that the code will fail whenever we add a new version forcing us to revisit and update. --- #### 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) * https://github.com/alcionai/corso/pull/2906 * fixes https://github.com/alcionai/corso/issues/2909 #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- CHANGELOG.md | 3 ++ src/internal/connector/onedrive/restore.go | 10 ++++- .../connector/onedrive/restore_test.go | 41 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ff7ca1a..6c88de28c 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 +- Fixed permissions restore in latest backup version + ## [v0.6.1] (beta) - 2023-03-21 ### Added diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 933709f8e..1fd4d5e70 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -646,7 +646,15 @@ func AugmentRestorePaths(backupVersion int, paths []path.Path) ([]path.Path, err // collection. for _, p := range colPaths { el := p.Elements() - if backupVersion >= version.OneDrive4DirIncludesPermissions { + + if backupVersion >= version.OneDrive6NameInMeta { + mPath, err := p.Append(".dirmeta", true) + if err != nil { + return nil, err + } + + paths = append(paths, mPath) + } else if backupVersion >= version.OneDrive4DirIncludesPermissions { mPath, err := p.Append(el[len(el)-1]+".dirmeta", true) if err != nil { return nil, err diff --git a/src/internal/connector/onedrive/restore_test.go b/src/internal/connector/onedrive/restore_test.go index 0282d8222..26ad369c3 100644 --- a/src/internal/connector/onedrive/restore_test.go +++ b/src/internal/connector/onedrive/restore_test.go @@ -21,6 +21,12 @@ func TestRestoreUnitSuite(t *testing.T) { } func (suite *RestoreUnitSuite) TestAugmentRestorePaths() { + // Adding a simple test here so that we can be sure that this + // function gets updated whenever we add a new version. + if version.Backup > version.OneDrive6NameInMeta { + require.Less(suite.T(), version.OneDrive6NameInMeta+1, version.Backup, "unsupported backup version") + } + table := []struct { name string version int @@ -121,6 +127,41 @@ func (suite *RestoreUnitSuite) TestAugmentRestorePaths() { "folder/folder2/folder2.dirmeta", }, }, + { + name: "no change v6", + version: version.OneDrive6NameInMeta, + input: []string{ + "file.txt.data", + }, + output: []string{ + "file.txt.data", + }, + }, + { + name: "one folder v6", + version: version.OneDrive6NameInMeta, + input: []string{ + "folder/file.txt.data", + }, + output: []string{ + "folder/.dirmeta", + "folder/file.txt.data", + }, + }, + { + name: "nested folders v6", + version: version.OneDrive6NameInMeta, + input: []string{ + "folder/file.txt.data", + "folder/folder2/file.txt.data", + }, + output: []string{ + "folder/.dirmeta", + "folder/file.txt.data", + "folder/folder2/.dirmeta", + "folder/folder2/file.txt.data", + }, + }, } for _, test := range table {