This commit is contained in:
Ahrav Dutta
2024-04-23 14:40:02 -07:00
parent 8c8b3028c8
commit 59a518edd7
+15 -1
View File
@@ -101,7 +101,21 @@ func (d *Diff) write(p []byte) error {
// handle the final flush in the finalize method, in case there's data remaining in the buffer.
// This method should be called to release resources, especially when writing to a file.
func (d *Diff) finalize() error {
return d.contentWriter.CloseForWriting()
if err := d.contentWriter.CloseForWriting(); err != nil {
return fmt.Errorf("failed to finalize diff: %w", err)
}
if !d.IsBinary {
return nil
}
// If the diff is binary, the contentWriter will NOT contain any diff content.
// We should close it to release resources.
rdr, err := d.ReadCloser()
if err != nil {
return fmt.Errorf("failed to finalize diff: %w", err)
}
return rdr.Close()
}
// Commit contains commit header info and diffs.