Skip to content

Commit

Permalink
a/b testing if inline closes not defers fixes windows tests
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 e56681c commit 193254c
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/pkg/layout/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ func splitFile(srcPath string, chunkSize int) (err error) {
if err != nil {
return err
}
defer func() {
err2 := srcFile.Close()
err = errors.Join(err, err2)
}()

fi, err := srcFile.Stat()
if err != nil {
return err
Expand All @@ -50,10 +45,10 @@ func splitFile(srcPath string, chunkSize int) (err error) {
if err != nil {
return err
}
defer func(dstFile *os.File) {
err2 := dstFile.Close()
err = errors.Join(err, err2)
}(dstFile)
// defer func(dstFile *os.File) {
// err2 := dstFile.Close()
// err = errors.Join(err, err2)
// }(dstFile)

written, copyErr := io.CopyN(dstFile, srcFile, int64(chunkSize))
if copyErr != nil && !errors.Is(copyErr, io.EOF) {
Expand All @@ -72,6 +67,12 @@ func splitFile(srcPath string, chunkSize int) (err error) {
return err
}

// Does inline close fix windows?
err = dstFile.Close()
if err != nil {
return err
}

// EOF error could be returned on 0 bytes written.
if written == 0 {
err = os.Remove(path)
Expand All @@ -87,7 +88,11 @@ func splitFile(srcPath string, chunkSize int) (err error) {
}
}

// Done, lets cleanup the src
// Remove original file
err = srcFile.Close()
if err != nil {
return err
}
err = os.Remove(srcPath)
if err != nil {
return err
Expand Down

0 comments on commit 193254c

Please sign in to comment.