From 7b89735ae7263cf24669a518a5508f2782235036 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 14 May 2024 12:27:03 +0100 Subject: [PATCH] onedrive: allow setting permissions to fail if failok flag is set For example using --onedrive-metadata-permissions read,write,failok Will allow permissions to be read and written but if the writing fails, then only an ERROR will be written in the log and the transfer won't fail. --- backend/onedrive/metadata.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/onedrive/metadata.go b/backend/onedrive/metadata.go index b94dcb974..ab6569a9a 100644 --- a/backend/onedrive/metadata.go +++ b/backend/onedrive/metadata.go @@ -133,6 +133,7 @@ func (rwChoices) Choices() []fs.BitsChoicesInfo { {Bit: uint64(rwOff), Name: "off"}, {Bit: uint64(rwRead), Name: "read"}, {Bit: uint64(rwWrite), Name: "write"}, + {Bit: uint64(rwFailOK), Name: "failok"}, } } @@ -142,6 +143,7 @@ type rwChoice = fs.Bits[rwChoices] const ( rwRead rwChoice = 1 << iota rwWrite + rwFailOK rwOff rwChoice = 0 ) @@ -158,6 +160,9 @@ var rwExamples = fs.OptionExamples{{ }, { Value: (rwRead | rwWrite).String(), Help: "Read and Write the value.", +}, { + Value: rwFailOK.String(), + Help: "If writing fails log errors only, don't fail the transfer", }} // Metadata describes metadata properties shared by both Objects and Directories @@ -363,6 +368,15 @@ func (m *Metadata) WritePermissions(ctx context.Context) (err error) { if m.normalizedID == "" { return errors.New("internal error: normalizedID is missing") } + if m.fs.opt.MetadataPermissions.IsSet(rwFailOK) { + // If failok is set, allow the permissions setting to fail and only log an ERROR + defer func() { + if err != nil { + fs.Errorf(m.fs, "Ignoring error as failok is set: %v", err) + err = nil + } + }() + } // compare current to queued and sort into add/update/remove queues add, update, remove := m.sortPermissions()