Skip to content

Commit 1235f18

Browse files
committed
Ensure hidden backup files are deleted after a config apply is done
1 parent fb4afba commit 1235f18

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/file/file_manager_service.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,20 @@ func (fms *FileManagerService) ConfigApply(ctx context.Context,
197197
}
198198

199199
func (fms *FileManagerService) ClearCache() {
200-
slog.Debug("Clearing cache and temp files")
200+
slog.Debug("Clearing cache and backup files")
201+
202+
for _, fileAction := range fms.fileActions {
203+
if fileAction.Action == model.Update || fileAction.Action == model.Delete {
204+
tempFilePath := tempBackupFilePath(fileAction.File.GetFileMeta().GetName())
205+
if err := os.Remove(tempFilePath); err != nil && !os.IsNotExist(err) {
206+
slog.Warn("Unable to delete backup file",
207+
"file", fileAction.File.GetFileMeta().GetName(),
208+
"error", err,
209+
)
210+
}
211+
}
212+
}
213+
201214
clear(fms.fileActions)
202215
clear(fms.previousManifestFiles)
203216
}

0 commit comments

Comments
 (0)