forked from prasmussen/gdrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
39 lines (32 loc) · 832 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package drive
import (
"fmt"
"io"
)
type DeleteArgs struct {
Out io.Writer
Id string
Recursive bool
}
func (self *Drive) Delete(args DeleteArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("name", "mimeType").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
if isDir(f) && !args.Recursive {
return fmt.Errorf("'%s' is a directory, use the 'recursive' flag to delete directories", f.Name)
}
err = self.service.Files.Delete(args.Id).Do()
if err != nil {
return fmt.Errorf("Failed to delete file: %s", err)
}
fmt.Fprintf(args.Out, "Deleted '%s'\n", f.Name)
return nil
}
func (self *Drive) deleteFile(fileId string) error {
err := self.service.Files.Delete(fileId).Do()
if err != nil {
return fmt.Errorf("Failed to delete file: %s", err)
}
return nil
}