From 833c69305b2da62a7697e4eee4df59f0df3731a6 Mon Sep 17 00:00:00 2001 From: lincube Date: Mon, 20 Apr 2026 08:07:58 +0800 Subject: [PATCH] fix: make delta pack generation robust for empty diffs and linux paths --- scripts/Generate-DeltaPackage.ps1 | 33 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/scripts/Generate-DeltaPackage.ps1 b/scripts/Generate-DeltaPackage.ps1 index 5bb7705..8166470 100644 --- a/scripts/Generate-DeltaPackage.ps1 +++ b/scripts/Generate-DeltaPackage.ps1 @@ -29,17 +29,29 @@ function Get-NormalizedRelativePath { [string]$FullPath ) - $root = [System.IO.Path]::GetFullPath($RootDir) - $path = [System.IO.Path]::GetFullPath($FullPath) + $separator = [System.IO.Path]::DirectorySeparatorChar + $altSeparator = [System.IO.Path]::AltDirectorySeparatorChar - if (-not $root.EndsWith([System.IO.Path]::DirectorySeparatorChar.ToString()) -and - -not $root.EndsWith([System.IO.Path]::AltDirectorySeparatorChar.ToString())) { - $root += [System.IO.Path]::DirectorySeparatorChar + $root = [System.IO.Path]::GetFullPath($RootDir).Replace($altSeparator, $separator).TrimEnd($separator) + $path = [System.IO.Path]::GetFullPath($FullPath).Replace($altSeparator, $separator) + + $comparison = if ($separator -eq '\') { + [System.StringComparison]::OrdinalIgnoreCase + } + else { + [System.StringComparison]::Ordinal } - $rootUri = [System.Uri]$root - $pathUri = [System.Uri]$path - $relative = [System.Uri]::UnescapeDataString($rootUri.MakeRelativeUri($pathUri).ToString()) + $rootWithSeparator = "$root$separator" + if ($path.StartsWith($rootWithSeparator, $comparison)) { + $relative = $path.Substring($rootWithSeparator.Length) + } + elseif ($path.Equals($root, $comparison)) { + $relative = "" + } + else { + throw "File path '$path' is not under root '$root'." + } return $relative.Replace('\', '/') } @@ -87,8 +99,9 @@ function New-DeltaArchive { [Parameter(Mandatory = $true)] [string]$CurrentRoot, - [Parameter(Mandatory = $true)] - [object[]]$ChangedFiles + [Parameter(Mandatory = $false)] + [AllowEmptyCollection()] + [object[]]$ChangedFiles = @() ) if (Test-Path -LiteralPath $ZipPath) {