net-ssh/net-scp

Passing in a Pathname object as local for download! fails

ezekg opened this issue · 3 comments

ezekg commented

I'm assuming the Pathname object implements the write method, so this error is mistakenly thrown. Casting the Pathname object to a string fixes the issue, but this was rather hard to debug since the error message was about using an in-memory buffer.

To reproduce,

download! "some/path", Pathname.new("/some/other/path").parent, {
  recursive: true
}

To fix,

download! "some/path", Pathname.new("/some/other/path").parent.to_s, {
  recursive: true
}

What if we automatically perform a to_s on Pathname objects to catch this?

ezekg commented

For reference, here's an issue that was reported to me with a stack trace: themejuice/tj#73

Similar behavior occurs for upload! -- passing a Pathname object as the 'remote' argument raises an exception when the channel is closed. Converting the 'remote' to a string does not raise an exception -- in both cases the upload itself succeeds.

I think instead of write we could check for is_a?(StringIO) i don't see it docmented that user can passin anything that accepts a write