From 2657d705677a28740d37ad52b95ba2c6a8123d7c Mon Sep 17 00:00:00 2001 From: Fionera Date: Wed, 24 Apr 2019 19:11:34 +0200 Subject: [PATCH] drive: fix move and copy from TeamDrive to GDrive --- backend/drive/drive.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 49e43c9a7..91781171c 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -1877,11 +1877,16 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) { return nil, err } + supportTeamDrives, err := f.ShouldSupportTeamDrives(src) + if err != nil { + return nil, err + } + var info *drive.File err = f.pacer.Call(func() (bool, error) { info, err = f.svc.Files.Copy(srcObj.id, createInfo). Fields(partialFields). - SupportsTeamDrives(f.isTeamDrive). + SupportsTeamDrives(supportTeamDrives). KeepRevisionForever(f.opt.KeepRevisionForever). Do() return shouldRetry(err) @@ -2025,6 +2030,11 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) { dstParents := strings.Join(dstInfo.Parents, ",") dstInfo.Parents = nil + supportTeamDrives, err := f.ShouldSupportTeamDrives(src) + if err != nil { + return nil, err + } + // Do the move var info *drive.File err = f.pacer.Call(func() (bool, error) { @@ -2032,7 +2042,7 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) { RemoveParents(srcParentID). AddParents(dstParents). Fields(partialFields). - SupportsTeamDrives(f.isTeamDrive). + SupportsTeamDrives(supportTeamDrives). Do() return shouldRetry(err) }) @@ -2043,6 +2053,20 @@ func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error) { return f.newObjectWithInfo(remote, info) } +// ShouldSupportTeamDrives returns the request should support TeamDrives +func (f *Fs) ShouldSupportTeamDrives(src fs.Object) (bool, error) { + srcIsTeamDrive := false + if srcFs, ok := src.Fs().(*Fs); ok { + srcIsTeamDrive = srcFs.isTeamDrive + } + + if f.isTeamDrive { + return true, nil + } + + return srcIsTeamDrive, nil +} + // PublicLink adds a "readable by anyone with link" permission on the given file or folder. func (f *Fs) PublicLink(remote string) (link string, err error) { id, err := f.dirCache.FindDir(remote, false)