aboutsummaryrefslogtreecommitdiffstats
path: root/drive/sync_download.go
diff options
context:
space:
mode:
Diffstat (limited to 'drive/sync_download.go')
-rw-r--r--drive/sync_download.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/drive/sync_download.go b/drive/sync_download.go
index 04b50b9..58cd49c 100644
--- a/drive/sync_download.go
+++ b/drive/sync_download.go
@@ -19,6 +19,7 @@ type DownloadSyncArgs struct {
Path string
DryRun bool
DeleteExtraneous bool
+ Timeout time.Duration
Resolution ConflictResolution
Comparer FileComparer
}
@@ -188,14 +189,16 @@ func (self *Drive) downloadRemoteFile(id, fpath string, args DownloadSyncArgs, t
}
// Get timeout reader wrapper and context
- timeoutReaderWrapper, ctx := getTimeoutReaderWrapperContext()
+ timeoutReaderWrapper, ctx := getTimeoutReaderWrapperContext(args.Timeout)
res, err := self.service.Files.Get(id).Context(ctx).Download()
if err != nil {
- if isBackendError(err) && try < MaxBackendErrorRetries {
+ if isBackendOrRateLimitError(err) && try < MaxErrorRetries {
exponentialBackoffSleep(try)
try++
return self.downloadRemoteFile(id, fpath, args, try)
+ } else if isTimeoutError(err) {
+ return fmt.Errorf("Failed to download file: timeout, no data was transferred for %v", args.Timeout)
} else {
return fmt.Errorf("Failed to download file: %s", err)
}
@@ -228,7 +231,7 @@ func (self *Drive) downloadRemoteFile(id, fpath string, args DownloadSyncArgs, t
_, err = io.Copy(outFile, reader)
if err != nil {
outFile.Close()
- if try < MaxBackendErrorRetries {
+ if try < MaxErrorRetries {
exponentialBackoffSleep(try)
try++
return self.downloadRemoteFile(id, fpath, args, try)