From 51e569e110c3d2472fe158b5d2f4d367cca49dff Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 13 Oct 2021 10:43:44 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 2095 (#2960) * Mitigate relative path calculation error on multiple iterations * Revert "Mitigate relative path calculation error on multiple iterations" This reverts commit 45baedd990c6a3085742a38a4891d8706a93be77. * GetRelativePath should check if path is already relative before calling [IO.Path]::GetRelativePath Co-authored-by: Daniel Jurek --- 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 10cb4158c..1b543ba37 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 "\\", '/'