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

Add the skip parameter to download and download query commands #191

Merged
merged 1 commit into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add the skip parameter to download and download query commands
  • Loading branch information
gbinside committed Sep 6, 2016
commit 025f6fc019eb42a51c07ade00a966d9bc10b3874
22 changes: 17 additions & 5 deletions drive/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package drive

import (
"fmt"
"google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi"
"io"
"os"
"path/filepath"
"time"

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

type DownloadArgs struct {
Expand All @@ -16,6 +17,7 @@ type DownloadArgs struct {
Id string
Path string
Force bool
Skip bool
Recursive bool
Delete bool
Stdout bool
Expand Down Expand Up @@ -68,6 +70,7 @@ type DownloadQueryArgs struct {
Query string
Path string
Force bool
Skip bool
Recursive bool
}

Expand All @@ -86,6 +89,7 @@ func (self *Drive) DownloadQuery(args DownloadQueryArgs) error {
Progress: args.Progress,
Path: args.Path,
Force: args.Force,
Skip: args.Skip,
}

for _, f := range files {
Expand Down Expand Up @@ -147,6 +151,7 @@ func (self *Drive) downloadBinary(f *drive.File, args DownloadArgs) (int64, int6
contentLength: res.ContentLength,
fpath: fpath,
force: args.Force,
skip: args.Skip,
stdout: args.Stdout,
progress: args.Progress,
})
Expand All @@ -158,6 +163,7 @@ type saveFileArgs struct {
contentLength int64
fpath string
force bool
skip bool
stdout bool
progress io.Writer
}
Expand All @@ -172,9 +178,15 @@ func (self *Drive) saveFile(args saveFileArgs) (int64, int64, error) {
return 0, 0, err
}

// Check if file exists
if !args.force && fileExists(args.fpath) {
return 0, 0, fmt.Errorf("File '%s' already exists, use --force to overwrite", args.fpath)
// 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
Expand Down
15 changes: 14 additions & 1 deletion gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
"github.com/prasmussen/gdrive/cli"
"os"

"github.com/prasmussen/gdrive/cli"
)

const Name = "gdrive"
Expand Down Expand Up @@ -106,6 +107,12 @@ func main() {
Description: "Overwrite existing file",
OmitValue: true,
},
cli.BoolFlag{
Name: "skip",
Patterns: []string{"-s", "--skip"},
Description: "Skip existing files",
OmitValue: true,
},
cli.BoolFlag{
Name: "recursive",
Patterns: []string{"-r", "--recursive"},
Expand Down Expand Up @@ -157,6 +164,12 @@ func main() {
Description: "Overwrite existing file",
OmitValue: true,
},
cli.BoolFlag{
Name: "skip",
Patterns: []string{"-s", "--skip"},
Description: "Skip existing files",
OmitValue: true,
},
cli.BoolFlag{
Name: "recursive",
Patterns: []string{"-r", "--recursive"},
Expand Down
9 changes: 6 additions & 3 deletions handlers_drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package main

import (
"fmt"
"github.com/prasmussen/gdrive/auth"
"github.com/prasmussen/gdrive/cli"
"github.com/prasmussen/gdrive/drive"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"time"

"github.com/prasmussen/gdrive/auth"
"github.com/prasmussen/gdrive/cli"
"github.com/prasmussen/gdrive/drive"
)

const ClientId = "367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com"
Expand Down Expand Up @@ -53,6 +54,7 @@ func downloadHandler(ctx cli.Context) {
Out: os.Stdout,
Id: args.String("fileId"),
Force: args.Bool("force"),
Skip: args.Bool("skip"),
Path: args.String("path"),
Delete: args.Bool("delete"),
Recursive: args.Bool("recursive"),
Expand All @@ -69,6 +71,7 @@ func downloadQueryHandler(ctx cli.Context) {
Out: os.Stdout,
Query: args.String("query"),
Force: args.Bool("force"),
Skip: args.Bool("skip"),
Recursive: args.Bool("recursive"),
Path: args.String("path"),
Progress: progressWriter(args.Bool("noProgress")),
Expand Down