mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
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:
parent
ed6ae15500
commit
d6b37affd3
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user