aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Rasmussen2016-09-06 17:16:11 +0200
committerGitHub2016-09-06 17:16:11 +0200
commitaaaa4d2a2687fd2a6e36d5e8782b468f53f706ae (patch)
treea23e3757c43f9814534727ba3dba13f140984183
parent20b71922b6a3c8fd71bb5ab1f3f2a84558248322 (diff)
parent025f6fc019eb42a51c07ade00a966d9bc10b3874 (diff)
downloadgdrive-aaaa4d2a2687fd2a6e36d5e8782b468f53f706ae.tar.bz2
Merge pull request #191 from dreamtechit/master
Add the skip parameter to download and download query commands
-rw-r--r--drive/download.go22
-rw-r--r--gdrive.go15
-rw-r--r--handlers_drive.go9
3 files changed, 37 insertions, 9 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
diff --git a/gdrive.go b/gdrive.go
index 272a9e9..4833eaa 100644
--- a/gdrive.go
+++ b/gdrive.go
@@ -2,8 +2,9 @@ package main
import (
"fmt"
- "github.com/prasmussen/gdrive/cli"
"os"
+
+ "github.com/prasmussen/gdrive/cli"
)
const Name = "gdrive"
@@ -107,6 +108,12 @@ func main() {
OmitValue: true,
},
cli.BoolFlag{
+ Name: "skip",
+ Patterns: []string{"-s", "--skip"},
+ Description: "Skip existing files",
+ OmitValue: true,
+ },
+ cli.BoolFlag{
Name: "recursive",
Patterns: []string{"-r", "--recursive"},
Description: "Download directory recursively, documents will be skipped",
@@ -158,6 +165,12 @@ func main() {
OmitValue: true,
},
cli.BoolFlag{
+ Name: "skip",
+ Patterns: []string{"-s", "--skip"},
+ Description: "Skip existing files",
+ OmitValue: true,
+ },
+ cli.BoolFlag{
Name: "recursive",
Patterns: []string{"-r", "--recursive"},
Description: "Download directories recursively, documents will be skipped",
diff --git a/handlers_drive.go b/handlers_drive.go
index 516feff..5b651ba 100644
--- a/handlers_drive.go
+++ b/handlers_drive.go
@@ -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"
@@ -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"),
@@ -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")),