pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.5k stars 379 forks source link

[bug] Write error not returned if reader already signals EOF #494

Closed hmoragrega closed 2 years ago

hmoragrega commented 2 years ago

During the last chunk of a sequential write, when the reader already returned io.EOF, if the writer fails, the error is lost.

This happens due to err being already io.EOF so the condition to overwrite the error with the write error is false

if err == nil { // write error lost if err == io.EOF
    err = err2
}

I've provided a new test, not sure if it could be tested as a test case on another one though.

hmoragrega commented 2 years ago

I'll work on the test side, thanks!

drakkan commented 2 years ago

@hmoragrega thanks for noticing this bug. I'm trying to fix the test cases as requested by @puellanivis and your commits will be merged as part of #499 once that test cases are ok

puellanivis commented 2 years ago

Thanks for spotting the issue and getting us started on a fix @hmoragrega

hmoragrega commented 2 years ago

No worries! I couldn't found time to apply the latest changes these week, glad you can take it from here