Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Net::SFTP::StatusException instead of RuntimeError in the download operation #48

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/net/sftp/operations/download.rb
Expand Up @@ -255,7 +255,7 @@ def process_next_entry
# operation was successful.
def on_opendir(response)
entry = response.request[:entry]
raise "opendir #{entry.remote}: #{response}" unless response.ok?
raise StatusException.new(response, "opendir #{entry.remote}") unless response.ok?
entry.handle = response[:handle]
request = sftp.readdir(response[:handle], &method(:on_readdir))
request[:parent] = entry
Expand All @@ -270,7 +270,7 @@ def on_readdir(response)
request = sftp.close(entry.handle, &method(:on_closedir))
request[:parent] = entry
elsif !response.ok?
raise "readdir #{entry.remote}: #{response}"
raise StatusException.new(response, "readdir #{entry.remote}")
else
response[:names].each do |item|
next if item.name == "." || item.name == ".."
Expand All @@ -296,15 +296,15 @@ def open_file(entry)
def on_closedir(response)
@active -= 1
entry = response.request[:parent]
raise "close #{entry.remote}: #{response}" unless response.ok?
raise StatusException.new(response, "close #{entry.remote}") unless response.ok?
process_next_entry
end

# Called when a file has been opened. This will call #download_next_chunk
# to initiate the data transfer.
def on_open(response)
entry = response.request[:entry]
raise "open #{entry.remote}: #{response}" unless response.ok?
raise StatusException.new(response, "open #{entry.remote}") unless response.ok?

entry.handle = response[:handle]
entry.sink = entry.local.respond_to?(:write) ? entry.local : ::File.open(entry.local, "wb")
Expand Down Expand Up @@ -332,7 +332,7 @@ def on_read(response)
request = sftp.close(entry.handle, &method(:on_close))
request[:entry] = entry
elsif !response.ok?
raise "read #{entry.remote}: #{response}"
raise StatusException.new(response, "read #{entry.remote}")
else
entry.offset += response[:data].bytesize
update_progress(:get, entry, response.request[:offset], response[:data])
Expand All @@ -345,7 +345,7 @@ def on_read(response)
def on_close(response)
@active -= 1
entry = response.request[:entry]
raise "close #{entry.remote}: #{response}" unless response.ok?
raise StatusException.new(response, "close #{entry.remote}") unless response.ok?
process_next_entry
end

Expand Down