sftpd: return the error Operation Unsupported for unexpected reads

a cloud based file cannot be opened for read and write at the same
time. Return a proper error if a client try to do this.

It can happen only for SFTP
This commit is contained in:
Nicola Murino 2020-11-09 21:01:56 +01:00
parent 093df15fac
commit 4c5a0d663e
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 16 additions and 0 deletions

View file

@ -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)

View file

@ -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,