diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go index eb280b0a9..af55e2688 100644 --- a/fs/accounting/accounting.go +++ b/fs/accounting/accounting.go @@ -16,9 +16,13 @@ import ( "github.com/rclone/rclone/fs/fserrors" ) -// ErrorMaxTransferLimitReached is returned from Read when the max +// ErrorMaxTransferLimitReached defines error when transfer limit is reached. +// Used for checking on exit and matching to correct exit code. +var ErrorMaxTransferLimitReached = errors.New("Max transfer limit reached as set by --max-transfer") + +// ErrorMaxTransferLimitReachedFatal is returned from Read when the max // transfer limit is reached. -var ErrorMaxTransferLimitReached = fserrors.FatalError(errors.New("Max transfer limit reached as set by --max-transfer")) +var ErrorMaxTransferLimitReachedFatal = fserrors.FatalError(ErrorMaxTransferLimitReached) // Account limits and accounts for one transfer type Account struct { @@ -172,7 +176,7 @@ func (acc *Account) checkRead() (err error) { acc.statmu.Lock() if acc.max >= 0 && acc.stats.GetBytes() >= acc.max { acc.statmu.Unlock() - return ErrorMaxTransferLimitReached + return ErrorMaxTransferLimitReachedFatal } // Set start time. if acc.start.IsZero() { diff --git a/fs/accounting/accounting_test.go b/fs/accounting/accounting_test.go index 9a00f48dd..083072e59 100644 --- a/fs/accounting/accounting_test.go +++ b/fs/accounting/accounting_test.go @@ -219,7 +219,7 @@ func TestAccountMaxTransfer(t *testing.T) { assert.NoError(t, err) n, err = acc.Read(b) assert.Equal(t, 0, n) - assert.Equal(t, ErrorMaxTransferLimitReached, err) + assert.Equal(t, ErrorMaxTransferLimitReachedFatal, err) assert.True(t, fserrors.IsFatalError(err)) fs.Config.CutoffMode = fs.CutoffModeSoft diff --git a/fs/operations/operations.go b/fs/operations/operations.go index ce4f24a5c..1cd86a9e1 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -364,7 +364,7 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj actionTaken = "Copied (server side copy)" if fs.Config.MaxTransfer >= 0 && (accounting.Stats(ctx).GetBytes() >= int64(fs.Config.MaxTransfer) || (fs.Config.CutoffMode == fs.CutoffModeCautious && accounting.Stats(ctx).GetBytesWithPending()+src.Size() >= int64(fs.Config.MaxTransfer))) { - return nil, accounting.ErrorMaxTransferLimitReached + return nil, accounting.ErrorMaxTransferLimitReachedFatal } if doCopy := f.Features().Copy; doCopy != nil && (SameConfig(src.Fs(), f) || (SameRemoteType(src.Fs(), f) && f.Features().ServerSideAcrossConfigs)) { in := tr.Account(nil) // account the transfer diff --git a/fs/sync/sync_test.go b/fs/sync/sync_test.go index 69381fc0f..710c7d1c7 100644 --- a/fs/sync/sync_test.go +++ b/fs/sync/sync_test.go @@ -1811,7 +1811,7 @@ func TestAbort(t *testing.T) { accounting.GlobalStats().ResetCounters() err := Sync(context.Background(), r.Fremote, r.Flocal, false) - expectedErr := fserrors.FsError(accounting.ErrorMaxTransferLimitReached) + expectedErr := fserrors.FsError(accounting.ErrorMaxTransferLimitReachedFatal) fserrors.Count(expectedErr) assert.Equal(t, expectedErr, err) }