Skip to content

Align remote file reads with IO length semantics - #174

Open
OskarEichler wants to merge 2 commits into
net-ssh:masterfrom
OskarEichler:codex/file-read-contract
Open

Align remote file reads with IO length semantics#174
OskarEichler wants to merge 2 commits into
net-ssh:masterfrom
OskarEichler:codex/file-read-contract

Conversation

@OskarEichler

Copy link
Copy Markdown

Problem: Net::SFTP::Operations::File#read did not follow Ruby IO length semantics: it accepted invalid negative lengths, performed a remote read for zero, returned an empty string instead of nil at positive-length EOF, and could spin when a server returned an empty DATA packet.

Fix: Coerce lengths through to_int, reject negative lengths, return immediately for zero, return nil at EOF for positive reads, and treat empty DATA as EOF.

Regression coverage: Adds focused upstream cases for coercion, invalid lengths, zero-length reads, EOF, and empty DATA. test_file.rb: 38 runs / 120 assertions. Full suite: 439 runs / 1,210 assertions with only the pre-existing Ruby 4 StartTest positional-hash/keyword expectation failure.

@OskarEichler

Copy link
Copy Markdown
Author

I did another pass over the read state machine and added a regression ensuring that once EOF has been observed, subsequent positive-length reads return nil without issuing another SFTP READ. The focused file tests pass (38 runs, 121 assertions). The full suite otherwise reaches 438/439 passing locally; the sole failure is the pre-existing StartTest#test_with_block_and_options keyword/hash expectation under this Ruby/net-ssh combination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant