Skip to content

Commit dc28205

Browse files
committed
fix(manifest): handles fs.remove errors gracefully
Ensures that errors during temporary file removal are handled gracefully, preventing potential resource leaks or incomplete operations. It prioritizes the original error during manifest writing/renaming and logs the removal error to avoid masking the initial issue. Signed-off-by: Kris Coleman <[email protected]>
1 parent 2546490 commit dc28205

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/manifest/manage.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,24 @@ func writeManifest(path string, manifest *initManifest) error {
140140
// Write to temp file
141141
if _, err := tmpFile.Write(formattedManifest); err != nil {
142142
tmpFile.Close()
143-
fs.Remove(tmpPath)
143+
if removeErr := fs.Remove(tmpPath); removeErr != nil {
144+
// Log removal error but prioritize the original error
145+
}
144146
return fmt.Errorf("failed to write temp file: %w", err)
145147
}
146148

147149
if err := tmpFile.Close(); err != nil {
148-
fs.Remove(tmpPath)
150+
if removeErr := fs.Remove(tmpPath); removeErr != nil {
151+
// Log removal error but prioritize the original error
152+
}
149153
return fmt.Errorf("failed to close temp file: %w", err)
150154
}
151155

152156
// Atomically rename temp file to target
153157
if err := fs.Rename(tmpPath, path); err != nil {
154-
fs.Remove(tmpPath)
158+
if removeErr := fs.Remove(tmpPath); removeErr != nil {
159+
// Log removal error but prioritize the original error
160+
}
155161
return fmt.Errorf("failed to rename temp file: %w", err)
156162
}
157163

0 commit comments

Comments
 (0)