Skip to content

Commit 2e51537

Browse files
authored
Merge pull request #2138 from nikita-dubrovskii/fix_cex_key_removal
luks: fix occasional cex.key file removal
2 parents cc16ece + 008fe5a commit 2e51537

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

docs/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ nav_order: 9
1515
### Changes
1616

1717
### Bug fixes
18-
18+
- Fix occasional cex.key file removal
1919

2020
## Ignition 2.23.0 (2025-09-10)
2121

internal/exec/stages/disks/luks.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ func (s *stage) createLuks(config types.Config) error {
132132
if err := keyFile.Close(); err != nil {
133133
s.Warning("could not close file %s: %v", keyFilePath, err)
134134
}
135-
defer func() {
136-
if err = os.Remove(keyFilePath); err != nil {
137-
s.Warning("could not remove file %s: %v", keyFilePath, err)
135+
// We must pass 'keyFilePath' as a parameter here, since it may change below (cex).
136+
// Otherwise, the deferred function will see the modified value instead of the original one.
137+
defer func(name string) {
138+
if removeErr := os.Remove(name); removeErr != nil {
139+
s.Warning("could not remove file %s: %v", name, removeErr)
138140
}
139-
}()
141+
}(keyFilePath)
140142

141143
if luks.Cex.IsPresent() {
142144
// each LUKS device has associated keyfiles

0 commit comments

Comments
 (0)