Skip temporary cleanup when no config file was staged

This commit is contained in:
Dandaedre 2026-10-19 13:51:30 +02:00
parent 537d581edd
commit c85679e86c
3 changed files with 23 additions and 1 deletions

View File

@ -129,3 +129,4 @@ open until it is run on disposable machines with the required account setups.
- [x] Make web config updates force replacement with backups by default, with an explicit opt-out.
- [x] Apply the force-by-default policy during install/bootstrap too, with a preserve-local-configs opt-out.
- [x] Replace bootstrap exit-code exceptions with friendly partial-success, reboot, and busy summaries while preserving automation status.
- [x] Avoid null temporary-file cleanup after registry deployment or config adoption; preserve original per-item errors.

View File

@ -268,7 +268,7 @@ function Invoke-ConfigOperation {
catch {
return [pscustomobject]@{ name = $Operation.name; status = 'Failed'; message = $_.Exception.Message }
}
finally { Remove-Item -LiteralPath $temporary -Force -ErrorAction SilentlyContinue }
finally { if ($temporary) { Remove-Item -LiteralPath $temporary -Force -ErrorAction SilentlyContinue } }
}
function Restore-ConfigBackup {

View File

@ -99,6 +99,27 @@ Describe 'Configuration deployment' {
(Get-Content "$output/capture.json" -Raw | ConvertFrom-Json).repositoryRevision | Should -Be 'abc123'
}
It 'adopts matching values without trying to clean up a nonexistent temporary file' {
$operation = [pscustomobject]@{
name = 'adopted'; action = 'Adopt'; mode = 'ini-overlay'
target = $destination; sourceHash = 'matching'
}
$result = Invoke-ConfigOperation -Operation $operation -Paths $paths -State $state
$result.status | Should -Be 'Succeeded'
$state.configs.adopted.sourceHash | Should -Be 'matching'
}
It 'keeps the original registry failure when no temporary file was created' {
Mock Get-RegistrySnapshot { throw 'Registry access denied' } -ModuleName Configs
$operation = [pscustomobject]@{
name = 'registry-test'; action = 'Update'; mode = 'registry'
target = 'HKCU:\Software\Test'; sourceHash = 'new'; desired = @{ values = @() }
}
$result = Invoke-ConfigOperation -Operation $operation -Paths $paths -State $state
$result.status | Should -Be 'Failed'
$result.message | Should -Be 'Registry access denied'
}
It 'refuses unsafe automatic restoration of registry and hosts backups' {
$registryState = @{ configs = @{ 'mpc-hc-settings' = @{ mode = 'registry'; target = 'HKCU:\Software\MPC-HC\MPC-HC' } } }
{ Restore-ConfigBackup -Name mpc-hc-settings -Paths $paths -State $registryState } | Should -Throw '*not supported for registry*'