Skip to content

Commit

Permalink
GetRelativePath should check if path is already relative before calli…
Browse files Browse the repository at this point in the history
…ng [IO.Path]::GetRelativePath
  • Loading branch information
danieljurek authored and azure-sdk committed Oct 13, 2021
1 parent 9946eda commit 5193e25
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions eng/common/scripts/Save-Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Verison property in that file.

[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[Parameter(Mandatory = $True)]
[string] $serviceDirectory,
[Parameter(Mandatory=$True)]
[Parameter(Mandatory = $True)]
[string] $outDirectory,
[switch] $addDevVersion
)
Expand All @@ -40,19 +40,16 @@ Param (
function SetOutput($outputPath, $incomingPackageSpec) {

# If there is an exsiting package info json file read that and set that as output object which gets properties updated here.
if (Test-Path $outputPath)
{
if (Test-Path $outputPath) {
Write-Host "Found existing package info json."
$outputObject = ConvertFrom-Json (Get-Content $outputPath -Raw)
}
else
{
else {
$outputObject = $incomingPackageSpec
}


if ($addDevVersion)
{
if ($addDevVersion) {
# Use the "Version" property which was provided by the incoming package spec
# as the DevVersion. This may be overridden later.
$outputObject.DevVersion = $incomingPackageSpec.Version
Expand All @@ -73,42 +70,44 @@ 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 "\\", '/'
return $relativePath
}

$allPackageProperties = Get-AllPkgProperties $serviceDirectory
if ($allPackageProperties)
{
if (-not (Test-Path -Path $outDirectory))
{
New-Item -ItemType Directory -Force -Path $outDirectory
}
foreach($pkg in $allPackageProperties)
{
if ($pkg.IsNewSdk)
{
Write-Host "Package Name: $($pkg.Name)"
Write-Host "Package Version: $($pkg.Version)"
Write-Host "Package SDK Type: $($pkg.SdkType)"
Write-Host "Artifact Name: $($pkg.ArtifactName)"
Write-Host "Release date: $($pkg.ReleaseStatus)"
$configFilePrefix = $pkg.Name
if ($pkg.ArtifactName)
{
$configFilePrefix = $pkg.ArtifactName
}
$outputPath = Join-Path -Path $outDirectory "$configFilePrefix.json"
SetOutput $outputPath $pkg
}
if ($allPackageProperties) {
if (-not (Test-Path -Path $outDirectory)) {
New-Item -ItemType Directory -Force -Path $outDirectory
}
foreach ($pkg in $allPackageProperties) {
if ($pkg.IsNewSdk) {
Write-Host "Package Name: $($pkg.Name)"
Write-Host "Package Version: $($pkg.Version)"
Write-Host "Package SDK Type: $($pkg.SdkType)"
Write-Host "Artifact Name: $($pkg.ArtifactName)"
Write-Host "Release date: $($pkg.ReleaseStatus)"
$configFilePrefix = $pkg.Name
if ($pkg.ArtifactName) {
$configFilePrefix = $pkg.ArtifactName
}
$outputPath = Join-Path -Path $outDirectory "$configFilePrefix.json"
SetOutput $outputPath $pkg
}
}

Get-ChildItem -Path $outDirectory
Get-ChildItem -Path $outDirectory
}
else
{
Write-Error "Package properties are not available for service directory $($serviceDirectory)"
exit 1
else {
Write-Error "Package properties are not available for service directory $($serviceDirectory)"
exit 1
}

0 comments on commit 5193e25

Please sign in to comment.