Skip to content

Commit 9271a46

Browse files
o-l-a-valerickson
authored andcommitted
Attempt fix save script without -includexml (#1609) (#1614)
1 parent 0826839 commit 9271a46

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/code/InstallHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,10 @@ private void MoveFilesIntoInstallPath(
522522
}
523523
}
524524
else {
525-
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML)));
526-
Utils.MoveFiles(Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML));
525+
if (_includeXml) {
526+
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML)));
527+
Utils.MoveFiles(Path.Combine(dirNameVersion, scriptXML), Path.Combine(installPath, scriptXML));
528+
}
527529
}
528530

529531
_cmdletPassedIn.WriteVerbose(string.Format("Moving '{0}' to '{1}'", scriptPath, Path.Combine(finalModuleVersionDir, pkgInfo.Name + PSScriptFileExt)));

test/SavePSResourceTests/SavePSResourceV2Tests.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' {
125125
$pkgDirVersion.Name | Should -Be "5.2.5"
126126
}
127127

128-
It "Save a module with a dependency" {
128+
It "Save a module with a dependency" {
129129
Save-PSResource -Name "TestModuleWithDependencyE" -Version "1.0.0.0" -Repository $PSGalleryName -Path $SaveDir -TrustRepository
130130
$pkgDirs = Get-ChildItem -Path $SaveDir | Where-Object { $_.Name -eq "TestModuleWithDependencyE" -or $_.Name -eq "TestModuleWithDependencyC" -or $_.Name -eq "TestModuleWithDependencyB" -or $_.Name -eq "TestModuleWithDependencyD"}
131131
$pkgDirs.Count | Should -BeGreaterThan 1
@@ -148,7 +148,7 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' {
148148
Find-PSResource -Name $testModuleName -Version "5.2.5-alpha001" -Repository $PSGalleryName | Save-PSResource -Path $SaveDir -TrustRepository -Verbose
149149
$pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName
150150
$pkgDir | Should -Not -BeNullOrEmpty
151-
(Get-ChildItem -Path $pkgDir.FullName) | Should -HaveCount 1
151+
(Get-ChildItem -Path $pkgDir.FullName) | Should -HaveCount 1
152152
}
153153

154154
It "Save module as a nupkg" {
@@ -173,10 +173,17 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' {
173173
$res.Version | Should -Be "1.0.0.0"
174174
}
175175

176+
It "Save script without using -IncludeXML" {
177+
Save-PSResource -Name $testScriptName -Repository $PSGalleryName -Path $SaveDir -TrustRepository | Should -Not -Throw
178+
179+
$SavedScriptFile = Join-Path -Path $SaveDir -ChildPath "$testScriptName.ps1"
180+
Test-Path -Path $SavedScriptFile -PathType 'Leaf' | Should -BeTrue
181+
}
182+
176183
It "Save script using -IncludeXML" {
177-
Save-PSResource -Name $testScriptName -Repository $PSGalleryName -Path $SaveDir -TrustRepository
184+
Save-PSResource -Name $testScriptName -Repository $PSGalleryName -Path $SaveDir -TrustRepository -IncludeXml
178185

179-
$scriptXML = $testScriptNamen + "_InstalledScriptInfo.xml"
186+
$scriptXML = $testScriptName + "_InstalledScriptInfo.xml"
180187
$savedScriptFile = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "test_script.ps1"
181188
$savedScriptXML = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $scriptXML
182189
$savedScriptFile | Should -Not -BeNullOrEmpty
@@ -192,4 +199,4 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' {
192199
$err.Count | Should -BeGreaterThan 0
193200
$err[0].FullyQualifiedErrorId | Should -BeExactly "InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource"
194201
}
195-
}
202+
}

0 commit comments

Comments
 (0)