Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions public/Test-DbaLastBackup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ function Test-DbaLastBackup {
if ($DataDirectory) {
if (-not (Test-DbaPath -SqlInstance $destserver -Path $DataDirectory)) {
$serviceAccount = $destserver.ServiceAccount
Stop-Function -Message "Can't access $DataDirectory Please check if $serviceAccount has permissions." -Continue
# No -Continue here: unlike the twin check in the per-instance loop below, no loop
# encloses this call, so the continue would escape the command and eat an iteration
# of whatever loop the caller runs in.
Stop-Function -Message "Can't access $DataDirectory Please check if $serviceAccount has permissions."
return
}
$effectiveDataDirectory = $DataDirectory
} else {
Expand All @@ -379,7 +383,9 @@ function Test-DbaLastBackup {
if ($LogDirectory) {
if (-not (Test-DbaPath -SqlInstance $destserver -Path $LogDirectory)) {
$serviceAccount = $destserver.ServiceAccount
Stop-Function -Message "$Destination can't access its local directory $LogDirectory. Please check if $serviceAccount has permissions." -Continue
# No -Continue here either, see above.
Stop-Function -Message "$Destination can't access its local directory $LogDirectory. Please check if $serviceAccount has permissions."
return
}
$effectiveLogDirectory = $LogDirectory
} else {
Expand Down
21 changes: 21 additions & 0 deletions tests/Test-DbaLastBackup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,27 @@ Describe $CommandName -Tag IntegrationTests {
}
}

Context "Test -Path with an inaccessible DataDirectory" {
It "Warns without eating an iteration of the caller's loop" {
# The inaccessible-directory checks used to run Stop-Function -Continue without an
# enclosing loop - the continue escaped the command and consumed an iteration of this
# very loop, so the counter fell short (#10638).
$splatInaccessible = @{
Path = $backupPath
Destination = $TestConfig.InstanceSingle
DataDirectory = "Q:\dbatoolsci\does\not\exist"
WarningAction = "SilentlyContinue"
}
$loopCount = 0
foreach ($i in 1..3) {
$null = Test-DbaLastBackup @splatInaccessible
$loopCount++
}
$loopCount | Should -Be 3
$WarnVar | Should -BeLike "*Can't access*"
}
}

Context "Test a single database" {
BeforeAll {
$singleDbResults = Test-DbaLastBackup -SqlInstance $TestConfig.InstanceSingle -Database $testlastbackup
Expand Down