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>
This commit is contained in:
Manuel Rüger 2026-03-13 02:11:18 +01:00
parent ed6ae15500
commit d6b37affd3
2 changed files with 5 additions and 5 deletions

View File

@ -170,16 +170,16 @@ func ResolveLocalAttachments(opener vfs.Opener, base string, replacements []stri
return nil, err return nil, err
} }
for _, attachment := range attachments { for i := range attachments {
checksum, err := GetChecksum(bytes.NewReader(attachment.FileBytes)) checksum, err := GetChecksum(bytes.NewReader(attachments[i].FileBytes))
if err != nil { if err != nil {
return nil, karma.Format( return nil, karma.Format(
err, 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 return attachments, err
} }

View File

@ -27,7 +27,7 @@ type virtualOpener struct {
PathToBuf map[string]*bufferCloser 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 { if buf, ok := o.PathToBuf[name]; ok {
return buf, nil return buf, nil
} }