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.
This commit is contained in:
Nick Craig-Wood 2024-05-14 12:27:03 +01:00
parent 91192c2c5e
commit 7b89735ae7

View File

@ -133,6 +133,7 @@ func (rwChoices) Choices() []fs.BitsChoicesInfo {
{Bit: uint64(rwOff), Name: "off"}, {Bit: uint64(rwOff), Name: "off"},
{Bit: uint64(rwRead), Name: "read"}, {Bit: uint64(rwRead), Name: "read"},
{Bit: uint64(rwWrite), Name: "write"}, {Bit: uint64(rwWrite), Name: "write"},
{Bit: uint64(rwFailOK), Name: "failok"},
} }
} }
@ -142,6 +143,7 @@ type rwChoice = fs.Bits[rwChoices]
const ( const (
rwRead rwChoice = 1 << iota rwRead rwChoice = 1 << iota
rwWrite rwWrite
rwFailOK
rwOff rwChoice = 0 rwOff rwChoice = 0
) )
@ -158,6 +160,9 @@ var rwExamples = fs.OptionExamples{{
}, { }, {
Value: (rwRead | rwWrite).String(), Value: (rwRead | rwWrite).String(),
Help: "Read and Write the value.", 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 // 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 == "" { if m.normalizedID == "" {
return errors.New("internal error: normalizedID is missing") 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 // compare current to queued and sort into add/update/remove queues
add, update, remove := m.sortPermissions() add, update, remove := m.sortPermissions()