From 45baedd990c6a3085742a38a4891d8706a93be77 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Tue, 12 Oct 2021 09:51:15 -0700 Subject: [PATCH 1/3] Mitigate relative path calculation error on multiple iterations --- eng/common/scripts/Save-Package-Properties.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/eng/common/scripts/Save-Package-Properties.ps1 b/eng/common/scripts/Save-Package-Properties.ps1 index 10cb4158c01..b29a6bc02df 100644 --- a/eng/common/scripts/Save-Package-Properties.ps1 +++ b/eng/common/scripts/Save-Package-Properties.ps1 @@ -48,8 +48,15 @@ function SetOutput($outputPath, $incomingPackageSpec) { else { $outputObject = $incomingPackageSpec + + # Set file paths to relative paths. Only do this if there is no existing + # package info json file as running this multiple times can create + # unexpected relative paths in some scenarios. + $outputObject.DirectoryPath = GetRelativePath $outputObject.DirectoryPath + $outputObject.ReadMePath = GetRelativePath $outputObject.ReadMePath + $outputObject.ChangeLogPath = GetRelativePath $outputObject.ChangeLogPath } - + if ($addDevVersion) { @@ -58,11 +65,6 @@ function SetOutput($outputPath, $incomingPackageSpec) { $outputObject.DevVersion = $incomingPackageSpec.Version } - # Set file paths to relative paths - $outputObject.DirectoryPath = GetRelativePath $outputObject.DirectoryPath - $outputObject.ReadMePath = GetRelativePath $outputObject.ReadMePath - $outputObject.ChangeLogPath = GetRelativePath $outputObject.ChangeLogPath - Set-Content ` -Path $outputPath ` -Value (ConvertTo-Json -InputObject $outputObject -Depth 100) From cbca4a6a0000ca37ed783fc53dd41690e336cdff Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Tue, 12 Oct 2021 20:35:45 -0700 Subject: [PATCH 2/3] Revert "Mitigate relative path calculation error on multiple iterations" This reverts commit 45baedd990c6a3085742a38a4891d8706a93be77. --- eng/common/scripts/Save-Package-Properties.ps1 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/eng/common/scripts/Save-Package-Properties.ps1 b/eng/common/scripts/Save-Package-Properties.ps1 index b29a6bc02df..10cb4158c01 100644 --- a/eng/common/scripts/Save-Package-Properties.ps1 +++ b/eng/common/scripts/Save-Package-Properties.ps1 @@ -48,15 +48,8 @@ function SetOutput($outputPath, $incomingPackageSpec) { else { $outputObject = $incomingPackageSpec - - # Set file paths to relative paths. Only do this if there is no existing - # package info json file as running this multiple times can create - # unexpected relative paths in some scenarios. - $outputObject.DirectoryPath = GetRelativePath $outputObject.DirectoryPath - $outputObject.ReadMePath = GetRelativePath $outputObject.ReadMePath - $outputObject.ChangeLogPath = GetRelativePath $outputObject.ChangeLogPath } - + if ($addDevVersion) { @@ -65,6 +58,11 @@ function SetOutput($outputPath, $incomingPackageSpec) { $outputObject.DevVersion = $incomingPackageSpec.Version } + # Set file paths to relative paths + $outputObject.DirectoryPath = GetRelativePath $outputObject.DirectoryPath + $outputObject.ReadMePath = GetRelativePath $outputObject.ReadMePath + $outputObject.ChangeLogPath = GetRelativePath $outputObject.ChangeLogPath + Set-Content ` -Path $outputPath ` -Value (ConvertTo-Json -InputObject $outputObject -Depth 100) From 4df21ff281223a95cd394e89b510873ea3f52d01 Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Tue, 12 Oct 2021 20:57:49 -0700 Subject: [PATCH 3/3] GetRelativePath should check if path is already relative before calling [IO.Path]::GetRelativePath --- eng/common/scripts/Save-Package-Properties.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eng/common/scripts/Save-Package-Properties.ps1 b/eng/common/scripts/Save-Package-Properties.ps1 index 10cb4158c01..1b543ba37c5 100644 --- a/eng/common/scripts/Save-Package-Properties.ps1 +++ b/eng/common/scripts/Save-Package-Properties.ps1 @@ -73,6 +73,14 @@ function GetRelativePath($path) { if (!$path) { return '' } + + # If the path is already relative return the path. Calling `GetRelativePath` + # on a relative path converts the relative path to an absolute path based on + # the current working directory which can result in unexpected outputs. + if (![IO.Path]::IsPathRooted($path)) { + return $path + } + $relativeTo = Resolve-Path $PSScriptRoot/../../../ # Replace "\" with "/" so the path is valid across other platforms and tools $relativePath = [IO.Path]::GetRelativePath($relativeTo, $path) -replace "\\", '/'