@@ -194,7 +194,7 @@ function Expand-PortableNodeArchive {
194194 $tarCommand = Get-Command tar - ErrorAction SilentlyContinue
195195 if ($tarCommand -and $tarCommand.Source ) {
196196 New-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
198198 if ($LASTEXITCODE -eq 0 ) {
199199 return
200200 }
@@ -206,8 +206,23 @@ function Expand-PortableNodeArchive {
206206 Write-Host " [!] tar extraction failed with exit code $tarExitCode ; trying .NET zip extraction." - ForegroundColor Yellow
207207 }
208208
209- 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}
212227
213228function 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" ))
230244
231245 New-Item - ItemType Directory - Force - Path $portableParent | Out-Null
232246 if (Test-Path $portableRoot ) {
233247 Remove-Item - Recurse - Force $portableRoot
234248 }
235- if (Test-Path $tmpExtract ) {
236- Remove-Item - Recurse - Force $tmpExtract
237- }
238249
239250 try {
240251 Write-Host " Downloading Node.js $ ( $download.Version ) ..." - ForegroundColor Gray
241252 Invoke-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 {
253255 if (Test-Path $tmpZip ) {
254256 Remove-Item - Force $tmpZip
255257 }
256- if (Test-Path $tmpExtract ) {
257- Remove-Item - Recurse - Force $tmpExtract
258- }
259258 }
260259
261260 if (-not (Use-PortableNodeIfPresent )) {
0 commit comments