dropbox,ftp,onedrive,yandex: make --timeout 0 work properly

See: https://forum.rclone.org/t/an-issue-about-ftp-backend-in-2-different-systems/22551
This commit is contained in:
Nick Craig-Wood 2021-03-01 12:05:36 +00:00
parent 9cc8ff4dd4
commit 0ad38dd6fa
5 changed files with 14 additions and 6 deletions

View File

@ -1269,7 +1269,7 @@ func (f *Fs) changeNotifyRunner(ctx context.Context, notifyFunc func(string, fs.
var res *files.ListFolderLongpollResult var res *files.ListFolderLongpollResult
// Dropbox sets a timeout range of 30 - 480 // Dropbox sets a timeout range of 30 - 480
timeout := uint64(f.ci.Timeout / time.Second) timeout := uint64(f.ci.TimeoutOrInfinite() / time.Second)
if timeout > 480 { if timeout > 480 {
timeout = 480 timeout = 480
} }

View File

@ -598,7 +598,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
}() }()
// Wait for List for up to Timeout seconds // Wait for List for up to Timeout seconds
timer := time.NewTimer(f.ci.Timeout) timer := time.NewTimer(f.ci.TimeoutOrInfinite())
select { select {
case listErr = <-errchan: case listErr = <-errchan:
timer.Stop() timer.Stop()

View File

@ -1088,7 +1088,7 @@ func (f *Fs) Precision() time.Duration {
// waitForJob waits for the job with status in url to complete // waitForJob waits for the job with status in url to complete
func (f *Fs) waitForJob(ctx context.Context, location string, o *Object) error { func (f *Fs) waitForJob(ctx context.Context, location string, o *Object) error {
deadline := time.Now().Add(f.ci.Timeout) deadline := time.Now().Add(f.ci.TimeoutOrInfinite())
for time.Now().Before(deadline) { for time.Now().Before(deadline) {
var resp *http.Response var resp *http.Response
var err error var err error
@ -1126,7 +1126,7 @@ func (f *Fs) waitForJob(ctx context.Context, location string, o *Object) error {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
return errors.Errorf("async operation didn't complete after %v", f.ci.Timeout) return errors.Errorf("async operation didn't complete after %v", f.ci.TimeoutOrInfinite())
} }
// Copy src to this remote using server-side copy operations. // Copy src to this remote using server-side copy operations.

View File

@ -537,7 +537,7 @@ func (f *Fs) waitForJob(ctx context.Context, location string) (err error) {
RootURL: location, RootURL: location,
Method: "GET", Method: "GET",
} }
deadline := time.Now().Add(f.ci.Timeout) deadline := time.Now().Add(f.ci.TimeoutOrInfinite())
for time.Now().Before(deadline) { for time.Now().Before(deadline) {
var resp *http.Response var resp *http.Response
var body []byte var body []byte
@ -568,7 +568,7 @@ func (f *Fs) waitForJob(ctx context.Context, location string) (err error) {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
return errors.Errorf("async operation didn't complete after %v", f.ci.Timeout) return errors.Errorf("async operation didn't complete after %v", f.ci.TimeoutOrInfinite())
} }
func (f *Fs) delete(ctx context.Context, path string, hardDelete bool) (err error) { func (f *Fs) delete(ctx context.Context, path string, hardDelete bool) (err error) {

View File

@ -164,6 +164,14 @@ func NewConfig() *ConfigInfo {
return c return c
} }
// TimeoutOrInfinite returns ci.Timeout if > 0 or infinite otherwise
func (c *ConfigInfo) TimeoutOrInfinite() time.Duration {
if c.Timeout > 0 {
return c.Timeout
}
return ModTimeNotSupported
}
type configContextKeyType struct{} type configContextKeyType struct{}
// Context key for config // Context key for config