Skip to content

Commit

Permalink
Merge pull request prasmussen#347 from Elbandi/master
Browse files Browse the repository at this point in the history
Dont download data if file is skipped

* git://github.com/prasmussen/gdrive:
  Dont download data if file is skipped
  • Loading branch information
Harsh Shandilya committed Nov 11, 2018
2 parents 25d1ba2 + 73af028 commit 8f967ba
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions drive/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ func (self *Drive) downloadRecursive(args DownloadArgs) error {
}

func (self *Drive) downloadBinary(f *drive.File, args DownloadArgs) (int64, int64, error) {
// Path to file
fpath := filepath.Join(args.Path, f.Name)

// Check if file exists to force
if !args.Skip && !args.Force && fileExists(fpath) {
return 0, 0, fmt.Errorf("File '%s' already exists, use --force to overwrite or --skip to skip", fpath)
}

//Check if file exists to skip
if args.Skip && fileExists(fpath) {
fmt.Printf("File '%s' already exists, skipping\n", fpath)
return 0, 0, nil
}

// Get timeout reader wrapper and context
timeoutReaderWrapper, ctx := getTimeoutReaderWrapperContext(args.Timeout)

Expand All @@ -159,9 +173,6 @@ func (self *Drive) downloadBinary(f *drive.File, args DownloadArgs) (int64, int6
// Close body on function exit
defer res.Body.Close()

// Path to file
fpath := filepath.Join(args.Path, f.Name)

if !args.Stdout {
fmt.Fprintf(args.Out, "Downloading %s -> %s\n", f.Name, fpath)
}
Expand Down Expand Up @@ -199,17 +210,6 @@ func (self *Drive) saveFile(args saveFileArgs) (int64, int64, error) {
return 0, 0, err
}

// Check if file exists to force
if !args.skip && !args.force && fileExists(args.fpath) {
return 0, 0, fmt.Errorf("File '%s' already exists, use --force to overwrite or --skip to skip", args.fpath)
}

//Check if file exists to skip
if args.skip && fileExists(args.fpath) {
fmt.Printf("File '%s' already exists, skipping\n", args.fpath)
return 0, 0, nil
}

// Ensure any parent directories exists
if err := mkdir(args.fpath); err != nil {
return 0, 0, err
Expand Down

0 comments on commit 8f967ba

Please sign in to comment.