From 193254cfc442c2a5c4be92b651760dde47369358 Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Tue, 1 Oct 2024 11:29:54 -0700 Subject: [PATCH] a/b testing if inline closes not defers fixes windows tests Signed-off-by: Kit Patella --- src/pkg/layout/split.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/pkg/layout/split.go b/src/pkg/layout/split.go index fc0a6520e5..16423a8a3a 100644 --- a/src/pkg/layout/split.go +++ b/src/pkg/layout/split.go @@ -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 @@ -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) { @@ -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) @@ -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