drive: allow setting metadata to fail if failok flag is set

For example using

    --drive-metadata-permissions read,write,failok

Will allow metadata 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-10 10:36:08 +01:00
parent f26fc8f07c
commit e9e9feb21e
2 changed files with 25 additions and 4 deletions

View File

@ -151,6 +151,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"},
} }
} }
@ -160,6 +161,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
) )
@ -173,6 +175,9 @@ var rwExamples = fs.OptionExamples{{
}, { }, {
Value: rwWrite.String(), Value: rwWrite.String(),
Help: "Write the value only", Help: "Write the value only",
}, {
Value: rwFailOK.String(),
Help: "If writing fails log errors only, don't fail the transfer",
}, { }, {
Value: (rwRead | rwWrite).String(), Value: (rwRead | rwWrite).String(),
Help: "Read and Write the value.", Help: "Read and Write the value.",

View File

@ -262,7 +262,7 @@ func (f *Fs) setLabels(ctx context.Context, info *drive.File, labels []*drive.La
return f.shouldRetry(ctx, err) return f.shouldRetry(ctx, err)
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to set owner: %w", err) return fmt.Errorf("failed to set labels: %w", err)
} }
return nil return nil
} }
@ -553,7 +553,12 @@ func (f *Fs) updateMetadata(ctx context.Context, updateInfo *drive.File, meta fs
} }
// Can't set Owner on upload so need to set afterwards // Can't set Owner on upload so need to set afterwards
callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error { callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error {
return f.setOwner(ctx, info, v) err := f.setOwner(ctx, info, v)
if err != nil && f.opt.MetadataOwner.IsSet(rwFailOK) {
fs.Errorf(f, "Ignoring error as failok is set: %v", err)
return nil
}
return err
}) })
case "permissions": case "permissions":
if !f.opt.MetadataPermissions.IsSet(rwWrite) { if !f.opt.MetadataPermissions.IsSet(rwWrite) {
@ -566,7 +571,13 @@ func (f *Fs) updateMetadata(ctx context.Context, updateInfo *drive.File, meta fs
} }
// Can't set Permissions on upload so need to set afterwards // Can't set Permissions on upload so need to set afterwards
callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error { callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error {
return f.setPermissions(ctx, info, perms) err := f.setPermissions(ctx, info, perms)
if err != nil && f.opt.MetadataPermissions.IsSet(rwFailOK) {
// We've already logged the permissions errors individually here
fs.Debugf(f, "Ignoring error as failok is set: %v", err)
return nil
}
return err
}) })
case "labels": case "labels":
if !f.opt.MetadataLabels.IsSet(rwWrite) { if !f.opt.MetadataLabels.IsSet(rwWrite) {
@ -579,7 +590,12 @@ func (f *Fs) updateMetadata(ctx context.Context, updateInfo *drive.File, meta fs
} }
// Can't set Labels on upload so need to set afterwards // Can't set Labels on upload so need to set afterwards
callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error { callbackFns = append(callbackFns, func(ctx context.Context, info *drive.File) error {
return f.setLabels(ctx, info, labels) err := f.setLabels(ctx, info, labels)
if err != nil && f.opt.MetadataLabels.IsSet(rwFailOK) {
fs.Errorf(f, "Ignoring error as failok is set: %v", err)
return nil
}
return err
}) })
case "folder-color-rgb": case "folder-color-rgb":
updateInfo.FolderColorRgb = v updateInfo.FolderColorRgb = v