diff options
| -rw-r--r-- | drive/download.go | 22 | ||||
| -rw-r--r-- | gdrive.go | 15 | ||||
| -rw-r--r-- | handlers_drive.go | 9 | 
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 @@ -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 8db7329..415224d 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")), | 
