From 94a5e8a63968bb58ebfde5237bb8b80fa13ca806 Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Fri, 10 Jul 2026 11:42:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=8F=91=E5=B8=83):=20=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=20Windows=20=E4=B8=AD=E6=96=87=E8=B7=AF=E5=BE=84=E6=89=93?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/publish-to-server.ps1 | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/publish-to-server.ps1 b/scripts/publish-to-server.ps1 index a1cfb36..6866ace 100644 --- a/scripts/publish-to-server.ps1 +++ b/scripts/publish-to-server.ps1 @@ -45,6 +45,19 @@ function Get-CommandPath([string]$name) { return $cmd.Source } +function Get-TarCommandPath { + $gitCommand = Get-Command "git" -ErrorAction SilentlyContinue + if ($gitCommand) { + $gitRoot = Split-Path (Split-Path $gitCommand.Source -Parent) -Parent + $gitTar = Join-Path $gitRoot "usr\bin\tar.exe" + if (Test-Path -LiteralPath $gitTar -PathType Leaf) { + return $gitTar + } + } + + return Get-CommandPath "tar" +} + function Invoke-External { param( [string]$FilePath, @@ -199,7 +212,9 @@ if ($HostName -notmatch '^[A-Za-z0-9.:-]+$') { throw "Host name contains unsupported characters." } -$tarExe = Get-CommandPath "tar" +$tarExe = Get-TarCommandPath +$tarDirectory = Split-Path $tarExe -Parent +$useGnuTar = Test-Path -LiteralPath (Join-Path $tarDirectory "gzip.exe") -PathType Leaf $remoteTarget = "$User@$HostName" $remoteDirLiteral = ConvertTo-ShellLiteral $RemoteDir $remoteArchiveLiteral = ConvertTo-ShellLiteral $RemoteArchive @@ -299,9 +314,9 @@ $deployCommand = $deployCommand.Replace("__SKIP_DEPLOY__", $skipDeployValue) $deployCommand = $deployCommand.Replace("__SKIP_BACKUP__", $skipBackupValue) try { - [System.IO.File]::WriteAllLines( + [System.IO.File]::WriteAllText( $fileListPath, - [string[]]$files, + (($files -join "`n") + "`n"), $utf8NoBom ) @@ -310,7 +325,17 @@ try { } Write-Host ">>> Creating release archive..." - Invoke-External -FilePath $tarExe -Arguments @("-czf", $archivePath, "-T", $fileListPath) -Description "Create release archive" + $tarArguments = @("-czf", $archivePath, "-T", $fileListPath) + $originalPath = $env:PATH + if ($useGnuTar) { + $env:PATH = "$tarDirectory;$env:PATH" + $tarArguments = @("--force-local") + $tarArguments + } + try { + Invoke-External -FilePath $tarExe -Arguments $tarArguments -Description "Create release archive" + } finally { + $env:PATH = $originalPath + } if ($password) { $plinkExe = Get-CommandPath "plink"