mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-25 09:00:27 +00:00
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:
parent
093df15fac
commit
4c5a0d663e
2 changed files with 16 additions and 0 deletions
|
@ -1680,6 +1680,13 @@ func TestTransferFailingReader(t *testing.T) {
|
||||||
err = tr.Close()
|
err = tr.Close()
|
||||||
assert.NoError(t, err)
|
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)
|
err = os.Remove(fsPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, connection.GetTransfers(), 0)
|
assert.Len(t, connection.GetTransfers(), 0)
|
||||||
|
|
|
@ -32,6 +32,9 @@ func (r *failingReader) ReadAt(p []byte, off int64) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *failingReader) Close() error {
|
func (r *failingReader) Close() error {
|
||||||
|
if r.innerReader == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return r.innerReader.Close()
|
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{
|
return &transfer{
|
||||||
BaseTransfer: baseTransfer,
|
BaseTransfer: baseTransfer,
|
||||||
writerAt: writer,
|
writerAt: writer,
|
||||||
|
|
Loading…
Reference in a new issue