miga-base 1.3.15.8 → 1.3.15.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67a4b45cec67cd472fc681bd0993b0ba7bb3f36229e0a6cf5120333131a65b72
4
- data.tar.gz: 968803414089403de2f50e4fe11624b57dc6b69ddeb37a22e5fac365b8fd8224
3
+ metadata.gz: a664f669e51be77875c62623d2c3f749ff6bcdb7a118f7432a9ecadcead1bcf2
4
+ data.tar.gz: ec9f67e76a763c17e660dab05191d5f8ced5ac84988ddc8a27566f42e90f906d
5
5
  SHA512:
6
- metadata.gz: bee8323fb44d70b5577baa076b77ebe7a8cdc69ffb40a535fdd714d299d09a08dd3dc73352325d11f1ade061ffca222d53e98602486bfd7571a773dca7ad2f47
7
- data.tar.gz: 245b2f64128473dcda952e82874fa3c1fad2a0b7aa0b82c8a57bb9a13f01c16094b5a9249899e4212224e10d9853e8b99d3c1c83bef7229a70c07b454ee09513
6
+ metadata.gz: d26498f03f512d96f4dc1a7ade3d065c9301bb7170e6cbff8c5241313e397782d8516e18f18e9dc0aee1b0a990fca58463cc138c4c2bce4c72b38f10fec148db
7
+ data.tar.gz: 3fff9c2b56a3f3e4a004375432170cab95a8102de0035428384c63b0818a3be18d4b040e32abdb413875f230a4f03195f42e3439c3eae9f61d72c23ed5a3e6a8
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ group :test do
6
6
  gem 'codeclimate-test-reporter', '~> 1.0'
7
7
  end
8
8
 
9
- gem 'rake', '~> 12.0'
9
+ gem 'rake', '~> 13.0'
@@ -139,7 +139,7 @@ class MiGA::Cli::Action::Db < MiGA::Cli::Action
139
139
  MiGA::MiGA.download_file_ftp(ftp, path, file) do |n, size|
140
140
  cli.advance("#{path}:", n, size) if cli[:pb]
141
141
  end
142
- cli.print "\n" if cli[:pb]
142
+ cli.say '' if cli[:pb]
143
143
  end
144
144
  file
145
145
  end
@@ -225,14 +225,21 @@ class MiGA::Cli::Action::Db < MiGA::Cli::Action
225
225
  cli.say 'Checking MD5 digest'
226
226
  cli.say "Expected: #{ver[:MD5]}"
227
227
  md5 = Digest::MD5.new
228
+ size = File.size(file)
229
+ n = 0
228
230
  File.open(file, 'rb') do |fh|
229
231
  until fh.eof?
230
- md5.update fh.read(1024)
232
+ md5 << fh.read(1024)
233
+ n += 1024
234
+ cli.advance('Processed:', [n, size].min, size) if cli[:pb]
231
235
  end
232
236
  end
237
+ cli.say '' if cli[:pb]
233
238
  dig = md5.hexdigest
234
239
  cli.say "Observed: #{dig}"
235
- raise 'Corrupt file, MD5 does not match' unless dig == ver[:MD5]
240
+ unless dig == ver[:MD5]
241
+ raise "Corrupt file, MD5 differs. Remove #{file} before trying again"
242
+ end
236
243
  end
237
244
 
238
245
  def version_size(ver)
@@ -49,6 +49,7 @@ module MiGA::Common::Net
49
49
  when 'ftp'
50
50
  ftp = Net::FTP.new(uri.host)
51
51
  ftp.passive = true
52
+ ftp.resume = true
52
53
  ftp.login
53
54
  ftp.chdir(uri.path) unless host.is_a?(URI)
54
55
  ftp
@@ -87,7 +88,8 @@ module MiGA::Common::Net
87
88
  # Prepare download
88
89
  FileUtils.mkdir_p(File.dirname(target)) if target
89
90
  filesize = connection.size(file)
90
- transferred = 0
91
+ transferred =
92
+ target && connection.resume && File.exist?(target) ? File.size(target) : 0
91
93
 
92
94
  # Get in chunks of 1KiB
93
95
  ret = ''
data/lib/miga/common.rb CHANGED
@@ -64,25 +64,33 @@ class MiGA::MiGA
64
64
  # The report goes to $stderr iff --verbose
65
65
  def advance(step, n = 0, total = nil, bin = true)
66
66
  # Initialize advance timing
67
- @_advance_time ||= { last: nil, n: 0, avg: nil }
68
- if @_advance_time[:n] > n
67
+ @_advance_time ||= { last: nil, n: 0, avg: nil, total: total }
68
+ if @_advance_time[:n] > n || total != @_advance_time[:total]
69
69
  @_advance_time[:last] = nil
70
70
  @_advance_time[:n] = 0
71
71
  @_advance_time[:avg] = nil
72
+ @_advance_time[:total] = total
72
73
  end
73
74
 
74
75
  # Estimate timing
75
76
  adv_n = n - @_advance_time[:n]
76
77
  if total.nil? || @_advance_time[:last].nil? || adv_n.negative?
78
+ # Initial report
77
79
  @_advance_time[:last] = Time.now
78
80
  @_advance_time[:n] = n
79
81
  elsif adv_n > 0.001 * total
82
+ # Advance report (if change > 0.1% change and time > 1 second)
80
83
  this_time = (Time.now - @_advance_time[:last]).to_f
84
+ return if this_time < 1.0 && n < total
85
+
81
86
  this_avg = this_time / adv_n
82
87
  @_advance_time[:avg] ||= this_avg
83
88
  @_advance_time[:avg] = 0.9 * @_advance_time[:avg] + 0.1 * this_avg
84
89
  @_advance_time[:last] = Time.now
85
90
  @_advance_time[:n] = n
91
+ else
92
+ # Final report (if the last update was too small) or ignore update
93
+ return if n < total
86
94
  end
87
95
 
88
96
  # Report
data/lib/miga/version.rb CHANGED
@@ -12,7 +12,7 @@ module MiGA
12
12
  # - String indicating release status:
13
13
  # - rc* release candidate, not released as gem
14
14
  # - [0-9]+ stable release, released as gem
15
- VERSION = [1.3, 15, 8].freeze
15
+ VERSION = [1.3, 15, 10].freeze
16
16
 
17
17
  ##
18
18
  # Nickname for the current major.minor version.
data/test/common_test.rb CHANGED
@@ -76,23 +76,26 @@ class CommonTest < Test::Unit::TestCase
76
76
  def test_advance
77
77
  m = MiGA::MiGA.new
78
78
 
79
- # Check advance when missing total
79
+ # Check advance when missing total and n
80
80
  o = capture_stderr { m.advance('x', 0) }.string
81
81
  assert_match(%r{\] x *\r}, o)
82
82
 
83
+ # Check advance when missing total
84
+ o = capture_stderr { m.advance('x', 10) }.string
85
+ assert_match(%r{\] x 10 *\r}, o)
86
+
83
87
  # Initialize advance
84
88
  o = capture_stderr { m.advance('x', 0, 1001) }.string
85
89
  assert_match(%r{\] x 0\.0% \(0/1001\) *\r}, o)
86
90
 
87
91
  # Insufficient data for prediction
88
- sleep(1)
89
92
  o = capture_stderr { m.advance('x', 1, 1000) }.string
90
93
  assert_match(%r{\] x 0\.1% \(1/1000\) *\r}, o)
91
94
 
92
95
  # Predict time
93
- sleep(1)
94
- o = capture_stderr { m.advance('x', 2, 1000) }.string
95
- assert_match(%r{\] x 0\.2% \(2/1000\) 1\d\.\dm left *\r}, o)
96
+ sleep(1.01)
97
+ o = capture_stderr { m.advance('x', 4, 1000) }.string
98
+ assert_match(%r{\] x 0\.4% \(4/1000\) \d\.\dm left *\r}, o)
96
99
  end
97
100
 
98
101
  def test_num_suffix
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.15.8
4
+ version: 1.3.15.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R