nsrr 0.1.0.beta5 → 0.1.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nsrr/helpers/download_request.rb +22 -12
- data/lib/nsrr/models/file.rb +48 -7
- data/lib/nsrr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40189a9d84626e30194f50c78d9b3223c74c817
|
4
|
+
data.tar.gz: 9acdd40aa3ebe199c644607b0932846f0e7577a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f869dca518b47dbf5b34c028d4d037661639a166f2670dac658cf08208f960c493870df7f01d25369980460cabb520615824e1da7950c27c17d2adf64c86ee24
|
7
|
+
data.tar.gz: 5a695dd5da13822137dc9f9cc0059813599590a62f29fdc60eeb0e73ff865dfc528117efdfe21faf6c329fe30e0338330415d23692d0a84e69226708b9f3c2a1
|
@@ -29,22 +29,32 @@ module Nsrr
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
# Writes file segments to disk immediately instead of storing in memory
|
32
33
|
def get
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
local_file = ::File.open(@download_folder, 'wb')
|
35
|
+
begin
|
36
|
+
partial = true
|
37
|
+
@http.request_get(@url.path) do |response|
|
38
|
+
case response.code when '200'
|
39
|
+
response.read_body do |segment|
|
40
|
+
local_file.write(segment)
|
41
|
+
end
|
42
|
+
@file_size = ::File.size(@download_folder)
|
43
|
+
partial = false
|
44
|
+
when '302'
|
45
|
+
@error = 'Token Not Authorized to Access Specified File'
|
46
|
+
else
|
47
|
+
@error = "#{response.code} #{response.class.name}"
|
48
|
+
end
|
40
49
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@
|
50
|
+
rescue => e # Net::ReadTimeout, SocketError
|
51
|
+
@error = "(#{e.class}) #{e.message}"
|
52
|
+
ensure
|
53
|
+
local_file.close()
|
54
|
+
::File.delete(@download_folder) if partial and ::File.exist?(@download_folder)
|
46
55
|
end
|
47
56
|
end
|
57
|
+
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
data/lib/nsrr/models/file.rb
CHANGED
@@ -16,6 +16,8 @@ module Nsrr
|
|
16
16
|
@web_file_size = json['file_size']
|
17
17
|
@dataset_slug = json['dataset']
|
18
18
|
@file_path = json['file_path']
|
19
|
+
@latest_checksum = ""
|
20
|
+
@latest_file_size = -1
|
19
21
|
end
|
20
22
|
|
21
23
|
# method:
|
@@ -30,30 +32,59 @@ module Nsrr
|
|
30
32
|
if md5_matches?(path)
|
31
33
|
skip
|
32
34
|
else
|
33
|
-
force_download(path, token)
|
35
|
+
force_download(path, token, method)
|
34
36
|
end
|
35
37
|
else
|
36
38
|
if redownload_all
|
37
|
-
force_download(path, token)
|
39
|
+
force_download(path, token, method)
|
38
40
|
else
|
39
41
|
if file_size_matches?(path)
|
40
42
|
skip
|
41
43
|
else
|
42
|
-
force_download(path, token)
|
44
|
+
force_download(path, token, method)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
|
50
|
+
# MD5 or file size checks are now performed after a file is downloaded without error.
|
51
|
+
# If the file check fails, the file is downloaded a second time and rechecked.
|
52
|
+
# If the second download and check fail, the file is marked as failed, and the downloader continues to the subsequent file.
|
53
|
+
def force_download(path, token, method)
|
49
54
|
download_folder = ::File.join(Dir.pwd, path.to_s, @name.to_s)
|
50
55
|
download_url = "#{Nsrr::WEBSITE}/datasets/#{@dataset_slug}/files/a/#{token}/m/nsrr-gem-v#{Nsrr::VERSION::STRING.gsub('.', '-')}/#{@file_path.to_s}"
|
51
56
|
download_request = Nsrr::Helpers::DownloadRequest.new(download_url, download_folder)
|
52
57
|
download_request.get
|
53
58
|
|
59
|
+
download_success = false
|
60
|
+
|
54
61
|
if download_request.error.to_s == ''
|
55
|
-
|
62
|
+
# Check to see if the file downloaded correctly
|
63
|
+
# If the file size doesn't match, attempt one additional download
|
64
|
+
download_success = did_download_succeed?(method, path)
|
65
|
+
|
66
|
+
unless download_success
|
67
|
+
download_request = Nsrr::Helpers::DownloadRequest.new(download_url, download_folder)
|
68
|
+
download_request.get
|
69
|
+
|
70
|
+
download_success = did_download_succeed?(method, path)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if download_request.error.to_s == '' and download_success
|
75
|
+
puts " downloaded".colorize(:green) + " #{@name}"
|
56
76
|
download_request.file_size
|
77
|
+
elsif download_request.error.to_s == ''
|
78
|
+
puts " failed".colorize(:red) + " #{@name}"
|
79
|
+
if method == 'fast'
|
80
|
+
puts " File size mismatch, expected: #{@web_file_size}"
|
81
|
+
puts " actual: #{@latest_file_size}"
|
82
|
+
else
|
83
|
+
puts " File checksum mismatch, expected: #{@web_checksum}"
|
84
|
+
puts " actual: #{@latest_checksum}"
|
85
|
+
end
|
86
|
+
::File.delete(download_folder) if ::File.exist?(download_folder)
|
87
|
+
'fail'
|
57
88
|
else
|
58
89
|
puts " failed".colorize(:red) + " #{@name}"
|
59
90
|
puts " #{download_request.error}"
|
@@ -72,11 +103,12 @@ module Nsrr
|
|
72
103
|
|
73
104
|
def local_checksum(path)
|
74
105
|
download_folder = ::File.join(Dir.pwd, path.to_s, self.name.to_s)
|
75
|
-
if ::File.exist?(download_folder)
|
106
|
+
@latest_checksum = if ::File.exist?(download_folder)
|
76
107
|
Digest::MD5.file(download_folder).hexdigest
|
77
108
|
else
|
78
109
|
""
|
79
110
|
end
|
111
|
+
@latest_checksum
|
80
112
|
end
|
81
113
|
|
82
114
|
def file_size_matches?(path)
|
@@ -85,11 +117,20 @@ module Nsrr
|
|
85
117
|
|
86
118
|
def local_filesize(path)
|
87
119
|
download_folder = ::File.join(Dir.pwd, path.to_s, self.name.to_s)
|
88
|
-
if ::File.exist?(download_folder)
|
120
|
+
@latest_file_size = if ::File.exist?(download_folder)
|
89
121
|
::File.size(download_folder)
|
90
122
|
else
|
91
123
|
-1
|
92
124
|
end
|
125
|
+
@latest_file_size
|
126
|
+
end
|
127
|
+
|
128
|
+
def did_download_succeed?(method, path)
|
129
|
+
if method == 'fast'
|
130
|
+
file_size_matches?(path)
|
131
|
+
else
|
132
|
+
md5_matches?(path)
|
133
|
+
end
|
93
134
|
end
|
94
135
|
|
95
136
|
end
|
data/lib/nsrr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsrr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Remo Mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|