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 +4 -4
- data/Gemfile +1 -1
- data/lib/miga/cli/action/db.rb +10 -3
- data/lib/miga/common/net.rb +3 -1
- data/lib/miga/common.rb +10 -2
- data/lib/miga/version.rb +1 -1
- data/test/common_test.rb +8 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a664f669e51be77875c62623d2c3f749ff6bcdb7a118f7432a9ecadcead1bcf2
|
4
|
+
data.tar.gz: ec9f67e76a763c17e660dab05191d5f8ced5ac84988ddc8a27566f42e90f906d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d26498f03f512d96f4dc1a7ade3d065c9301bb7170e6cbff8c5241313e397782d8516e18f18e9dc0aee1b0a990fca58463cc138c4c2bce4c72b38f10fec148db
|
7
|
+
data.tar.gz: 3fff9c2b56a3f3e4a004375432170cab95a8102de0035428384c63b0818a3be18d4b040e32abdb413875f230a4f03195f42e3439c3eae9f61d72c23ed5a3e6a8
|
data/Gemfile
CHANGED
data/lib/miga/cli/action/db.rb
CHANGED
@@ -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.
|
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
|
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
|
-
|
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)
|
data/lib/miga/common/net.rb
CHANGED
@@ -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 =
|
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,
|
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',
|
95
|
-
assert_match(%r{\] x 0\.
|
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
|