diff --git a/sftpd/internal_test.go b/sftpd/internal_test.go index 33b64895..a167d8fd 100644 --- a/sftpd/internal_test.go +++ b/sftpd/internal_test.go @@ -1680,6 +1680,13 @@ func TestTransferFailingReader(t *testing.T) { err = tr.Close() assert.NoError(t, err) + tr = newTransfer(baseTransfer, nil, nil, errRead) + _, err = tr.ReadAt(buf, 0) + assert.EqualError(t, err, errRead.Error()) + + err = tr.Close() + assert.NoError(t, err) + err = os.Remove(fsPath) assert.NoError(t, err) assert.Len(t, connection.GetTransfers(), 0) diff --git a/sftpd/transfer.go b/sftpd/transfer.go index 6d200036..49c66941 100644 --- a/sftpd/transfer.go +++ b/sftpd/transfer.go @@ -32,6 +32,9 @@ func (r *failingReader) ReadAt(p []byte, off int64) (n int, err error) { } func (r *failingReader) Close() error { + if r.innerReader == nil { + return nil + } return r.innerReader.Close() } @@ -70,6 +73,12 @@ func newTransfer(baseTransfer *common.BaseTransfer, pipeWriter *vfs.PipeWriter, } } } + if baseTransfer.File == nil && errForRead != nil && pipeReader == nil { + reader = &failingReader{ + innerReader: nil, + errRead: errForRead, + } + } return &transfer{ BaseTransfer: baseTransfer, writerAt: writer,