net-scp 4.2.1 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee8ac18a34abb6482265e9cef492d7a2988d821feeda9bd25b13158ae9676987
4
- data.tar.gz: b35016e03ea18a6a707e6c9f0236930db49fe6ba33e2e675b910b6913f525419
3
+ metadata.gz: 2d9333fc8b5f1e6a3ef2ac8e0cac2da60439a1a007c0d3f4cdde1f65d9a8b15e
4
+ data.tar.gz: 71a0e15c9061385b5c3f22b224859ba6d0afb841889210ca21a1e02bef3b3f37
5
5
  SHA512:
6
- metadata.gz: d3a721c9a2310e338dc12f6f06bc712a3b0961f3236de4f69584541c04b2b4b83caf26954b104b8b4a834a93e8e5a4e50167057d7d9d238455d2012f6754ada6
7
- data.tar.gz: aa7d1a69eeb9d67f622ca4af00576c91938bc39c68ce23e57a70b7ff2f156ec3337ecbc0c6fa4edf52780ce1a0ea95e8090e1fd53a23be42e46e86b675dcf8b2
6
+ metadata.gz: 1fefda923541258a50e80a72412331e1ecf253778912cb4d2baaf75f66010fca666075a8c9fef45a68f133a442e2fb43de54a94cb5ffdd8977e1a9aab9ebf801
7
+ data.tar.gz: 47e43e791e8939779334280c4593a74d739076d5a690286557ae4d0b4fbc7ba6b0d798656b85b931812a328ecfd0c14b9457f7447095a5c27289840d4d29b6fe
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 4.2.2
2
+
3
+ * Downloads into an IO-like object whose `write` returns a partial byte count now retry until the whole chunk is written, instead of reporting success with only part of the file stored; a count of zero, a negative one or one larger than the chunk raises `Net::SCP::Error`. Thanks @OskarEichler [#121, #99]
4
+ * Uploads now send exactly the number of bytes announced to the server, counted in bytes rather than characters: data a source gains after the size is taken is not sent, and a source that ends early or a reader returning more than requested raises `Net::SCP::Error` instead of completing a short or overlong transfer. Previously the extra bytes of an overlong upload could be read by the server as the next SCP command. Thanks @OskarEichler [#120, #98]
5
+
1
6
  === 4.2.1
2
7
 
3
8
  * Add a `:limit` option to `upload`/`download` to cap bandwidth in Kbit/s, like `scp -l`. Based on #53 by @marcelrouw [#119, #53]
@@ -67,12 +67,26 @@ module Net; class SCP
67
67
  def read_data_state(channel)
68
68
  return if channel[:buffer].empty?
69
69
  data = channel[:buffer].read!(channel[:remaining])
70
- channel[:io].write(data)
70
+ write_fully(channel, data)
71
71
  channel[:remaining] -= data.length
72
72
  progress_callback(channel, channel[:file][:name], channel[:file][:size] - channel[:remaining], channel[:file][:size])
73
73
  await_response(channel, :finish_read) if channel[:remaining] <= 0
74
74
  end
75
75
 
76
+ # Writes +data+ to the local IO, retrying after partial writes. A write
77
+ # returning something other than an Integer is taken to have written all
78
+ # of it, as for sinks like uri/open-scp's that return the buffer.
79
+ def write_fully(channel, data)
80
+ until data.empty?
81
+ written = channel[:io].write(data)
82
+ return unless written.is_a?(Integer)
83
+ unless written > 0 && written <= data.bytesize
84
+ raise Net::SCP::Error, "#{channel[:file][:name]}: write returned #{written} for #{data.bytesize} bytes"
85
+ end
86
+ data = data.byteslice(written..-1)
87
+ end
88
+ end
89
+
76
90
  # Finishes off the read, sets the times for the file (if any), and then
77
91
  # jumps to either #finish_state (for single-file downloads) or
78
92
  # #read_directive_state (for recursive downloads). A 0-byte is sent to the
@@ -70,16 +70,26 @@ module Net; class SCP
70
70
  end
71
71
  end
72
72
 
73
- # If any data remains to be transferred from the current file, sends it.
74
- # Otherwise, sends a 0-byte and transfers to #next_item_state.
73
+ # If any of the announced bytes remain to be transferred from the current
74
+ # file, sends the next chunk of them. Otherwise, sends a 0-byte and
75
+ # transfers to #next_item_state. Data beyond the size announced in the 'C'
76
+ # directive is never read, as the server would take it as the next directive.
75
77
  def send_data_state(channel)
76
- data = channel[:io].read(channel[:chunk_size])
77
- if data.nil?
78
+ remaining = channel[:size] - channel[:sent]
79
+ if remaining <= 0
78
80
  channel[:io].close unless channel[:local].respond_to?(:read)
79
81
  channel.send_data("\0")
80
82
  await_response(channel, :next_item)
81
83
  else
82
- channel[:sent] += data.length
84
+ length = [channel[:chunk_size], remaining].min
85
+ data = channel[:io].read(length)
86
+ if data.nil? || data.empty?
87
+ raise Net::SCP::Error, "#{channel[:name]}: source ended after #{channel[:sent]} of #{channel[:size]} bytes"
88
+ elsif data.bytesize > length
89
+ raise Net::SCP::Error, "#{channel[:name]}: read returned #{data.bytesize} bytes, more than the #{length} requested"
90
+ end
91
+
92
+ channel[:sent] += data.bytesize
83
93
  progress_callback(channel, channel[:name], channel[:sent], channel[:size])
84
94
  channel.send_data(data)
85
95
  end
@@ -52,7 +52,7 @@ module Net
52
52
  MINOR = 2
53
53
 
54
54
  # The tiny component of this version of the Net::SSH library
55
- TINY = 1
55
+ TINY = 2
56
56
 
57
57
  # The prerelease component of this version of the Net::SSH library
58
58
  # nil allowed
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-scp
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -32,7 +32,7 @@ cert_chain:
32
32
  vNiMFH5yLu/tlav4xh+HlYscWVdFQIvd7f/Uxa+Vip1Pi16wmhnrE15z/vDX921v
33
33
  hukBRIoCEAuUgNVBh+L/C8aETzbf/77WU3Si/w==
34
34
  -----END CERTIFICATE-----
35
- date: 2026-11-02 00:00:00.000000000 Z
35
+ date: 2026-11-09 00:00:00.000000000 Z
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: net-ssh
metadata.gz.sig CHANGED
Binary file