1
mirror of https://github.com/rclone/rclone synced 2024-11-28 06:41:41 +01:00

onedrive: set all metadata permissions and return error summary

Before this change when setting permissions from the metadata rclone
would stop on the first error.

This change causes rclone to attempt to set all the permissions and
return an error summary at the end.
This commit is contained in:
nielash 2024-04-11 08:51:38 -04:00 committed by Nick Craig-Wood
parent 47cbddbd27
commit 51582e36e8

View File

@ -12,6 +12,7 @@ import (
"github.com/rclone/rclone/backend/onedrive/api" "github.com/rclone/rclone/backend/onedrive/api"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/dircache" "github.com/rclone/rclone/lib/dircache"
"github.com/rclone/rclone/lib/errcount"
"golang.org/x/exp/slices" // replace with slices after go1.21 is the minimum version "golang.org/x/exp/slices" // replace with slices after go1.21 is the minimum version
) )
@ -432,17 +433,21 @@ func (m *Metadata) sortPermissions() (add, update, remove []*api.PermissionsType
// processPermissions executes the add, update, and remove queues for writing permissions // processPermissions executes the add, update, and remove queues for writing permissions
func (m *Metadata) processPermissions(ctx context.Context, add, update, remove []*api.PermissionsType) (newPermissions []*api.PermissionsType, err error) { func (m *Metadata) processPermissions(ctx context.Context, add, update, remove []*api.PermissionsType) (newPermissions []*api.PermissionsType, err error) {
errs := errcount.New()
for _, p := range remove { // remove (need to do these first because of remove + add workaround) for _, p := range remove { // remove (need to do these first because of remove + add workaround)
_, err := m.removePermission(ctx, p) _, err := m.removePermission(ctx, p)
if err != nil { if err != nil {
return newPermissions, err fs.Errorf(m.remote, "Failed to remove permission: %v", err)
errs.Add(err)
} }
} }
for _, p := range add { // add for _, p := range add { // add
newPs, _, err := m.addPermission(ctx, p) newPs, _, err := m.addPermission(ctx, p)
if err != nil { if err != nil {
return newPermissions, err fs.Errorf(m.remote, "Failed to add permission: %v", err)
errs.Add(err)
continue
} }
newPermissions = append(newPermissions, newPs...) newPermissions = append(newPermissions, newPs...)
} }
@ -450,12 +455,14 @@ func (m *Metadata) processPermissions(ctx context.Context, add, update, remove [
for _, p := range update { // update for _, p := range update { // update
newP, _, err := m.updatePermission(ctx, p) newP, _, err := m.updatePermission(ctx, p)
if err != nil { if err != nil {
return newPermissions, err fs.Errorf(m.remote, "Failed to update permission: %v", err)
errs.Add(err)
continue
} }
newPermissions = append(newPermissions, newP) newPermissions = append(newPermissions, newP)
} }
return newPermissions, err return newPermissions, errs.Err("failed to set permissions")
} }
// fillRecipients looks for recipients to add from the permission passed in. // fillRecipients looks for recipients to add from the permission passed in.