From c85679e86cac9a25ff72416de3ca0c496ab2464b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 13:51:30 +0200 Subject: [PATCH] Skip temporary cleanup when no config file was staged --- TASKS.md | 1 + src/Configs.psm1 | 2 +- tests/Configs.Tests.ps1 | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/TASKS.md b/TASKS.md index ae13ea9..4d89bb7 100644 --- a/TASKS.md +++ b/TASKS.md @@ -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. diff --git a/src/Configs.psm1 b/src/Configs.psm1 index a851fac..80b9c2b 100644 --- a/src/Configs.psm1 +++ b/src/Configs.psm1 @@ -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 { diff --git a/tests/Configs.Tests.ps1 b/tests/Configs.Tests.ps1 index f76e756..8c92f3e 100644 --- a/tests/Configs.Tests.ps1 +++ b/tests/Configs.Tests.ps1 @@ -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*'