From 51582e36e86d6be656cab7cc6b987fc8fb9688ed Mon Sep 17 00:00:00 2001 From: nielash Date: Thu, 11 Apr 2024 08:51:38 -0400 Subject: [PATCH] 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. --- backend/onedrive/metadata.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/onedrive/metadata.go b/backend/onedrive/metadata.go index c6a67b132..30fad0359 100644 --- a/backend/onedrive/metadata.go +++ b/backend/onedrive/metadata.go @@ -12,6 +12,7 @@ import ( "github.com/rclone/rclone/backend/onedrive/api" "github.com/rclone/rclone/fs" "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 ) @@ -432,17 +433,21 @@ func (m *Metadata) sortPermissions() (add, update, remove []*api.PermissionsType // 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) { + errs := errcount.New() for _, p := range remove { // remove (need to do these first because of remove + add workaround) _, err := m.removePermission(ctx, p) if err != nil { - return newPermissions, err + fs.Errorf(m.remote, "Failed to remove permission: %v", err) + errs.Add(err) } } for _, p := range add { // add newPs, _, err := m.addPermission(ctx, p) if err != nil { - return newPermissions, err + fs.Errorf(m.remote, "Failed to add permission: %v", err) + errs.Add(err) + continue } newPermissions = append(newPermissions, newPs...) } @@ -450,12 +455,14 @@ func (m *Metadata) processPermissions(ctx context.Context, add, update, remove [ for _, p := range update { // update newP, _, err := m.updatePermission(ctx, p) if err != nil { - return newPermissions, err + fs.Errorf(m.remote, "Failed to update permission: %v", err) + errs.Add(err) + continue } 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.