"Fossies" - the Fresh Open Source Software Archive

Member "gdrive-2.1.1/drive/delete.go" (28 May 2021, 832 Bytes) of package /linux/misc/old/gdrive-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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