mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 09:14:25 +08:00
fix: make delta pack generation robust for empty diffs and linux paths
This commit is contained in:
@@ -29,17 +29,29 @@ function Get-NormalizedRelativePath {
|
|||||||
[string]$FullPath
|
[string]$FullPath
|
||||||
)
|
)
|
||||||
|
|
||||||
$root = [System.IO.Path]::GetFullPath($RootDir)
|
$separator = [System.IO.Path]::DirectorySeparatorChar
|
||||||
$path = [System.IO.Path]::GetFullPath($FullPath)
|
$altSeparator = [System.IO.Path]::AltDirectorySeparatorChar
|
||||||
|
|
||||||
if (-not $root.EndsWith([System.IO.Path]::DirectorySeparatorChar.ToString()) -and
|
$root = [System.IO.Path]::GetFullPath($RootDir).Replace($altSeparator, $separator).TrimEnd($separator)
|
||||||
-not $root.EndsWith([System.IO.Path]::AltDirectorySeparatorChar.ToString())) {
|
$path = [System.IO.Path]::GetFullPath($FullPath).Replace($altSeparator, $separator)
|
||||||
$root += [System.IO.Path]::DirectorySeparatorChar
|
|
||||||
|
$comparison = if ($separator -eq '\') {
|
||||||
|
[System.StringComparison]::OrdinalIgnoreCase
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[System.StringComparison]::Ordinal
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootUri = [System.Uri]$root
|
$rootWithSeparator = "$root$separator"
|
||||||
$pathUri = [System.Uri]$path
|
if ($path.StartsWith($rootWithSeparator, $comparison)) {
|
||||||
$relative = [System.Uri]::UnescapeDataString($rootUri.MakeRelativeUri($pathUri).ToString())
|
$relative = $path.Substring($rootWithSeparator.Length)
|
||||||
|
}
|
||||||
|
elseif ($path.Equals($root, $comparison)) {
|
||||||
|
$relative = ""
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw "File path '$path' is not under root '$root'."
|
||||||
|
}
|
||||||
|
|
||||||
return $relative.Replace('\', '/')
|
return $relative.Replace('\', '/')
|
||||||
}
|
}
|
||||||
@@ -87,8 +99,9 @@ function New-DeltaArchive {
|
|||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$CurrentRoot,
|
[string]$CurrentRoot,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $false)]
|
||||||
[object[]]$ChangedFiles
|
[AllowEmptyCollection()]
|
||||||
|
[object[]]$ChangedFiles = @()
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Test-Path -LiteralPath $ZipPath) {
|
if (Test-Path -LiteralPath $ZipPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user