Skip to content

Commit

Permalink
fix: if the file is already closed, don't join to err return
Browse files Browse the repository at this point in the history
Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Oct 1, 2024
1 parent df0d3b4 commit 2afa430
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pkg/layout/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ func splitFile(srcPath string, chunkSize int) (err error) {
// Ensure we close our sourcefile, even if we error out.
defer func() {
err2 := srcFile.Close()
err = errors.Join(err, err2)
// Ignore if file is already closed
if !errors.Is(err2, os.ErrClosed) {
err = errors.Join(err, err2)
}
}()

fi, err := srcFile.Stat()
Expand All @@ -53,7 +56,10 @@ func splitFile(srcPath string, chunkSize int) (err error) {
}
defer func(dstFile *os.File) {
err2 := dstFile.Close()
err = errors.Join(err, err2)
// Ignore if file is already closed
if !errors.Is(err2, os.ErrClosed) {
err = errors.Join(err, err2)
}
}(dstFile)

written, copyErr := io.CopyN(dstFile, srcFile, int64(chunkSize))
Expand Down

0 comments on commit 2afa430

Please sign in to comment.