@oadank/dsh-input-tools 0.3.5 → 0.3.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oadank/dsh-input-tools",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -61,14 +61,20 @@ New-Item -ItemType Directory -Force -Path "$InstallDir\tmp" | Out-Null
61
61
  # ---- 1b. 下载/解压工具函数(2026-08-21 增强:断点续传 + 完整性校验 + 损坏自动重试)----
62
62
  # 之前 XDN 实测:GitHub 大文件下载中断 → 只下了 42.7MB/230MB → tar 报 Truncated → 脚本抛错退出,
63
63
  # 用户只看到"跑到最后报错"毫无提示。现在 curl -C - 断点续传 + 解压后校验,损坏文件自动删除重下。
64
+ # ⚠️ PowerShell 坑:$ErrorActionPreference=Stop 时 curl/tar 写 stderr(进度/警告)会抛 NativeCommandError
65
+ # 中断脚本(0.3.5 实测踩中)。因此所有原生命令用 cmd /c 包装 + 2>nul 吞 stderr + 临时放宽 EAP,
66
+ # 只依据 $LASTEXITCODE 判断成败。
64
67
  function Download-Resume {
65
68
  param([string]$Url, [string]$OutFile)
66
69
  for ($attempt = 1; $attempt -le 3; $attempt++) {
67
70
  Write-Host " 下载(第 $attempt 次尝试): $Url" -ForegroundColor Yellow
68
- # Windows 10+ 自带 curl.exe;-C - 断点续传;--retry 网络层重试
69
- & curl.exe -L -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o $OutFile $Url 2>$null
70
- if ($LASTEXITCODE -eq 0) { return $true }
71
- Write-Host " 下载中断(exit=$LASTEXITCODE),3 秒后重试..." -ForegroundColor Yellow
71
+ $prevEAP = $ErrorActionPreference
72
+ $ErrorActionPreference = "Continue"
73
+ cmd /c "curl.exe -sL -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o `"$OutFile`" `"$Url`" 2>nul"
74
+ $code = $LASTEXITCODE
75
+ $ErrorActionPreference = $prevEAP
76
+ if ($code -eq 0) { return $true }
77
+ Write-Host " 下载中断(exit=$code),3 秒后重试..." -ForegroundColor Yellow
72
78
  Start-Sleep -Seconds 3
73
79
  }
74
80
  return $false
@@ -77,10 +83,14 @@ function Expand-TarBz2 {
77
83
  param([string]$Archive, [string]$Dest, [int]$Strip = 0)
78
84
  $tmpDir = Join-Path $Dest ".extract-tmp"
79
85
  New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
80
- $tarArgs = @('-xjf', $Archive, '-C', $tmpDir)
81
- if ($Strip -gt 0) { $tarArgs += "--strip-components=$Strip" }
82
- tar @tarArgs 2>$null
83
- if ($LASTEXITCODE -ne 0) {
86
+ $stripArgs = ""
87
+ if ($Strip -gt 0) { $stripArgs = "--strip-components=$Strip" }
88
+ $prevEAP = $ErrorActionPreference
89
+ $ErrorActionPreference = "Continue"
90
+ cmd /c "tar -xjf `"$Archive`" -C `"$tmpDir`" $stripArgs 2>nul"
91
+ $code = $LASTEXITCODE
92
+ $ErrorActionPreference = $prevEAP
93
+ if ($code -ne 0) {
84
94
  Write-Host " 解压失败:压缩包损坏或不完整($Archive)" -ForegroundColor Red
85
95
  Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
86
96
  Remove-Item -Force $Archive -ErrorAction SilentlyContinue
@@ -18,13 +18,19 @@ $ErrorActionPreference = "Stop"
18
18
  $Version = "v1.13.6"
19
19
 
20
20
  # ---- 下载/解压工具函数(2026-08-21 增强:断点续传 + 完整性校验 + 损坏自动重试)----
21
+ # ⚠️ PowerShell 坑:$ErrorActionPreference=Stop 时 curl/tar 写 stderr 会抛 NativeCommandError(0.3.5 实测踩中)。
22
+ # 原生命令一律 cmd /c 包装 + 2>nul + 临时放宽 EAP,只依据 $LASTEXITCODE。
21
23
  function Download-Resume {
22
24
  param([string]$Url, [string]$OutFile)
23
25
  for ($attempt = 1; $attempt -le 3; $attempt++) {
24
26
  Write-Host " 下载(第 $attempt 次尝试): $Url" -ForegroundColor Yellow
25
- & curl.exe -L -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o $OutFile $Url 2>$null
26
- if ($LASTEXITCODE -eq 0) { return $true }
27
- Write-Host " 下载中断(exit=$LASTEXITCODE),3 秒后重试..." -ForegroundColor Yellow
27
+ $prevEAP = $ErrorActionPreference
28
+ $ErrorActionPreference = "Continue"
29
+ cmd /c "curl.exe -sL -C - --retry 3 --retry-delay 2 --connect-timeout 20 -o `"$OutFile`" `"$Url`" 2>nul"
30
+ $code = $LASTEXITCODE
31
+ $ErrorActionPreference = $prevEAP
32
+ if ($code -eq 0) { return $true }
33
+ Write-Host " 下载中断(exit=$code),3 秒后重试..." -ForegroundColor Yellow
28
34
  Start-Sleep -Seconds 3
29
35
  }
30
36
  return $false
@@ -33,10 +39,14 @@ function Expand-TarBz2 {
33
39
  param([string]$Archive, [string]$Dest, [int]$Strip = 0)
34
40
  $tmpDir = Join-Path $Dest ".extract-tmp"
35
41
  New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
36
- $tarArgs = @('-xjf', $Archive, '-C', $tmpDir)
37
- if ($Strip -gt 0) { $tarArgs += "--strip-components=$Strip" }
38
- tar @tarArgs 2>$null
39
- if ($LASTEXITCODE -ne 0) {
42
+ $stripArgs = ""
43
+ if ($Strip -gt 0) { $stripArgs = "--strip-components=$Strip" }
44
+ $prevEAP = $ErrorActionPreference
45
+ $ErrorActionPreference = "Continue"
46
+ cmd /c "tar -xjf `"$Archive`" -C `"$tmpDir`" $stripArgs 2>nul"
47
+ $code = $LASTEXITCODE
48
+ $ErrorActionPreference = $prevEAP
49
+ if ($code -ne 0) {
40
50
  Write-Host " 解压失败:压缩包损坏或不完整($Archive)" -ForegroundColor Red
41
51
  Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
42
52
  Remove-Item -Force $Archive -ErrorAction SilentlyContinue