Get dir permissions inline

Add code to prepare for storing directory permissions in the directory
itself. This code allows for fetching directory permissions using the
RestoreCollection interface.
This commit is contained in:
Ashlie Martinez 2023-02-09 16:46:36 -08:00
parent 6e0b9183b4
commit 856c2130e5
2 changed files with 36 additions and 14 deletions

View File

@ -41,7 +41,8 @@ const (
// name. // name.
// TODO(ashmrtn): Update this to a real value when we merge the file name // TODO(ashmrtn): Update this to a real value when we merge the file name
// change. Set to MAXINT for now to keep the if-check using it working. // change. Set to MAXINT for now to keep the if-check using it working.
versionWithNameInMeta = math.MaxInt versionWithNameInMeta = math.MaxInt
versionWithDataAndMetaFilesInDir = 3
) )
func getParentPermissions( func getParentPermissions(
@ -66,19 +67,22 @@ func getParentPermissions(
} }
func getParentAndCollectionPermissions( func getParentAndCollectionPermissions(
ctx context.Context,
drivePath *path.DrivePath, drivePath *path.DrivePath,
collectionPath path.Path, dc data.RestoreCollection,
permissions map[string][]UserPermission, permissions map[string][]UserPermission,
backupVersion int,
restorePerms bool, restorePerms bool,
) ([]UserPermission, []UserPermission, error) { ) ([]UserPermission, []UserPermission, error) {
if !restorePerms { if !restorePerms || backupVersion < versionWithDataAndMetaFiles {
return nil, nil, nil return nil, nil, nil
} }
var ( var (
err error err error
parentPerms []UserPermission parentPerms []UserPermission
colPerms []UserPermission colPerms []UserPermission
collectionPath = dc.FullPath()
) )
// Only get parent permissions if we're not restoring the root. // Only get parent permissions if we're not restoring the root.
@ -94,11 +98,24 @@ func getParentAndCollectionPermissions(
} }
} }
// TODO(ashmrtn): For versions after this pull the permissions from the if backupVersion < versionWithDataAndMetaFilesInDir {
// current collection with Fetch(). colPerms, err = getParentPermissions(collectionPath, permissions)
colPerms, err = getParentPermissions(collectionPath, permissions) if err != nil {
if err != nil { return nil, nil, clues.Wrap(err, "getting collection permissions")
return nil, nil, clues.Wrap(err, "getting collection permissions") }
} else if len(drivePath.Folders) > 0 {
// Root folder doesn't have a metadata file associated with it.
folders := collectionPath.Folders()
meta, err := fetchAndReadMetadata(
ctx,
dc,
folders[len(folders)-1]+DirMetaFileSuffix)
if err != nil {
return nil, nil, clues.Wrap(err, "collection permissions")
}
colPerms = meta.Permissions
} }
return parentPerms, colPerms, nil return parentPerms, colPerms, nil
@ -223,9 +240,11 @@ func RestoreCollection(
"destination", restoreFolderElements) "destination", restoreFolderElements)
parentPerms, colPerms, err := getParentAndCollectionPermissions( parentPerms, colPerms, err := getParentAndCollectionPermissions(
ctx,
drivePath, drivePath,
dc.FullPath(), dc,
parentPermissions, parentPermissions,
backupVersion,
restorePerms) restorePerms)
if err != nil { if err != nil {
errUpdater(directory.String(), err) errUpdater(directory.String(), err)
@ -330,7 +349,10 @@ func RestoreCollection(
// RestoreOp, so we still need to handle them in some way. // RestoreOp, so we still need to handle them in some way.
continue continue
} else if strings.HasSuffix(name, DirMetaFileSuffix) { } else if strings.HasSuffix(name, DirMetaFileSuffix) {
if !restorePerms { // Only the versionWithDataAndMetaFiles needed to deserialize the
// permission for child folders here. Later versions can request
// permissions inline when processing the collection.
if !restorePerms || backupVersion >= versionWithDataAndMetaFilesInDir {
continue continue
} }

View File

@ -14,7 +14,7 @@ import (
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
const Version = 2 const Version = 3
// Backup represents the result of a backup operation // Backup represents the result of a backup operation
type Backup struct { type Backup struct {