Skip to content

Commit

Permalink
Support relative paths that don't begin with '.' to denote the curren…
Browse files Browse the repository at this point in the history
…t working directory.

For example, an -OutPath of "SomeFolder" should represent a sub-folder of the current working directory. While PowerShell can handle path fragments of this type, interacting with .NET methods, such as XmlDocument.Save() can cause the file to be saved to an unintended directory.

The fix is to use Resolve-UnverifiedPath in-order to resolve path fragments like this to a full path.

Additonally, adds a new function Ensure-Directory, to ensure a directory is created/exists.

Bump module version to 1.11.0
  • Loading branch information
Daniel Belcher committed Oct 13, 2017
1 parent a6fc80b commit 7378e93
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Extensions/ConvertFrom-ExistingIapSubmission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -601,5 +601,10 @@ function Main
}




# Script body
$OutPath = Resolve-UnverifiedPath -Path $OutPath

# function Main invocation
Main
Main
10 changes: 8 additions & 2 deletions Extensions/ConvertFrom-ExistingSubmission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,14 @@ function Ensure-PdpFilePath
[string] $FileName
)

$dropFolder = Join-Path $PdpRootPath $Lang
$dropFolder = Join-Path -Path $PdpRootPath -ChildPath $Lang

if (-not (Test-Path -PathType Container -Path $dropFolder))
{
New-Item -Force -ItemType Directory -Path $dropFolder | Out-Null
}

return (Join-Path $dropFolder $FileName)
return (Join-Path -Path $dropFolder -ChildPath $FileName)
}

function Show-ImageFileNames
Expand Down Expand Up @@ -1112,5 +1113,10 @@ function Main
}




# Script body
$OutPath = Resolve-UnverifiedPath -Path $OutPath

# function Main invocation
Main
41 changes: 41 additions & 0 deletions StoreBroker/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,44 @@ function Resolve-UnverifiedPath
return $resolvedPath.ProviderPath
}
}

function Ensure-Directory
{
<#
.SYNOPSIS
A utility function for ensuring a given directory exists.
.DESCRIPTION
A utility function for ensuring a given directory exists.
If the directory does not already exist, it will be created.
.PARAMETER Path
A full or relative path to the directory that should exist when the function exits.
.NOTES
Uses the Resolve-UnverifiedPath function to resolve relative paths.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $Path
)

try
{
$Path = Resolve-UnverifiedPath -Path $Path

if (-not (Test-Path -PathType Container -Path $Path))
{
Write-Log "Creating directory: [$Path]" -Level Verbose
New-Item -ItemType Directory -Path $Path | Out-Null
}
}
catch
{
Write-Log "Could not ensure directory: [$Path]" -Level Error

throw
}
}
20 changes: 10 additions & 10 deletions StoreBroker/PackageTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ function Write-SubmissionRequestBody

if ($PSCmdlet.ShouldProcess($OutFilePath, "Output to File"))
{
Ensure-Directory -Path (Split-Path -Parent -Path $OutFilePath)

Write-Log "Writing submission request JSON file: [$OutFilePath]." -Level Verbose

$JsonObject |
Expand Down Expand Up @@ -582,10 +584,10 @@ function Test-Xml
)

# Relative paths such as '.\File.txt' can resolve as 'C:\windows\System32\File.txt' when
# interacting with .NET libraries. Run [string] path parameters through 'Convert-Path' to
# interacting with .NET libraries. Run [string] path parameters through 'Resolve-UnverifiedPath' to
# get a full-path before using the path with any .NET libraries.
$XsdFile = Convert-Path -Path $XsdFile
$XmlFile = Convert-Path -Path $XmlFile
$XsdFile = Resolve-UnverifiedPath -Path $XsdFile
$XmlFile = Resolve-UnverifiedPath -Path $XmlFile

# The ValidationEventHandler runs in its own scope and does not have access to variables from
# Test-Xml. Make $validationErrors a script variable so capture exceptions in the
Expand Down Expand Up @@ -2336,7 +2338,7 @@ function Resolve-PackageParameters
if (-not [String]::IsNullOrWhiteSpace($ParamMap[$param]))
{
# Resolve path parameters to full paths. Necessary in case a path contains '.' or '..'
$ParamMap[$param] = Convert-Path -Path $ParamMap[$param]
$ParamMap[$param] = Resolve-UnverifiedPath -Path $ParamMap[$param]

if (-not (Test-Path -PathType Container -Path $ParamMap[$param]))
{
Expand Down Expand Up @@ -2385,7 +2387,7 @@ function Resolve-PackageParameters
}

# Resolve path parameters to full paths. Necessary in case a path contains '.' or '..'
$ParamMap[$script:s_OutPath] = Convert-Path -Path $ParamMap[$script:s_OutPath]
$ParamMap[$script:s_OutPath] = Resolve-UnverifiedPath -Path $ParamMap[$script:s_OutPath]
}


Expand Down Expand Up @@ -2506,7 +2508,7 @@ function Resolve-PackageParameters
}

# Resolve AppxPath to a list of full paths.
$ParamMap[$script:s_AppxPath] = $ParamMap[$script:s_AppxPath] | ForEach-Object { Convert-Path -Path $_ }
$ParamMap[$script:s_AppxPath] = $ParamMap[$script:s_AppxPath] | ForEach-Object { Resolve-UnverifiedPath -Path $_ }
}

if ($SkipValidation -inotcontains $script:s_DisableAutoPackageNameFormatting)
Expand Down Expand Up @@ -2662,8 +2664,8 @@ function Join-SubmissionPackage
Add-Type -AssemblyName System.IO.Compression.FileSystem

# Fix the paths
$MasterJsonPath = Convert-Path $MasterJsonPath
$AdditionalJsonPath = Convert-Path $AdditionalJsonPath
$MasterJsonPath = Resolve-UnverifiedPath -Path $MasterJsonPath
$AdditionalJsonPath = Resolve-UnverifiedPath -Path $AdditionalJsonPath

# Determine the paths to the zip files for these json files
$masterZipPath = Join-Path (Split-Path $MasterJsonPath -Parent) "$([System.IO.Path]::GetFileNameWithoutExtension($MasterJsonPath)).zip"
Expand Down Expand Up @@ -2907,7 +2909,6 @@ function New-SubmissionPackage
})]
[string[]] $AppxPath,

[ValidateScript({ if (Test-Path -PathType Container $_) { $true } else { throw "$_ cannot be found." } })]
[string] $OutPath,

[string] $OutName,
Expand Down Expand Up @@ -3135,7 +3136,6 @@ function New-InAppProductSubmissionPackage
[ValidateScript({ if (Test-Path -PathType Container $_) { $true } else { throw "$_ cannot be found." } })]
[string] $ImagesRootPath,

[ValidateScript({ if (Test-Path -PathType Container $_) { $true } else { throw "$_ cannot be found." } })]
[string] $OutPath,

[string] $OutName
Expand Down
2 changes: 1 addition & 1 deletion StoreBroker/StoreBroker.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CompanyName = 'Microsoft Corporation'
Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.'

ModuleVersion = '1.10.1'
ModuleVersion = '1.11.0'
Description = 'Provides command-line access to the Windows Store Submission REST API.'

RootModule = 'StoreIngestionApi'
Expand Down

0 comments on commit 7378e93

Please sign in to comment.