diff options
| author | Petter Rasmussen | 2016-02-13 11:46:03 +0100 |
|---|---|---|
| committer | Petter Rasmussen | 2016-02-13 11:46:03 +0100 |
| commit | f9d75405d586b3b4e196ad5b9f749b3c99faf55c (patch) | |
| tree | 11aac85baea4ffead7b57270decb36d8f98f5bb5 /drive | |
| parent | 60c06768d323e17ad814a7aabdd509453af2a422 (diff) | |
| download | gdrive-f9d75405d586b3b4e196ad5b9f749b3c99faf55c.tar.bz2 | |
Move dry run check out of loop
Diffstat (limited to 'drive')
| -rw-r--r-- | drive/sync_download.go | 12 | ||||
| -rw-r--r-- | drive/sync_upload.go | 25 |
2 files changed, 17 insertions, 20 deletions
diff --git a/drive/sync_download.go b/drive/sync_download.go index ec496e7..918c731 100644 --- a/drive/sync_download.go +++ b/drive/sync_download.go @@ -145,10 +145,6 @@ func (self *Drive) downloadMissingFiles(files *syncFiles, args DownloadSyncArgs) } fmt.Fprintf(args.Out, "[%04d/%04d] Downloading %s -> %s\n", i + 1, missingCount, rf.relPath, filepath.Join(filepath.Base(args.Path), rf.relPath)) - if args.DryRun { - continue - } - err = self.downloadRemoteFile(rf.file.Id, absPath, args, 0) if err != nil { return err @@ -177,10 +173,6 @@ func (self *Drive) downloadChangedFiles(changedFiles []*changedFile, args Downlo } fmt.Fprintf(args.Out, "[%04d/%04d] Downloading %s -> %s\n", i + 1, changedCount, cf.remote.relPath, filepath.Join(filepath.Base(args.Path), cf.remote.relPath)) - if args.DryRun { - continue - } - err = self.downloadRemoteFile(cf.remote.file.Id, absPath, args, 0) if err != nil { return err @@ -191,6 +183,10 @@ func (self *Drive) downloadChangedFiles(changedFiles []*changedFile, args Downlo } func (self *Drive) downloadRemoteFile(id, fpath string, args DownloadSyncArgs, try int) error { + if args.DryRun { + return nil + } + res, err := self.service.Files.Get(id).Download() if err != nil { if isBackendError(err) && try < MaxBackendErrorRetries { diff --git a/drive/sync_upload.go b/drive/sync_upload.go index fbfa1a6..2c4a363 100644 --- a/drive/sync_upload.go +++ b/drive/sync_upload.go @@ -194,10 +194,6 @@ func (self *Drive) uploadMissingFiles(files *syncFiles, args UploadSyncArgs) err fmt.Fprintf(args.Out, "[%04d/%04d] Uploading %s -> %s\n", i + 1, missingCount, lf.relPath, filepath.Join(files.root.file.Name, lf.relPath)) - if args.DryRun { - continue - } - err := self.uploadMissingFile(parent.file.Id, lf, args, 0) if err != nil { return err @@ -222,10 +218,6 @@ func (self *Drive) updateChangedFiles(changedFiles []*changedFile, root *drive.F fmt.Fprintf(args.Out, "[%04d/%04d] Updating %s -> %s\n", i + 1, changedCount, cf.local.relPath, filepath.Join(root.Name, cf.local.relPath)) - if args.DryRun { - continue - } - err := self.updateChangedFile(cf, args, 0) if err != nil { return err @@ -249,10 +241,6 @@ func (self *Drive) deleteExtraneousRemoteFiles(files *syncFiles, args UploadSync for i, rf := range extraneousFiles { fmt.Fprintf(args.Out, "[%04d/%04d] Deleting %s\n", i + 1, extraneousCount, filepath.Join(files.root.file.Name, rf.relPath)) - if args.DryRun { - continue - } - err := self.deleteRemoteFile(rf, args, 0) if err != nil { return err @@ -289,6 +277,10 @@ func (self *Drive) createMissingRemoteDir(args createMissingRemoteDirArgs) (*dri } func (self *Drive) uploadMissingFile(parentId string, lf *LocalFile, args UploadSyncArgs, try int) error { + if args.DryRun { + return nil + } + srcFile, err := os.Open(lf.absPath) if err != nil { return fmt.Errorf("Failed to open file: %s", err) @@ -325,6 +317,10 @@ func (self *Drive) uploadMissingFile(parentId string, lf *LocalFile, args Upload } func (self *Drive) updateChangedFile(cf *changedFile, args UploadSyncArgs, try int) error { + if args.DryRun { + return nil + } + srcFile, err := os.Open(cf.local.absPath) if err != nil { return fmt.Errorf("Failed to open file: %s", err) @@ -357,6 +353,11 @@ func (self *Drive) updateChangedFile(cf *changedFile, args UploadSyncArgs, try i } func (self *Drive) deleteRemoteFile(rf *RemoteFile, args UploadSyncArgs, try int) error { + if args.DryRun { + return nil + } + + err := self.service.Files.Delete(rf.file.Id).Do() if err != nil { if isBackendError(err) && try < MaxBackendErrorRetries { |
