@paulnsorensen/tilth-nightly 0.0.0-experimental.23.1 → 0.0.0-experimental.231.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.
- package/install.js +23 -2
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -42,10 +42,24 @@ fs.mkdirSync(binDir, { recursive: true });
|
|
|
42
42
|
console.log(`tilth: downloading ${target} nightly binary...`);
|
|
43
43
|
|
|
44
44
|
const MAX_REDIRECTS = 5;
|
|
45
|
+
const MAX_ATTEMPTS = 4;
|
|
46
|
+
const RETRY_BACKOFF_MS = [1000, 2000, 4000];
|
|
47
|
+
|
|
48
|
+
function isRetryableStatus(code) {
|
|
49
|
+
return code === 429 || code === 404 || (code >= 500 && code < 600);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function retryDownload(url, depth, callback, attempt, reason) {
|
|
53
|
+
const delayMs = RETRY_BACKOFF_MS[attempt - 1];
|
|
54
|
+
console.error(
|
|
55
|
+
`tilth: download failed (${reason}), retry ${attempt}/${MAX_ATTEMPTS - 1} in ${delayMs / 1000}s`,
|
|
56
|
+
);
|
|
57
|
+
setTimeout(() => follow(url, depth, callback, attempt + 1), delayMs);
|
|
58
|
+
}
|
|
45
59
|
|
|
46
60
|
// HTTPS-only, depth-capped: this binary is executed after download, so never
|
|
47
61
|
// let a redirect downgrade to plaintext or loop.
|
|
48
|
-
function follow(url, depth, callback) {
|
|
62
|
+
function follow(url, depth, callback, attempt = 1) {
|
|
49
63
|
if (!url.startsWith("https:")) {
|
|
50
64
|
console.error(`tilth: refusing non-HTTPS download URL: ${url}`);
|
|
51
65
|
process.exit(1);
|
|
@@ -58,7 +72,10 @@ function follow(url, depth, callback) {
|
|
|
58
72
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
59
73
|
res.resume();
|
|
60
74
|
// Location may be relative; resolve against the current URL before recursing.
|
|
61
|
-
follow(new URL(res.headers.location, url).href, depth + 1, callback);
|
|
75
|
+
follow(new URL(res.headers.location, url).href, depth + 1, callback, attempt);
|
|
76
|
+
} else if (isRetryableStatus(res.statusCode) && attempt < MAX_ATTEMPTS) {
|
|
77
|
+
res.resume();
|
|
78
|
+
retryDownload(url, depth, callback, attempt, `HTTP ${res.statusCode}`);
|
|
62
79
|
} else if (res.statusCode !== 200) {
|
|
63
80
|
console.error(`tilth: download failed (HTTP ${res.statusCode})`);
|
|
64
81
|
console.error(`URL: ${url}`);
|
|
@@ -69,6 +86,10 @@ function follow(url, depth, callback) {
|
|
|
69
86
|
}
|
|
70
87
|
});
|
|
71
88
|
req.on("error", (err) => {
|
|
89
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
90
|
+
retryDownload(url, depth, callback, attempt, err.message);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
72
93
|
console.error(`tilth: download failed: ${err.message}`);
|
|
73
94
|
console.error("Install manually: cargo install --git https://github.com/paulnsorensen/tilth");
|
|
74
95
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paulnsorensen/tilth-nightly",
|
|
3
|
-
"version": "0.0.0-experimental.
|
|
3
|
+
"version": "0.0.0-experimental.231.2",
|
|
4
4
|
"description": "EXPERIMENTAL rolling build of paulnsorensen/tilth off main — unofficial fork, NOT the official `tilth` package",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tilth": "run.js"
|