From d00c126cefa5376b4fceb082faf91b88d60a885d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 2 Nov 2020 17:13:19 +0000 Subject: [PATCH] operations: fix --cutof-mode hard not cutting off immediately This failure was noted on the integration tests server. The fix was to be more careful about which error message was emitted with which --cutoff-mode --- fs/operations/operations.go | 16 +++++++++++++--- fs/operations/operations_test.go | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 68fbb6165..ab8e907f0 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -375,9 +375,19 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj // Try server-side copy first - if has optional interface and // is same underlying remote 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.ErrorMaxTransferLimitReachedGraceful + if fs.Config.MaxTransfer >= 0 { + var bytesSoFar int64 + if fs.Config.CutoffMode == fs.CutoffModeCautious { + bytesSoFar = accounting.Stats(ctx).GetBytesWithPending() + src.Size() + } else { + bytesSoFar = accounting.Stats(ctx).GetBytes() + } + if bytesSoFar >= int64(fs.Config.MaxTransfer) { + if fs.Config.CutoffMode == fs.CutoffModeHard { + return nil, accounting.ErrorMaxTransferLimitReachedFatal + } + return nil, accounting.ErrorMaxTransferLimitReachedGraceful + } } if doCopy := f.Features().Copy; doCopy != nil && (SameConfig(src.Fs(), f) || (SameRemoteType(src.Fs(), f) && f.Features().ServerSideAcrossConfigs)) { in := tr.Account(ctx, nil) // account the transfer diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index 547f24151..f35ed49cd 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -1428,7 +1428,7 @@ func TestCopyFileMaxTransfer(t *testing.T) { err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file2.Path) require.NotNil(t, err, "Did not get expected max transfer limit error") assert.Contains(t, err.Error(), "Max transfer limit reached") - assert.True(t, fserrors.IsFatalError(err)) + assert.True(t, fserrors.IsFatalError(err), fmt.Sprintf("Not fatal error: %v: %#v:", err, err)) fstest.CheckItems(t, r.Flocal, file1, file2, file3, file4) fstest.CheckItems(t, r.Fremote, file1)