Skip to content

Commit

Permalink
Add -Force switch to Join-SubmissionPackage
Browse files Browse the repository at this point in the history
Currently, `Join-SubmissionPackage` prevents you from outputting
to a file that already exists. Now with the `-Force` switch, you
can overwrite the same file if you want to.

This was a user request for when they are chaining together multiple
`Join-SubmissionPackage` commands in a row, where the request is to
be able to use the same intermedia file as both the output for one
command, as well as the input (and then output again) of the next
command.
  • Loading branch information
HowardWolosky committed Feb 13, 2018
1 parent f053418 commit fb0764a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
38 changes: 28 additions & 10 deletions StoreBroker/PackageTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3255,6 +3255,9 @@ function Join-SubmissionPackage
If specified, the packages from AdditionalJsonPath will be merged with those in
MasterJsonPath
.PARAMETER Force
If specified, will overwrite the output files if they already exist.
.EXAMPLE
Join-SubmissionPackage c:\SBCallingRS1.json c:\SBCallingTH2.json c:\SBCallingMerged.json -AddPackages
Expand All @@ -3274,13 +3277,12 @@ function Join-SubmissionPackage
[string] $AdditionalJsonPath,

[Parameter(Mandatory=$true)]
[ValidateScript({if (Test-Path -Path $_ -PathType Leaf) { throw "$_ already exists. Choose a different name." } else { $true }})]
[string] $OutJsonPath,

[switch] $AddPackages
)
[switch] $AddPackages,

Add-Type -AssemblyName System.IO.Compression.FileSystem
[switch] $Force
)

# Fix the paths
$MasterJsonPath = Resolve-UnverifiedPath -Path $MasterJsonPath
Expand All @@ -3291,6 +3293,28 @@ function Join-SubmissionPackage
$additionalZipPath = Join-Path (Split-Path $AdditionalJsonPath -Parent) "$([System.IO.Path]::GetFileNameWithoutExtension($AdditionalJsonPath)).zip"
$outZipPath = Join-Path (Split-Path $OutJsonPath -Parent) "$([System.IO.Path]::GetFileNameWithoutExtension($OutJsonPath)).zip"

# It the user isn't using -Force, we need to ensure that the target json/zip files don't already exist.
if (-not $Force)
{
$errorMessage = "[{0}] already exists. Choose a different name, or specify the -Force switch to overwrite it."

if (Test-Path -Path $OutJsonPath -PathType Leaf)
{
$output = $errorMessage -f $OutJsonPath
Write-Log -Message $output -Level Error
throw $output
}

if (Test-Path -Path $outZipPath -PathType Leaf)
{
$output = $errorMessage -f $outZipPath
Write-Log -Message $output -Level Error
throw $output
}
}

Add-Type -AssemblyName System.IO.Compression.FileSystem

# Make sure that these zip files actually exist.
foreach ($zipFile in ($masterZipPath, $additionalZipPath))
{
Expand All @@ -3300,12 +3324,6 @@ function Join-SubmissionPackage
}
}

# Make sure that the output one *doesn't* exist
if (Test-Path -Path $outZipPath -PathType Leaf)
{
throw "[$outZipPath] already exists. Please choose a different name."
}

# Warn the user if they didn't specify anything to actually get merged in.
# At the moment, the only switch supported is AddPackages, but this may change over time.
if (-not $AddPackages)
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.15.0'
ModuleVersion = '1.15.1'
Description = 'Provides command-line access to the Windows Store Submission REST API.'

RootModule = 'StoreIngestionApi'
Expand Down

0 comments on commit fb0764a

Please sign in to comment.