Rename folder metadata files to just .dirmeta (#2758)

Removing the folder name from the dirmeta file name
plays better with upcoming incremental backup changes
because we no longer have to discover what the old
name of the metadata file was

Bumps the Corso backup version number

Contains minor changes to how tests detect root
folder's metadata

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

* closes #2754

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-03-13 10:41:35 -07:00 committed by GitHub
parent dc21f4ce07
commit d1e86264e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 14 deletions

View File

@ -682,12 +682,12 @@ func compareOneDriveItem(
t *testing.T, t *testing.T,
expected map[string][]byte, expected map[string][]byte,
item data.Stream, item data.Stream,
dest control.RestoreDestination,
restorePermissions bool, restorePermissions bool,
rootDir bool,
) bool { ) bool {
// Skip OneDrive permissions in the folder that used to be the root. We don't // Skip OneDrive permissions in the folder that used to be the root. We don't
// have a good way to materialize these in the test right now. // have a good way to materialize these in the test right now.
if item.UUID() == dest.ContainerName+onedrive.DirMetaFileSuffix { if rootDir && item.UUID() == onedrive.DirMetaFileSuffix {
return false return false
} }
@ -777,8 +777,8 @@ func compareItem(
service path.ServiceType, service path.ServiceType,
category path.CategoryType, category path.CategoryType,
item data.Stream, item data.Stream,
dest control.RestoreDestination,
restorePermissions bool, restorePermissions bool,
rootDir bool,
) bool { ) bool {
if mt, ok := item.(data.StreamModTime); ok { if mt, ok := item.(data.StreamModTime); ok {
assert.NotZero(t, mt.ModTime()) assert.NotZero(t, mt.ModTime())
@ -798,7 +798,7 @@ func compareItem(
} }
case path.OneDriveService: case path.OneDriveService:
return compareOneDriveItem(t, expected, item, dest, restorePermissions) return compareOneDriveItem(t, expected, item, restorePermissions, rootDir)
default: default:
assert.FailNowf(t, "unexpected service: %s", service.String()) assert.FailNowf(t, "unexpected service: %s", service.String())
@ -850,6 +850,8 @@ func checkCollections(
service = returned.FullPath().Service() service = returned.FullPath().Service()
category = returned.FullPath().Category() category = returned.FullPath().Category()
expectedColData = expected[returned.FullPath().String()] expectedColData = expected[returned.FullPath().String()]
folders = returned.FullPath().Elements()
rootDir = folders[len(folders)-1] == dest.ContainerName
) )
// Need to iterate through all items even if we don't expect to find a match // Need to iterate through all items even if we don't expect to find a match
@ -875,7 +877,7 @@ func checkCollections(
continue continue
} }
if !compareItem(t, expectedColData, service, category, item, dest, restorePermissions) { if !compareItem(t, expectedColData, service, category, item, restorePermissions, rootDir) {
gotItems-- gotItems--
} }
} }

View File

@ -192,7 +192,8 @@ func (c *onedriveCollection) withFile(name string, fileData []byte, perm permDat
name+onedrive.DataFileSuffix, name+onedrive.DataFileSuffix,
fileData)) fileData))
case version.OneDrive1DataAndMetaFiles, 2, version.OneDrive3IsMetaMarker, version.OneDrive4DirIncludesPermissions: case version.OneDrive1DataAndMetaFiles, 2, version.OneDrive3IsMetaMarker,
version.OneDrive4DirIncludesPermissions, version.OneDrive5DirMetaNoName:
c.items = append(c.items, onedriveItemWithData( c.items = append(c.items, onedriveItemWithData(
c.t, c.t,
name+onedrive.DataFileSuffix, name+onedrive.DataFileSuffix,
@ -217,7 +218,7 @@ func (c *onedriveCollection) withFile(name string, fileData []byte, perm permDat
func (c *onedriveCollection) withFolder(name string, perm permData) *onedriveCollection { func (c *onedriveCollection) withFolder(name string, perm permData) *onedriveCollection {
switch c.backupVersion { switch c.backupVersion {
case 0, version.OneDrive4DirIncludesPermissions: case 0, version.OneDrive4DirIncludesPermissions, version.OneDrive5DirMetaNoName:
return c return c
case version.OneDrive1DataAndMetaFiles, 2, version.OneDrive3IsMetaMarker: case version.OneDrive1DataAndMetaFiles, 2, version.OneDrive3IsMetaMarker:
@ -247,6 +248,12 @@ func (c *onedriveCollection) withPermissions(perm permData) *onedriveCollection
} }
name := c.pathElements[len(c.pathElements)-1] name := c.pathElements[len(c.pathElements)-1]
metaName := name
if c.backupVersion >= version.OneDrive5DirMetaNoName {
// We switched to just .dirmeta for metadata file names.
metaName = ""
}
if name == "root:" { if name == "root:" {
return c return c
@ -255,7 +262,7 @@ func (c *onedriveCollection) withPermissions(perm permData) *onedriveCollection
metadata := onedriveMetadata( metadata := onedriveMetadata(
c.t, c.t,
name, name,
name+onedrive.DirMetaFileSuffix, metaName+onedrive.DirMetaFileSuffix,
perm, perm,
c.backupVersion >= versionPermissionSwitchedToID) c.backupVersion >= versionPermissionSwitchedToID)

View File

@ -339,6 +339,7 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
itemInfo details.ItemInfo itemInfo details.ItemInfo
itemMeta io.ReadCloser itemMeta io.ReadCloser
itemMetaSize int itemMetaSize int
metaFileName string
metaSuffix string metaSuffix string
err error err error
) )
@ -356,10 +357,12 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
if isFile { if isFile {
atomic.AddInt64(&itemsFound, 1) atomic.AddInt64(&itemsFound, 1)
metaFileName = itemName
metaSuffix = MetaFileSuffix metaSuffix = MetaFileSuffix
} else { } else {
atomic.AddInt64(&dirsFound, 1) atomic.AddInt64(&dirsFound, 1)
// metaFileName not set for directories so we get just ".dirmeta"
metaSuffix = DirMetaFileSuffix metaSuffix = DirMetaFileSuffix
} }
@ -464,7 +467,7 @@ func (oc *Collection) populateItems(ctx context.Context, errs *fault.Bus) {
}) })
oc.data <- &metadataItem{ oc.data <- &metadataItem{
id: itemName + metaSuffix, id: metaFileName + metaSuffix,
data: metaReader, data: metaReader,
modTime: time.Now(), modTime: time.Now(),
} }

View File

@ -68,11 +68,13 @@ func getCollectionMetadata(
// Root folder doesn't have a metadata file associated with it. // Root folder doesn't have a metadata file associated with it.
folders := collectionPath.Folders() folders := collectionPath.Folders()
metaName := folders[len(folders)-1] + DirMetaFileSuffix
meta, err := fetchAndReadMetadata( if backupVersion >= version.OneDrive5DirMetaNoName {
ctx, metaName = DirMetaFileSuffix
dc, }
folders[len(folders)-1]+DirMetaFileSuffix)
meta, err := fetchAndReadMetadata(ctx, dc, metaName)
if err != nil { if err != nil {
return Metadata{}, clues.Wrap(err, "collection metadata") return Metadata{}, clues.Wrap(err, "collection metadata")
} }

View File

@ -2,7 +2,7 @@ package version
import "math" import "math"
const Backup = 4 const Backup = 5
// Various labels to refer to important version changes. // Various labels to refer to important version changes.
// Labels don't need 1:1 service:version representation. Add a new // Labels don't need 1:1 service:version representation. Add a new
@ -25,6 +25,11 @@ const (
// collection as the folder itself. // collection as the folder itself.
OneDrive4DirIncludesPermissions = 4 OneDrive4DirIncludesPermissions = 4
// OneDrive5DirMetaNoName changed the directory metadata file name from
// <dirname>.dirmeta to just .dirmeta to avoid issues with folder renames
// during incremental backups.
OneDrive5DirMetaNoName = 5
// OneDriveXNameInMeta points to the backup format version where we begin // OneDriveXNameInMeta points to the backup format version where we begin
// storing files in kopia with their item ID instead of their OneDrive file // storing files in kopia with their item ID instead of their OneDrive file
// name. // name.