drive: support metadata setting and mapping on server side Move,Copy
Before this change the backend would not run the metadata mapper and it would ignore metadata set when doing server side moves or copies.
This commit is contained in:
parent
6e85a39e99
commit
9f2ce2c7fc
1 changed files with 24 additions and 2 deletions
|
@ -2791,6 +2791,12 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
createInfo.Description = ""
|
createInfo.Description = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust metadata if required
|
||||||
|
updateMetadata, err := f.fetchAndUpdateMetadata(ctx, src, fs.MetadataAsOpenOptions(ctx), createInfo, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// get the ID of the thing to copy
|
// get the ID of the thing to copy
|
||||||
// copy the contents if CopyShortcutContent
|
// copy the contents if CopyShortcutContent
|
||||||
// else copy the shortcut only
|
// else copy the shortcut only
|
||||||
|
@ -2804,7 +2810,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
var info *drive.File
|
var info *drive.File
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
copy := f.svc.Files.Copy(id, createInfo).
|
copy := f.svc.Files.Copy(id, createInfo).
|
||||||
Fields(partialFields).
|
Fields(f.getFileFields(ctx)).
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
KeepRevisionForever(f.opt.KeepRevisionForever)
|
KeepRevisionForever(f.opt.KeepRevisionForever)
|
||||||
srcObj.addResourceKey(copy.Header())
|
srcObj.addResourceKey(copy.Header())
|
||||||
|
@ -2840,6 +2846,11 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
fs.Errorf(existingObject, "Failed to remove existing object after copy: %v", err)
|
fs.Errorf(existingObject, "Failed to remove existing object after copy: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Finalise metadata
|
||||||
|
err = updateMetadata(ctx, info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return newObject, nil
|
return newObject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3013,13 +3024,19 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
dstParents := strings.Join(dstInfo.Parents, ",")
|
dstParents := strings.Join(dstInfo.Parents, ",")
|
||||||
dstInfo.Parents = nil
|
dstInfo.Parents = nil
|
||||||
|
|
||||||
|
// Adjust metadata if required
|
||||||
|
updateMetadata, err := f.fetchAndUpdateMetadata(ctx, src, fs.MetadataAsOpenOptions(ctx), dstInfo, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Do the move
|
// Do the move
|
||||||
var info *drive.File
|
var info *drive.File
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
info, err = f.svc.Files.Update(shortcutID(srcObj.id), dstInfo).
|
info, err = f.svc.Files.Update(shortcutID(srcObj.id), dstInfo).
|
||||||
RemoveParents(srcParentID).
|
RemoveParents(srcParentID).
|
||||||
AddParents(dstParents).
|
AddParents(dstParents).
|
||||||
Fields(partialFields).
|
Fields(f.getFileFields(ctx)).
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Context(ctx).Do()
|
Context(ctx).Do()
|
||||||
return f.shouldRetry(ctx, err)
|
return f.shouldRetry(ctx, err)
|
||||||
|
@ -3028,6 +3045,11 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finalise metadata
|
||||||
|
err = updateMetadata(ctx, info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return f.newObjectWithInfo(ctx, remote, info)
|
return f.newObjectWithInfo(ctx, remote, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue