coreutils-wasm 1.1.1 → 1.1.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 +4 -4
- data/lib/coreutils_wasm/downloader.rb +26 -21
- data/lib/coreutils_wasm/version.rb +1 -1
- 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: 65800d9d3ebb71f3402d59452228da0221924072355d28493541ea1ded51ebec
|
|
4
|
+
data.tar.gz: 56fada4b8e4987674349278d6bfe9c1e3beef9811e81b463ca13d4919763f4eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4c32c5f6118c5774df9308b738703876fcfd0764c80c8adfbe65f8a9dc0cfed0fbcecef3f8ce1dc5a748c094fa7c083d1cf574c2b2c93e4657079bf3ad33a802
|
|
7
|
+
data.tar.gz: e2a4d442e39f50751ba075e2a2d3286fc36fa8e43b66227255e2712b6d501c291d071abedcb573242037452b335c7bd81d6e098ac94f1204b2ab12fd91bcc3d0
|
|
@@ -32,38 +32,43 @@ module CoreutilsWasm
|
|
|
32
32
|
|
|
33
33
|
def get_latest_release_tag
|
|
34
34
|
uri = URI("https://api.github.com/repos/#{REPO_OWNER}/#{REPO_NAME}/releases/latest")
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
|
|
36
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
|
37
|
+
request = Net::HTTP::Get.new(uri)
|
|
38
|
+
request['Accept'] = 'application/vnd.github+json'
|
|
39
|
+
http.request(request)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
43
|
+
raise "GitHub API returned #{response.code}: could not fetch latest release for #{REPO_OWNER}/#{REPO_NAME}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
data = JSON.parse(response.body)
|
|
37
47
|
data['tag_name']
|
|
38
48
|
end
|
|
39
49
|
|
|
40
50
|
def download_asset(tag, target)
|
|
41
51
|
uri = URI("https://github.com/#{REPO_OWNER}/#{REPO_NAME}/releases/download/#{tag}/#{ASSET_NAME}")
|
|
42
|
-
|
|
43
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
|
44
|
-
request = Net::HTTP::Get.new(uri)
|
|
45
|
-
http.request(request) do |response|
|
|
46
|
-
if response.is_a?(Net::HTTPRedirection)
|
|
47
|
-
return download_from_uri(URI(response['location']), target)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
File.open(target, 'wb') do |file|
|
|
51
|
-
response.read_body do |chunk|
|
|
52
|
-
file.write(chunk)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
52
|
+
download_from_uri(uri, target)
|
|
57
53
|
end
|
|
58
54
|
|
|
59
|
-
def download_from_uri(uri, target)
|
|
55
|
+
def download_from_uri(uri, target, redirect_limit: 5)
|
|
56
|
+
raise 'Too many redirects' if redirect_limit.zero?
|
|
57
|
+
|
|
60
58
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
61
59
|
request = Net::HTTP::Get.new(uri)
|
|
62
60
|
http.request(request) do |response|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
case response
|
|
62
|
+
when Net::HTTPRedirection
|
|
63
|
+
return download_from_uri(URI(response['location']), target, redirect_limit: redirect_limit - 1)
|
|
64
|
+
when Net::HTTPSuccess
|
|
65
|
+
File.open(target, 'wb') do |file|
|
|
66
|
+
response.read_body do |chunk|
|
|
67
|
+
file.write(chunk)
|
|
68
|
+
end
|
|
66
69
|
end
|
|
70
|
+
else
|
|
71
|
+
raise "Download failed: server returned #{response.code} for #{uri}"
|
|
67
72
|
end
|
|
68
73
|
end
|
|
69
74
|
end
|