From 05ddef117adbd297db145178d1720ec789c5866e Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 26 Jun 2020 17:24:16 +0100 Subject: [PATCH] accounting: add HasBuffer method to Account --- fs/accounting/accounting.go | 8 ++++++++ fs/accounting/accounting_test.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go index 244df0784..05e19f4b3 100644 --- a/fs/accounting/accounting.go +++ b/fs/accounting/accounting.go @@ -109,6 +109,14 @@ func (acc *Account) WithBuffer() *Account { return acc } +// HasBuffer - returns true if this Account has an AsyncReader with a buffer +func (acc *Account) HasBuffer() bool { + acc.mu.Lock() + defer acc.mu.Unlock() + _, ok := acc.in.(*asyncreader.AsyncReader) + return ok +} + // GetReader returns the underlying io.ReadCloser under any Buffer func (acc *Account) GetReader() io.ReadCloser { acc.mu.Lock() diff --git a/fs/accounting/accounting_test.go b/fs/accounting/accounting_test.go index bd6c101ac..bfee18a26 100644 --- a/fs/accounting/accounting_test.go +++ b/fs/accounting/accounting_test.go @@ -37,6 +37,7 @@ func TestNewAccountSizeName(t *testing.T) { assert.Equal(t, acc, stats.inProgress.get("test")) acc.Done() assert.Nil(t, stats.inProgress.get("test")) + assert.False(t, acc.HasBuffer()) } func TestAccountWithBuffer(t *testing.T) { @@ -44,7 +45,9 @@ func TestAccountWithBuffer(t *testing.T) { stats := NewStats() acc := newAccountSizeName(stats, in, -1, "test") + assert.False(t, acc.HasBuffer()) acc.WithBuffer() + assert.True(t, acc.HasBuffer()) // should have a buffer for an unknown size _, ok := acc.in.(*asyncreader.AsyncReader) require.True(t, ok)