更新
This commit is contained in:
+56
-37
@@ -158,27 +158,14 @@ function Start-ProcessWithInputFile {
|
||||
[string[]]$Arguments,
|
||||
[string]$InputFile
|
||||
)
|
||||
$psi = [System.Diagnostics.ProcessStartInfo]::new()
|
||||
$psi.FileName = $FilePath
|
||||
$psi.UseShellExecute = $false
|
||||
$psi.RedirectStandardInput = $true
|
||||
Set-ProcessArguments -ProcessStartInfo $psi -Arguments $Arguments
|
||||
|
||||
$process = [System.Diagnostics.Process]::Start($psi)
|
||||
try {
|
||||
$fileStream = [System.IO.File]::OpenRead($InputFile)
|
||||
try {
|
||||
$fileStream.CopyTo($process.StandardInput.BaseStream)
|
||||
} finally {
|
||||
$fileStream.Dispose()
|
||||
}
|
||||
$process.StandardInput.Close()
|
||||
$process.WaitForExit()
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Fail "command failed ($($process.ExitCode)): $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
} finally {
|
||||
$process.Dispose()
|
||||
$commandParts = @((ConvertTo-WindowsArgument $FilePath))
|
||||
$commandParts += @($Arguments | ForEach-Object { ConvertTo-WindowsArgument $_ })
|
||||
$commandLine = (($commandParts -join " ") + " < " + (ConvertTo-WindowsArgument $InputFile))
|
||||
|
||||
& cmd.exe /d /s /c $commandLine
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Fail "command failed ($LASTEXITCODE): $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,22 +175,13 @@ function Start-ProcessWithInputText {
|
||||
[string[]]$Arguments,
|
||||
[string]$InputText
|
||||
)
|
||||
$psi = [System.Diagnostics.ProcessStartInfo]::new()
|
||||
$psi.FileName = $FilePath
|
||||
$psi.UseShellExecute = $false
|
||||
$psi.RedirectStandardInput = $true
|
||||
Set-ProcessArguments -ProcessStartInfo $psi -Arguments $Arguments
|
||||
|
||||
$process = [System.Diagnostics.Process]::Start($psi)
|
||||
$inputFile = [System.IO.Path]::GetTempFileName()
|
||||
try {
|
||||
$process.StandardInput.Write($InputText)
|
||||
$process.StandardInput.Close()
|
||||
$process.WaitForExit()
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Fail "command failed ($($process.ExitCode)): $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
[System.IO.File]::WriteAllText($inputFile, $InputText, $Utf8NoBom)
|
||||
Start-ProcessWithInputFile -FilePath $FilePath -Arguments $Arguments -InputFile $inputFile
|
||||
} finally {
|
||||
$process.Dispose()
|
||||
Remove-Item -LiteralPath $inputFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,7 +460,7 @@ if (-not (Test-Path -LiteralPath $SourceAbs -PathType Container)) {
|
||||
Fail "source directory not found: $SourceDir"
|
||||
}
|
||||
|
||||
$FullIncludePaths = @("app", "config", "extend", "public/dongqiudi-crawler", "route")
|
||||
$FullIncludePaths = @("app", "config", "extend", "public", "route")
|
||||
$GitCwd = $RepoRoot
|
||||
$GitPathPrefix = $SourceDir
|
||||
$SourceIsGitRepo = $false
|
||||
@@ -647,7 +625,49 @@ run_priv() {
|
||||
fi
|
||||
}
|
||||
|
||||
tar_extract_flags=(--no-same-owner --no-same-permissions --no-overwrite-dir)
|
||||
copy_payload_without_metadata() {
|
||||
local payload_dir="$1"
|
||||
local target_dir="$2"
|
||||
|
||||
while IFS= read -r -d '' dir; do
|
||||
local rel="${dir#./}"
|
||||
[[ "$rel" != "." ]] || continue
|
||||
run_priv mkdir -p "$target_dir/$rel"
|
||||
done < <(cd "$payload_dir" && find . -type d -print0)
|
||||
|
||||
while IFS= read -r -d '' item; do
|
||||
local rel="${item#./}"
|
||||
local source_path="$payload_dir/$rel"
|
||||
local target_path="$target_dir/$rel"
|
||||
local target_parent
|
||||
target_parent="$(dirname "$target_path")"
|
||||
run_priv mkdir -p "$target_parent"
|
||||
|
||||
if [[ -L "$source_path" ]]; then
|
||||
local link_target
|
||||
link_target="$(readlink "$source_path")"
|
||||
run_priv rm -f "$target_path"
|
||||
run_priv ln -s "$link_target" "$target_path"
|
||||
elif [[ -f "$source_path" ]]; then
|
||||
run_priv cp -f "$source_path" "$target_path"
|
||||
else
|
||||
echo "[deploy][remote][warn] skip unsupported payload entry: $rel" >&2
|
||||
fi
|
||||
done < <(cd "$payload_dir" && find . ! -type d -print0)
|
||||
}
|
||||
|
||||
install_payload() {
|
||||
local payload_dir="$1"
|
||||
local target_dir="$2"
|
||||
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
remote_log "install payload into remote dir with rsync"
|
||||
run_priv rsync -r --links --no-perms --no-owner --no-group "$payload_dir"/ "$target_dir"/
|
||||
else
|
||||
remote_log "install payload into remote dir with file copy"
|
||||
copy_payload_without_metadata "$payload_dir" "$target_dir"
|
||||
fi
|
||||
}
|
||||
|
||||
remote_log "prepare remote work dir: $REMOTE_WORK_DIR"
|
||||
mkdir -p "$REMOTE_WORK_DIR"
|
||||
@@ -657,8 +677,7 @@ remote_log "ensure remote dir: $REMOTE_DIR"
|
||||
run_priv mkdir -p "$REMOTE_DIR"
|
||||
|
||||
if [[ -d "$REMOTE_WORK_DIR/payload" ]]; then
|
||||
remote_log "install payload into remote dir"
|
||||
tar -cf - -C "$REMOTE_WORK_DIR/payload" . | run_priv tar "${tar_extract_flags[@]}" -xf - -C "$REMOTE_DIR"
|
||||
install_payload "$REMOTE_WORK_DIR/payload" "$REMOTE_DIR"
|
||||
fi
|
||||
|
||||
if [[ -f "$REMOTE_WORK_DIR/.deleted-paths.txt" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user