diff --git a/backend/drive/drive.go b/backend/drive/drive.go index 4b909d404..d2f92d692 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -758,6 +758,9 @@ func (f *Fs) shouldRetry(ctx context.Context, err error) (bool, error) { } else if f.opt.StopOnDownloadLimit && reason == "downloadQuotaExceeded" { fs.Errorf(f, "Received download limit error: %v", err) return false, fserrors.FatalError(err) + } else if f.opt.StopOnUploadLimit && reason == "quotaExceeded" { + fs.Errorf(f, "Received upload limit error: %v", err) + return false, fserrors.FatalError(err) } else if f.opt.StopOnUploadLimit && reason == "teamDriveFileLimitExceeded" { fs.Errorf(f, "Received Shared Drive file limit error: %v", err) return false, fserrors.FatalError(err) diff --git a/backend/drive/drive_internal_test.go b/backend/drive/drive_internal_test.go index 8df52716c..22a84b0bb 100644 --- a/backend/drive/drive_internal_test.go +++ b/backend/drive/drive_internal_test.go @@ -19,6 +19,7 @@ import ( _ "github.com/rclone/rclone/backend/local" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/filter" + "github.com/rclone/rclone/fs/fserrors" "github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/sync" @@ -28,6 +29,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/api/drive/v3" + "google.golang.org/api/googleapi" ) func TestDriveScopes(t *testing.T) { @@ -190,6 +192,60 @@ func TestExtensionsForImportFormats(t *testing.T) { } } +func (f *Fs) InternalTestShouldRetry(t *testing.T) { + ctx := context.Background() + gatewayTimeout := googleapi.Error{ + Code: 503, + } + timeoutRetry, timeoutError := f.shouldRetry(ctx, &gatewayTimeout) + assert.True(t, timeoutRetry) + assert.Equal(t, &gatewayTimeout, timeoutError) + generic403 := googleapi.Error{ + Code: 403, + } + rLEItem := googleapi.ErrorItem{ + Reason: "rateLimitExceeded", + Message: "User rate limit exceeded.", + } + generic403.Errors = append(generic403.Errors, rLEItem) + oldStopUpload := f.opt.StopOnUploadLimit + oldStopDownload := f.opt.StopOnDownloadLimit + f.opt.StopOnUploadLimit = true + f.opt.StopOnDownloadLimit = true + defer func() { + f.opt.StopOnUploadLimit = oldStopUpload + f.opt.StopOnDownloadLimit = oldStopDownload + }() + expectedRLError := fserrors.FatalError(&generic403) + rateLimitRetry, rateLimitErr := f.shouldRetry(ctx, &generic403) + assert.False(t, rateLimitRetry) + assert.Equal(t, rateLimitErr, expectedRLError) + dQEItem := googleapi.ErrorItem{ + Reason: "downloadQuotaExceeded", + } + generic403.Errors[0] = dQEItem + expectedDQError := fserrors.FatalError(&generic403) + downloadQuotaRetry, downloadQuotaError := f.shouldRetry(ctx, &generic403) + assert.False(t, downloadQuotaRetry) + assert.Equal(t, downloadQuotaError, expectedDQError) + tDFLEItem := googleapi.ErrorItem{ + Reason: "teamDriveFileLimitExceeded", + } + generic403.Errors[0] = tDFLEItem + expectedTDFLError := fserrors.FatalError(&generic403) + teamDriveFileLimitRetry, teamDriveFileLimitError := f.shouldRetry(ctx, &generic403) + assert.False(t, teamDriveFileLimitRetry) + assert.Equal(t, teamDriveFileLimitError, expectedTDFLError) + qEItem := googleapi.ErrorItem{ + Reason: "quotaExceeded", + } + generic403.Errors[0] = qEItem + expectedQuotaError := fserrors.FatalError(&generic403) + quotaExceededRetry, quotaExceededError := f.shouldRetry(ctx, &generic403) + assert.False(t, quotaExceededRetry) + assert.Equal(t, quotaExceededError, expectedQuotaError) +} + func (f *Fs) InternalTestDocumentImport(t *testing.T) { oldAllow := f.opt.AllowImportNameChange f.opt.AllowImportNameChange = true @@ -545,6 +601,7 @@ func (f *Fs) InternalTest(t *testing.T) { t.Run("UnTrash", f.InternalTestUnTrash) t.Run("CopyID", f.InternalTestCopyID) t.Run("AgeQuery", f.InternalTestAgeQuery) + t.Run("ShouldRetry", f.InternalTestShouldRetry) } var _ fstests.InternalTester = (*Fs)(nil)