asherah 3.0.12 → 3.0.14
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/package.json +9 -3
- package/scripts/download-libraries.sh +52 -10
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asherah",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "Asherah envelope encryption and key rotation library",
|
|
5
|
+
"main": "./dist/asherah.node",
|
|
6
|
+
"types": "./dist/asherah.d.ts",
|
|
5
7
|
"exports": {
|
|
6
|
-
"
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/asherah.d.ts",
|
|
10
|
+
"require": "./dist/asherah.node",
|
|
11
|
+
"import": "./dist/asherah.node",
|
|
12
|
+
"default": "./dist/asherah.node"
|
|
13
|
+
}
|
|
7
14
|
},
|
|
8
15
|
"repository": {
|
|
9
16
|
"type": "git",
|
|
@@ -74,7 +81,6 @@
|
|
|
74
81
|
"spec": "test/**/*.spec.ts",
|
|
75
82
|
"require": "ts-node/register"
|
|
76
83
|
},
|
|
77
|
-
"types": "dist/asherah.d.ts",
|
|
78
84
|
"dependencies": {
|
|
79
85
|
"node-addon-api": "^8.3.0"
|
|
80
86
|
}
|
|
@@ -5,6 +5,8 @@ set -e # Exit on any command failure
|
|
|
5
5
|
# Global Constants
|
|
6
6
|
CHECK_INTERVAL_SECONDS=$((5 * 60)) # 5 minutes
|
|
7
7
|
MAX_DOWNLOAD_RETRIES=3
|
|
8
|
+
MAX_FILE_DOWNLOAD_RETRIES=5
|
|
9
|
+
DOWNLOAD_TIMEOUT=60 # 1 minute per file
|
|
8
10
|
|
|
9
11
|
# Function to check if a specific file download is necessary
|
|
10
12
|
function check_download_required {
|
|
@@ -52,19 +54,45 @@ function check_download_required {
|
|
|
52
54
|
return 1 # (download not required)
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
# Function to download a file
|
|
57
|
+
# Function to download a file with retry logic
|
|
56
58
|
function download_file {
|
|
57
59
|
local url=$1
|
|
58
60
|
local file=$2
|
|
59
61
|
local etag_file="${file}.etag"
|
|
62
|
+
local retry_count=0
|
|
63
|
+
local backoff=1
|
|
64
|
+
|
|
65
|
+
while [[ $retry_count -lt $MAX_FILE_DOWNLOAD_RETRIES ]]; do
|
|
66
|
+
# Use --show-error to display errors even with -s (silent progress)
|
|
67
|
+
# Add connection and max-time timeouts to prevent hanging
|
|
68
|
+
if curl -sS -L --fail \
|
|
69
|
+
--connect-timeout 30 \
|
|
70
|
+
--max-time "$DOWNLOAD_TIMEOUT" \
|
|
71
|
+
--retry 2 \
|
|
72
|
+
--retry-delay 2 \
|
|
73
|
+
--etag-save "$etag_file" \
|
|
74
|
+
--etag-compare "$etag_file" \
|
|
75
|
+
-O "$url"; then
|
|
76
|
+
# Explicitly touch the etag file to update its modification time only if successful
|
|
77
|
+
touch "$etag_file"
|
|
78
|
+
return 0
|
|
79
|
+
fi
|
|
60
80
|
|
|
61
|
-
|
|
62
|
-
echo "Failed to download $url" >&2
|
|
63
|
-
exit 1
|
|
64
|
-
fi
|
|
81
|
+
((retry_count++))
|
|
65
82
|
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
if [[ $retry_count -lt $MAX_FILE_DOWNLOAD_RETRIES ]]; then
|
|
84
|
+
echo "Download attempt $retry_count failed for $url, retrying in ${backoff}s..." >&2
|
|
85
|
+
sleep "$backoff"
|
|
86
|
+
# Exponential backoff with a cap at 16 seconds
|
|
87
|
+
backoff=$((backoff * 2))
|
|
88
|
+
if [[ $backoff -gt 16 ]]; then
|
|
89
|
+
backoff=16
|
|
90
|
+
fi
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
|
|
94
|
+
echo "Failed to download $url after $MAX_FILE_DOWNLOAD_RETRIES attempts" >&2
|
|
95
|
+
return 1
|
|
68
96
|
}
|
|
69
97
|
|
|
70
98
|
# Function to verify checksums
|
|
@@ -245,16 +273,31 @@ function main {
|
|
|
245
273
|
local retries=0
|
|
246
274
|
local checksums_verified=false
|
|
247
275
|
while [[ $checksums_verified == false && $retries -lt $MAX_DOWNLOAD_RETRIES ]]; do
|
|
276
|
+
local download_failed=false
|
|
277
|
+
|
|
248
278
|
# Per-file touch and download logic
|
|
249
279
|
for i in "${!file_names[@]}"; do
|
|
250
280
|
if check_download_required "${file_names[$i]}" "$no_cache" "$CHECK_INTERVAL_SECONDS"; then
|
|
251
|
-
download_file "${file_urls[$i]}" "${file_names[$i]}"
|
|
281
|
+
if ! download_file "${file_urls[$i]}" "${file_names[$i]}"; then
|
|
282
|
+
echo "Failed to download ${file_names[$i]}" >&2
|
|
283
|
+
download_failed=true
|
|
284
|
+
break
|
|
285
|
+
fi
|
|
252
286
|
else
|
|
253
287
|
interval_str=$(interval_message "$CHECK_INTERVAL_SECONDS")
|
|
254
288
|
echo "${file_names[$i]} is up to date (checked within the last ${interval_str})"
|
|
255
289
|
fi
|
|
256
290
|
done
|
|
257
291
|
|
|
292
|
+
# If any download failed, retry the whole batch
|
|
293
|
+
if [[ $download_failed == true ]]; then
|
|
294
|
+
echo "Download failed, cleaning up and retrying..."
|
|
295
|
+
rm -f ./*.a ./*.h ./*.so ./*.dylib ./*.etag
|
|
296
|
+
((retries++))
|
|
297
|
+
sleep 2
|
|
298
|
+
continue
|
|
299
|
+
fi
|
|
300
|
+
|
|
258
301
|
# Verify checksums and copy files
|
|
259
302
|
if verify_checksums "${archive}" "${header}" "${warmup}" "${sums}"; then
|
|
260
303
|
copy_files "${archive}" "${header}"
|
|
@@ -263,12 +306,11 @@ function main {
|
|
|
263
306
|
echo "Verification failed, re-downloading files..."
|
|
264
307
|
((retries++))
|
|
265
308
|
# Sleep for a bit before retrying to avoid hammering the server
|
|
266
|
-
sleep
|
|
309
|
+
sleep 2
|
|
267
310
|
fi
|
|
268
311
|
done
|
|
269
312
|
|
|
270
313
|
if [[ $checksums_verified == true ]]; then
|
|
271
|
-
copy_files "${archive}" "${header}"
|
|
272
314
|
echo "Asherah libraries downloaded successfully"
|
|
273
315
|
else
|
|
274
316
|
echo "Failed to download Asherah libraries after $retries retries."
|