Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Allow use of team drives #409

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
State support for team drives
  • Loading branch information
petrpulc committed Nov 2, 2018
commit 0f01d8474fcf25b4013d22847350b10939476461
4 changes: 2 additions & 2 deletions drive/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (self *Drive) ListChanges(args ListChangesArgs) error {
return nil
}

changeList, err := self.service.Changes.List(args.PageToken).PageSize(args.MaxChanges).RestrictToMyDrive(true).Fields("newStartPageToken", "nextPageToken", "changes(fileId,removed,time,file(id,name,md5Checksum,mimeType,createdTime,modifiedTime))").Do()
changeList, err := self.service.Changes.List(args.PageToken).SupportsTeamDrives(true).PageSize(args.MaxChanges).RestrictToMyDrive(true).Fields("newStartPageToken", "nextPageToken", "changes(fileId,removed,time,file(id,name,md5Checksum,mimeType,createdTime,modifiedTime))").Do()
if err != nil {
return fmt.Errorf("Failed listing changes: %s", err)
}
Expand All @@ -43,7 +43,7 @@ func (self *Drive) ListChanges(args ListChangesArgs) error {
}

func (self *Drive) GetChangesStartPageToken() (string, error) {
res, err := self.service.Changes.GetStartPageToken().Do()
res, err := self.service.Changes.GetStartPageToken().SupportsTeamDrives(true).Do()
if err != nil {
return "", fmt.Errorf("Failed getting start page token: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions drive/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type DeleteArgs struct {
}

func (self *Drive) Delete(args DeleteArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("name", "mimeType").Do()
f, err := self.service.Files.Get(args.Id).SupportsTeamDrives(true).Fields("name", "mimeType").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
Expand All @@ -21,7 +21,7 @@ func (self *Drive) Delete(args DeleteArgs) error {
return fmt.Errorf("'%s' is a directory, use the 'recursive' flag to delete directories", f.Name)
}

err = self.service.Files.Delete(args.Id).Do()
err = self.service.Files.Delete(args.Id).SupportsTeamDrives(true).Do()
if err != nil {
return fmt.Errorf("Failed to delete file: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions drive/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (self *Drive) Download(args DownloadArgs) error {
return self.downloadRecursive(args)
}

f, err := self.service.Files.Get(args.Id).Fields("id", "name", "size", "mimeType", "md5Checksum").Do()
f, err := self.service.Files.Get(args.Id).SupportsTeamDrives(true).Fields("id", "name", "size", "mimeType", "md5Checksum").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func (self *Drive) DownloadQuery(args DownloadQueryArgs) error {
}

func (self *Drive) downloadRecursive(args DownloadArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("id", "name", "size", "mimeType", "md5Checksum").Do()
f, err := self.service.Files.Get(args.Id).SupportsTeamDrives(true).Fields("id", "name", "size", "mimeType", "md5Checksum").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
Expand All @@ -127,7 +127,7 @@ func (self *Drive) downloadBinary(f *drive.File, args DownloadArgs) (int64, int6
// Get timeout reader wrapper and context
timeoutReaderWrapper, ctx := getTimeoutReaderWrapperContext(args.Timeout)

res, err := self.service.Files.Get(f.Id).Context(ctx).Download()
res, err := self.service.Files.Get(f.Id).SupportsTeamDrives(true).Context(ctx).Download()
if err != nil {
if isTimeoutError(err) {
return 0, 0, fmt.Errorf("Failed to download file: timeout, no data was transferred for %v", args.Timeout)
Expand Down
2 changes: 1 addition & 1 deletion drive/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ExportArgs struct {
}

func (self *Drive) Export(args ExportArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("name", "mimeType").Do()
f, err := self.service.Files.Get(args.Id).SupportsTeamDrives(true).Fields("name", "mimeType").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion drive/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FileInfoArgs struct {
}

func (self *Drive) Info(args FileInfoArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("id", "name", "size", "createdTime", "modifiedTime", "md5Checksum", "mimeType", "parents", "shared", "description", "webContentLink", "webViewLink").Do()
f, err := self.service.Files.Get(args.Id).SupportsTeamDrives(true).Fields("id", "name", "size", "createdTime", "modifiedTime", "md5Checksum", "mimeType", "parents", "shared", "description", "webContentLink", "webViewLink").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion drive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (self *Drive) listAllFiles(args listAllFilesArgs) ([]*drive.File, error) {

controlledStop := fmt.Errorf("Controlled stop")

err := self.service.Files.List().Q(args.query).Fields(args.fields...).OrderBy(args.sortOrder).PageSize(pageSize).Pages(context.TODO(), func(fl *drive.FileList) error {
err := self.service.Files.List().SupportsTeamDrives(true).IncludeTeamDriveItems(true).Q(args.query).Fields(args.fields...).OrderBy(args.sortOrder).PageSize(pageSize).Pages(context.TODO(), func(fl *drive.FileList) error {
files = append(files, fl.Files...)

// Stop when we have all the files we need
Expand Down
2 changes: 1 addition & 1 deletion drive/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (self *Drive) mkdir(args MkdirArgs) (*drive.File, error) {
dstFile.Parents = args.Parents

// Create directory
f, err := self.service.Files.Create(dstFile).Do()
f, err := self.service.Files.Create(dstFile).SupportsTeamDrives(true).Do()
if err != nil {
return nil, fmt.Errorf("Failed to create directory: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion drive/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (self *remotePathfinder) getParent(id string) (*drive.File, error) {
}

// Fetch file from drive
f, err := self.service.Get(id).Fields("id", "name", "parents").Do()
f, err := self.service.Get(id).SupportsTeamDrives(true).Fields("id", "name", "parents").Do()
if err != nil {
return nil, fmt.Errorf("Failed to get file: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions drive/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (self *Drive) Share(args ShareArgs) error {
Domain: args.Domain,
}

_, err := self.service.Permissions.Create(args.FileId, permission).Do()
_, err := self.service.Permissions.Create(args.FileId, permission).SupportsTeamDrives(true).Do()
if err != nil {
return fmt.Errorf("Failed to share file: %s", err)
}
Expand All @@ -42,7 +42,7 @@ type RevokePermissionArgs struct {
}

func (self *Drive) RevokePermission(args RevokePermissionArgs) error {
err := self.service.Permissions.Delete(args.FileId, args.PermissionId).Do()
err := self.service.Permissions.Delete(args.FileId, args.PermissionId).SupportsTeamDrives(true).Do()
if err != nil {
fmt.Errorf("Failed to revoke permission: %s", err)
return err
Expand All @@ -58,7 +58,7 @@ type ListPermissionsArgs struct {
}

func (self *Drive) ListPermissions(args ListPermissionsArgs) error {
permList, err := self.service.Permissions.List(args.FileId).Fields("permissions(id,role,type,domain,emailAddress,allowFileDiscovery)").Do()
permList, err := self.service.Permissions.List(args.FileId).SupportsTeamDrives(true).Fields("permissions(id,role,type,domain,emailAddress,allowFileDiscovery)").Do()
if err != nil {
fmt.Errorf("Failed to list permissions: %s", err)
return err
Expand All @@ -77,7 +77,7 @@ func (self *Drive) shareAnyoneReader(fileId string) error {
Type: "anyone",
}

_, err := self.service.Permissions.Create(fileId, permission).Do()
_, err := self.service.Permissions.Create(fileId, permission).SupportsTeamDrives(true).Do()
if err != nil {
return fmt.Errorf("Failed to share file: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion drive/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (self *Drive) prepareSyncFiles(localPath string, root *drive.File, cmp File
}

func (self *Drive) isSyncFile(id string) (bool, error) {
f, err := self.service.Files.Get(id).Fields("appProperties").Do()
f, err := self.service.Files.Get(id).SupportsTeamDrives(true).Fields("appProperties").Do()
if err != nil {
return false, fmt.Errorf("Failed to get file: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions drive/sync_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (self *Drive) DownloadSync(args DownloadSyncArgs) error {

func (self *Drive) getSyncRoot(rootId string) (*drive.File, error) {
fields := []googleapi.Field{"id", "name", "mimeType", "appProperties"}
f, err := self.service.Files.Get(rootId).Fields(fields...).Do()
f, err := self.service.Files.Get(rootId).SupportsTeamDrives(true).Fields(fields...).Do()
if err != nil {
return nil, fmt.Errorf("Failed to find root dir: %s", err)
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (self *Drive) downloadRemoteFile(id, fpath string, args DownloadSyncArgs, t
// Get timeout reader wrapper and context
timeoutReaderWrapper, ctx := getTimeoutReaderWrapperContext(args.Timeout)

res, err := self.service.Files.Get(id).Context(ctx).Download()
res, err := self.service.Files.Get(id).SupportsTeamDrives(true).Context(ctx).Download()
if err != nil {
if isBackendOrRateLimitError(err) && try < MaxErrorRetries {
exponentialBackoffSleep(try)
Expand Down
14 changes: 7 additions & 7 deletions drive/sync_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (self *Drive) UploadSync(args UploadSyncArgs) error {

func (self *Drive) prepareSyncRoot(args UploadSyncArgs) (*drive.File, error) {
fields := []googleapi.Field{"id", "name", "mimeType", "appProperties"}
f, err := self.service.Files.Get(args.RootId).Fields(fields...).Do()
f, err := self.service.Files.Get(args.RootId).SupportsTeamDrives(true).Fields(fields...).Do()
if err != nil {
return nil, fmt.Errorf("Failed to find root dir: %s", err)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (self *Drive) prepareSyncRoot(args UploadSyncArgs) (*drive.File, error) {
AppProperties: map[string]string{"sync": "true", "syncRoot": "true"},
}

f, err = self.service.Files.Update(f.Id, dstFile).Fields(fields...).Do()
f, err = self.service.Files.Update(f.Id, dstFile).SupportsTeamDrives(true).Fields(fields...).Do()
if err != nil {
return nil, fmt.Errorf("Failed to update root directory: %s", err)
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (self *Drive) createMissingRemoteDir(args createMissingRemoteDirArgs) (*dri
return dstFile, nil
}

f, err := self.service.Files.Create(dstFile).Do()
f, err := self.service.Files.Create(dstFile).SupportsTeamDrives(true).Do()
if err != nil {
if isBackendOrRateLimitError(err) && args.try < MaxErrorRetries {
exponentialBackoffSleep(args.try)
Expand Down Expand Up @@ -311,7 +311,7 @@ func (self *Drive) uploadMissingFile(parentId string, lf *LocalFile, args Upload
// Wrap reader in timeout reader
reader, ctx := getTimeoutReaderContext(progressReader, args.Timeout)

_, err = self.service.Files.Create(dstFile).Fields("id", "name", "size", "md5Checksum").Context(ctx).Media(reader, chunkSize).Do()
_, err = self.service.Files.Create(dstFile).SupportsTeamDrives(true).Fields("id", "name", "size", "md5Checksum").Context(ctx).Media(reader, chunkSize).Do()
if err != nil {
if isBackendOrRateLimitError(err) && try < MaxErrorRetries {
exponentialBackoffSleep(try)
Expand Down Expand Up @@ -352,7 +352,7 @@ func (self *Drive) updateChangedFile(cf *changedFile, args UploadSyncArgs, try i
// Wrap reader in timeout reader
reader, ctx := getTimeoutReaderContext(progressReader, args.Timeout)

_, err = self.service.Files.Update(cf.remote.file.Id, dstFile).Context(ctx).Media(reader, chunkSize).Do()
_, err = self.service.Files.Update(cf.remote.file.Id, dstFile).SupportsTeamDrives(true).Context(ctx).Media(reader, chunkSize).Do()
if err != nil {
if isBackendOrRateLimitError(err) && try < MaxErrorRetries {
exponentialBackoffSleep(try)
Expand All @@ -373,7 +373,7 @@ func (self *Drive) deleteRemoteFile(rf *RemoteFile, args UploadSyncArgs, try int
return nil
}

err := self.service.Files.Delete(rf.file.Id).Do()
err := self.service.Files.Delete(rf.file.Id).SupportsTeamDrives(true).Do()
if err != nil {
if isBackendOrRateLimitError(err) && try < MaxErrorRetries {
exponentialBackoffSleep(try)
Expand All @@ -389,7 +389,7 @@ func (self *Drive) deleteRemoteFile(rf *RemoteFile, args UploadSyncArgs, try int

func (self *Drive) dirIsEmpty(id string) (bool, error) {
query := fmt.Sprintf("'%s' in parents", id)
fileList, err := self.service.Files.List().Q(query).Do()
fileList, err := self.service.Files.List().SupportsTeamDrives(true).Q(query).Do()
if err != nil {
return false, fmt.Errorf("Empty dir check failed: ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion drive/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (self *Drive) Update(args UpdateArgs) error {
fmt.Fprintf(args.Out, "Uploading %s\n", args.Path)
started := time.Now()

f, err := self.service.Files.Update(args.Id, dstFile).Fields("id", "name", "size").Context(ctx).Media(reader, chunkSize).Do()
f, err := self.service.Files.Update(args.Id, dstFile).SupportsTeamDrives(true).Fields("id", "name", "size").Context(ctx).Media(reader, chunkSize).Do()
if err != nil {
if isTimeoutError(err) {
return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout)
Expand Down
4 changes: 2 additions & 2 deletions drive/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (self *Drive) uploadFile(args UploadArgs) (*drive.File, int64, error) {
fmt.Fprintf(args.Out, "Uploading %s\n", args.Path)
started := time.Now()

f, err := self.service.Files.Create(dstFile).Fields("id", "name", "size", "md5Checksum", "webContentLink").Context(ctx).Media(reader, chunkSize).Do()
f, err := self.service.Files.Create(dstFile).SupportsTeamDrives(true).Fields("id", "name", "size", "md5Checksum", "webContentLink").Context(ctx).Media(reader, chunkSize).Do()
if err != nil {
if isTimeoutError(err) {
return nil, 0, fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout)
Expand Down Expand Up @@ -239,7 +239,7 @@ func (self *Drive) UploadStream(args UploadStreamArgs) error {
fmt.Fprintf(args.Out, "Uploading %s\n", dstFile.Name)
started := time.Now()

f, err := self.service.Files.Create(dstFile).Fields("id", "name", "size", "webContentLink").Context(ctx).Media(reader, chunkSize).Do()
f, err := self.service.Files.Create(dstFile).SupportsTeamDrives(true).Fields("id", "name", "size", "webContentLink").Context(ctx).Media(reader, chunkSize).Do()
if err != nil {
if isTimeoutError(err) {
return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout)
Expand Down