Skip to content

Commit

Permalink
feat: allow deleting all subfolders of a parent
Browse files Browse the repository at this point in the history
Special-cased feature for my one-off need
  • Loading branch information
msfjarvis committed Jan 27, 2023
1 parent df1c5e7 commit 41a96c5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drive/delete.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package drive

import (
"context"
"fmt"
"io"

"google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi"
)

type DeleteArgs struct {
Expand All @@ -21,6 +25,27 @@ func (self *Drive) Delete(args DeleteArgs) error {
return fmt.Errorf("'%s' is a directory, use the 'recursive' flag to delete directories", f.Name)
}

if false {
controlledStop := fmt.Errorf("Controlled stop")
var files []*drive.File
pageSize := 50
self.service.Files.List().SupportsTeamDrives(true).IncludeTeamDriveItems(true).Q(fmt.Sprintf("'%s' in parents", args.Id)).Fields([]googleapi.Field{"nextPageToken", "files(id,name)"}...).PageSize(int64(pageSize)).Pages(context.TODO(), func(fl *drive.FileList) error {
if len(fl.Files) != 0 {
files = append(files, fl.Files...)
} else {
return controlledStop
}
return nil
})
for _, f := range files {
fmt.Printf("Deleting file: %s\n", f.Name)
err = self.service.Files.Delete(f.Id).SupportsTeamDrives(true).Do()
if err != nil {
return fmt.Errorf("Failed to delete file: %s", err)
}
}
}

err = self.service.Files.Delete(args.Id).SupportsTeamDrives(true).Do()
if err != nil {
return fmt.Errorf("Failed to delete file: %s", err)
Expand Down

0 comments on commit 41a96c5

Please sign in to comment.