diff options
| author | Petter Rasmussen | 2016-09-06 17:16:11 +0200 |
|---|---|---|
| committer | GitHub | 2016-09-06 17:16:11 +0200 |
| commit | aaaa4d2a2687fd2a6e36d5e8782b468f53f706ae (patch) | |
| tree | a23e3757c43f9814534727ba3dba13f140984183 /drive/download.go | |
| parent | 20b71922b6a3c8fd71bb5ab1f3f2a84558248322 (diff) | |
| parent | 025f6fc019eb42a51c07ade00a966d9bc10b3874 (diff) | |
| download | gdrive-aaaa4d2a2687fd2a6e36d5e8782b468f53f706ae.tar.bz2 | |
Merge pull request #191 from dreamtechit/master
Add the skip parameter to download and download query commands
Diffstat (limited to 'drive/download.go')
| -rw-r--r-- | drive/download.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/drive/download.go b/drive/download.go index ec1af8a..e4a4141 100644 --- a/drive/download.go +++ b/drive/download.go @@ -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 { @@ -16,6 +17,7 @@ type DownloadArgs struct { Id string Path string Force bool + Skip bool Recursive bool Delete bool Stdout bool @@ -68,6 +70,7 @@ type DownloadQueryArgs struct { Query string Path string Force bool + Skip bool Recursive bool } @@ -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 { @@ -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, }) @@ -158,6 +163,7 @@ type saveFileArgs struct { contentLength int64 fpath string force bool + skip bool stdout bool progress io.Writer } @@ -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 |
