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

Commit

Permalink
Dont download data if file is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbandi committed Jul 25, 2019
1 parent 29ca5a9 commit 9ef044a
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 @@ -124,6 +124,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 @@ -138,9 +152,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 @@ -178,17 +189,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 9ef044a

Please sign in to comment.