From d6b37affd3cfdaef132ce898ac88df5817ccf4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 02:11:18 +0100 Subject: [PATCH] fix: use index-based loop in ResolveLocalAttachments to persist checksums The range loop 'for _, attachment := range attachments' copied each element by value. Assigning attachment.Checksum inside the loop only modified the local copy; the original slice element was never updated. All returned attachments had empty Checksum fields, causing every attachment to be treated as changed on every run (the checksum comparison would never match). Switch to an index-based loop so the checksum is written directly to the slice element. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- attachment/attachment.go | 8 ++++---- attachment/attachment_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/attachment/attachment.go b/attachment/attachment.go index ac4573e..cc6eadf 100644 --- a/attachment/attachment.go +++ b/attachment/attachment.go @@ -170,16 +170,16 @@ func ResolveLocalAttachments(opener vfs.Opener, base string, replacements []stri return nil, err } - for _, attachment := range attachments { - checksum, err := GetChecksum(bytes.NewReader(attachment.FileBytes)) + for i := range attachments { + checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes)) if err != nil { return nil, karma.Format( err, - "unable to get checksum for attachment: %q", attachment.Name, + "unable to get checksum for attachment: %q", attachments[i].Name, ) } - attachment.Checksum = checksum + attachments[i].Checksum = checksum } return attachments, err } diff --git a/attachment/attachment_test.go b/attachment/attachment_test.go index c3dc547..ac290dc 100644 --- a/attachment/attachment_test.go +++ b/attachment/attachment_test.go @@ -27,7 +27,7 @@ type virtualOpener struct { PathToBuf map[string]*bufferCloser } -func (o *virtualOpener) Open(name string) (io.ReadWriteCloser, error) { +func (o *virtualOpener) Open(name string) (io.ReadCloser, error) { if buf, ok := o.PathToBuf[name]; ok { return buf, nil }