drive: fix integration tests by enabling metadata support from the context

Before this change, the drive backend only used metadata if it was
created with Metadata enabled.

This patch changes it so the Metadata support is enabled dynamically
if it is set in the context.

This fixes the metadata tests in the integration tests which have been
changed to make sure Metadata is enabled.
This commit is contained in:
Nick Craig-Wood 2023-11-19 11:03:55 +00:00
parent 1ea8678be2
commit 64ec5709fe

View file

@ -828,7 +828,6 @@ type Fs struct {
exportExtensions []string // preferred extensions to download docs exportExtensions []string // preferred extensions to download docs
importMimeTypes []string // MIME types to convert to docs importMimeTypes []string // MIME types to convert to docs
isTeamDrive bool // true if this is a team drive isTeamDrive bool // true if this is a team drive
fileFields googleapi.Field // fields to fetch file info with
m configmap.Mapper m configmap.Mapper
grouping int32 // number of IDs to search at once in ListR - read with atomic grouping int32 // number of IDs to search at once in ListR - read with atomic
listRmu *sync.Mutex // protects listRempties listRmu *sync.Mutex // protects listRempties
@ -1096,7 +1095,7 @@ func (f *Fs) list(ctx context.Context, dirIDs []string, title string, directorie
list.Header().Add("X-Goog-Drive-Resource-Keys", resourceKeysHeader) list.Header().Add("X-Goog-Drive-Resource-Keys", resourceKeysHeader)
} }
fields := fmt.Sprintf("files(%s),nextPageToken,incompleteSearch", f.fileFields) fields := fmt.Sprintf("files(%s),nextPageToken,incompleteSearch", f.getFileFields(ctx))
OUTER: OUTER:
for { for {
@ -1374,7 +1373,6 @@ func newFs(ctx context.Context, name, path string, m configmap.Mapper) (*Fs, err
permissions: make(map[string]*drive.Permission), permissions: make(map[string]*drive.Permission),
} }
f.isTeamDrive = opt.TeamDriveID != "" f.isTeamDrive = opt.TeamDriveID != ""
f.fileFields = f.getFileFields()
f.features = (&fs.Features{ f.features = (&fs.Features{
DuplicateFiles: true, DuplicateFiles: true,
ReadMimeType: true, ReadMimeType: true,
@ -1510,14 +1508,14 @@ func (f *Fs) newBaseObject(ctx context.Context, remote string, info *drive.File)
parents: info.Parents, parents: info.Parents,
} }
err = nil err = nil
if f.ci.Metadata { if fs.GetConfig(ctx).Metadata {
err = o.parseMetadata(ctx, info) err = o.parseMetadata(ctx, info)
} }
return o, err return o, err
} }
// getFileFields gets the fields for a normal file Get or List // getFileFields gets the fields for a normal file Get or List
func (f *Fs) getFileFields() (fields googleapi.Field) { func (f *Fs) getFileFields(ctx context.Context) (fields googleapi.Field) {
fields = partialFields fields = partialFields
if f.opt.AuthOwnerOnly { if f.opt.AuthOwnerOnly {
fields += ",owners" fields += ",owners"
@ -1531,7 +1529,7 @@ func (f *Fs) getFileFields() (fields googleapi.Field) {
if f.opt.SizeAsQuota { if f.opt.SizeAsQuota {
fields += ",quotaBytesUsed" fields += ",quotaBytesUsed"
} }
if f.ci.Metadata { if fs.GetConfig(ctx).Metadata {
fields += "," + metadataFields fields += "," + metadataFields
} }
return fields return fields
@ -2308,7 +2306,7 @@ func (f *Fs) resolveShortcut(ctx context.Context, item *drive.File) (newItem *dr
fs.Errorf(nil, "Expecting shortcutDetails in %v", item) fs.Errorf(nil, "Expecting shortcutDetails in %v", item)
return item, nil return item, nil
} }
newItem, err = f.getFile(ctx, item.ShortcutDetails.TargetId, f.fileFields) newItem, err = f.getFile(ctx, item.ShortcutDetails.TargetId, f.getFileFields(ctx))
if err != nil { if err != nil {
var gerr *googleapi.Error var gerr *googleapi.Error
if errors.As(err, &gerr) && gerr.Code == 404 { if errors.As(err, &gerr) && gerr.Code == 404 {
@ -3389,7 +3387,7 @@ func (f *Fs) unTrashDir(ctx context.Context, dir string, recurse bool) (r unTras
// copy file with id to dest // copy file with id to dest
func (f *Fs) copyID(ctx context.Context, id, dest string) (err error) { func (f *Fs) copyID(ctx context.Context, id, dest string) (err error) {
info, err := f.getFile(ctx, id, f.fileFields) info, err := f.getFile(ctx, id, f.getFileFields(ctx))
if err != nil { if err != nil {
return fmt.Errorf("couldn't find id: %w", err) return fmt.Errorf("couldn't find id: %w", err)
} }
@ -4177,7 +4175,7 @@ func (o *baseObject) Metadata(ctx context.Context) (metadata fs.Metadata, err er
} }
fs.Debugf(o, "Fetching metadata") fs.Debugf(o, "Fetching metadata")
id := actualID(o.id) id := actualID(o.id)
info, err := o.fs.getFile(ctx, id, o.fs.fileFields) info, err := o.fs.getFile(ctx, id, o.fs.getFileFields(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
} }