From 3c7ba0e2a49409b57c2e9d3fcd0a68bb8f703554 Mon Sep 17 00:00:00 2001 From: "Rodweil, Theodor" Date: Sun, 30 Jul 2023 20:20:49 +0200 Subject: [PATCH] fix(manifest): allow for non cwd backups - fix a fault where the backup file was only generated within the current directory - fix a fault in Pester tests, where the parameter was wrongly used as the script block for assertion. --- PSConfluencePublisher/Manifest.Tests.ps1 | 14 +++++++------- PSConfluencePublisher/Manifest.psm1 | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/PSConfluencePublisher/Manifest.Tests.ps1 b/PSConfluencePublisher/Manifest.Tests.ps1 index 55f1760..ab54fc9 100755 --- a/PSConfluencePublisher/Manifest.Tests.ps1 +++ b/PSConfluencePublisher/Manifest.Tests.ps1 @@ -108,12 +108,12 @@ Describe 'Set-Manifest' ` Mock Copy-Item { #FIXME: the scope is completely wrong - Should -Invoke -CommandName 'Copy-Item' -Exactly -Times 1 + Should -Invoke -CommandName 'Copy-Item' -Exactly -Times 1 ` - $args[1] | Should -Be 'foobar.x' + $Path | Should -Be 'foobar.x' - $args[3] | Should -Be 'foobar.x.bck' - } + $Destination | Should -Be 'foobar.x.bck' + } #mocking Get-Content, therefore file name can be bogus Set-Manifest ` @@ -139,11 +139,11 @@ Describe 'Set-Manifest' ` Mock Copy-Item { #FIXME: the scope is completely wrong - Should -Invoke -CommandName 'Copy-Item' -Exactly -Times 1 + Should -Invoke -CommandName 'Copy-Item' -Exactly -Times 1 ` - $args[1] | Should -Be 'foo/bar/foobar.x' + $Path | Should -Be 'foo/bar/foobar.x' - $args[3] | Should -Be 'foo/bar/foobar.x.bck' + $Destination | Should -Be 'foo/bar/foobar.x.bck' } #mocking Get-Content, therefore file name can be bogus diff --git a/PSConfluencePublisher/Manifest.psm1 b/PSConfluencePublisher/Manifest.psm1 index e69339f..7fa0a22 100755 --- a/PSConfluencePublisher/Manifest.psm1 +++ b/PSConfluencePublisher/Manifest.psm1 @@ -68,8 +68,22 @@ function Set-Manifest if ($Backup) { - #FIXME: this always assumes the current working directory - Copy-Item -Path $File -Destination "$(Split-Path -Leaf $File).bck" + $baseDir = Split-Path $File + + $baseName = "$(Split-Path -Leaf $File).bck" + + #FIXME: this should be handled without an explicit condition + if ($baseDir) + { + $path = Join-Path $baseDir $baseName + } + + else + { + $path = $baseName + } + + Copy-Item -Path $File -Destination $path } Set-Content -Path $File -Value $raw