





















@@ -194,7 +194,7 @@ function Expand-PortableNodeArchive {
194194$tarCommand = Get-Command tar -ErrorAction SilentlyContinue
195195if ($tarCommand -and $tarCommand.Source) {
196196New-Item -ItemType Directory -Force -Path $DestinationPath | Out-Null
197-& $tarCommand.Source -xf $ZipPath -C $DestinationPath
197+& $tarCommand.Source -xf $ZipPath -C $DestinationPath --strip-components 1
198198if ($LASTEXITCODE -eq 0) {
199199return
200200 }
@@ -206,8 +206,23 @@ function Expand-PortableNodeArchive {
206206Write-Host "[!] tar extraction failed with exit code $tarExitCode; trying .NET zip extraction." -ForegroundColor Yellow
207207 }
208208209-Add-Type -AssemblyName System.IO.Compression.FileSystem
210- [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $DestinationPath)
209+$fallbackExtract = Join-Path (Split-Path -Parent $DestinationPath) ("portable-node-extract-" + [guid]::NewGuid().ToString("N"))
210+try {
211+Add-Type -AssemblyName System.IO.Compression.FileSystem
212+ [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $fallbackExtract)
213+214+$nodeDir = Get-ChildItem -Path $fallbackExtract -Directory |
215+Where-Object { Test-Path (Join-Path $_.FullName "node.exe") } |
216+Select-Object -First 1
217+if (-not $nodeDir) {
218+throw "Node.js archive did not contain node.exe."
219+ }
220+Copy-Item -LiteralPath $nodeDir.FullName -Destination $DestinationPath -Recurse -Force
221+ } finally {
222+if (Test-Path $fallbackExtract) {
223+Remove-Item -Recurse -Force $fallbackExtract
224+ }
225+ }
211226}
212227213228function Install-PortableNode {
@@ -226,36 +241,20 @@ function Install-PortableNode {
226241$portableRoot = Get-PortableNodeRoot
227242$portableParent = Split-Path -Parent $portableRoot
228243$tmpZip = Join-Path $env:TEMP $download.Name
229-$tmpExtract = Join-Path $env:TEMP ("openclaw-portable-node-" + [guid]::NewGuid().ToString("N"))
230244231245New-Item -ItemType Directory -Force -Path $portableParent | Out-Null
232246if (Test-Path $portableRoot) {
233247Remove-Item -Recurse -Force $portableRoot
234248 }
235-if (Test-Path $tmpExtract) {
236-Remove-Item -Recurse -Force $tmpExtract
237- }
238249239250try {
240251Write-Host " Downloading Node.js $($download.Version)..." -ForegroundColor Gray
241252Invoke-WebRequest -UseBasicParsing -Uri $download.Url -OutFile $tmpZip
242-Expand-PortableNodeArchive -ZipPath $tmpZip -DestinationPath $tmpExtract
243-244-$nodeDir = Get-ChildItem -Path $tmpExtract -Directory |
245-Where-Object { Test-Path (Join-Path $_.FullName "node.exe") } |
246-Select-Object -First 1
247-if (-not $nodeDir) {
248-throw "Node.js archive did not contain node.exe."
249- }
250-251-Copy-Item -LiteralPath $nodeDir.FullName -Destination $portableRoot -Recurse -Force
253+Expand-PortableNodeArchive -ZipPath $tmpZip -DestinationPath $portableRoot
252254 } finally {
253255if (Test-Path $tmpZip) {
254256Remove-Item -Force $tmpZip
255257 }
256-if (Test-Path $tmpExtract) {
257-Remove-Item -Recurse -Force $tmpExtract
258- }
259258 }
260259261260if (-not (Use-PortableNodeIfPresent)) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。