Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Fix file closing
  • Loading branch information
myitcv committed May 4, 2018
commit 41c38df9de9cbee94e3cf402b9b13585722cd804
5 changes: 3 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,10 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
if err != nil {
return nil, fmt.Errorf("could not open %v: %v", binPath, err)
}
defer binFile.Close()

binHash := sha256.New()
io.Copy(binHash, binFile)
binFile.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually (*File).Close doesn't usually cause error (if error happens, this is a critical error), but checking error is not bad here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree; if that fails we're in serious trouble. I think I'll leave this.

fmt.Fprintf(pkgHash, "gopherjs bin: %#x\n", binHash.Sum(nil))

orderedBuildTags := append([]string{}, s.options.BuildTags...)
Expand Down Expand Up @@ -656,6 +656,7 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
}
fmt.Fprintf(pkgHash, "file: %v\n", fp)
n, _ := io.Copy(pkgHash, file)
file.Close()
fmt.Fprintf(pkgHash, "%d bytes\n", n)
}

Expand All @@ -671,9 +672,9 @@ func (s *Session) BuildPackage(pkg *PackageData) (*compiler.Archive, error) {
}
return nil, err
}
defer objFile.Close()

archive, err := compiler.ReadArchive(pkg.PkgObj, pkg.ImportPath, objFile, s.Types)
objFile.Close()
if err != nil {
return nil, err
}
Expand Down