diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-07-19 22:05:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-19 22:05:00 +0200 |
commit | 2d10f1023e609894174b21bdf8d3738010099335 (patch) | |
tree | 929b050b54039af69b4eae6306429feafa9d8268 /plumbing/format/packfile/scanner.go | |
parent | 8738a04708b91683d5804b4c648c871fdeb87f82 (diff) | |
parent | 87888eaab1caa52b6b073f610508e0f65b4141f6 (diff) | |
download | go-git-2d10f1023e609894174b21bdf8d3738010099335.tar.gz |
Merge pull request #491 from smola/error-checks
*: add more IO error checks
Diffstat (limited to 'plumbing/format/packfile/scanner.go')
-rw-r--r-- | plumbing/format/packfile/scanner.go | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/plumbing/format/packfile/scanner.go b/plumbing/format/packfile/scanner.go index 97512d1..1dab2f2 100644 --- a/plumbing/format/packfile/scanner.go +++ b/plumbing/format/packfile/scanner.go @@ -8,10 +8,11 @@ import ( "hash" "hash/crc32" "io" - "io/ioutil" + stdioutil "io/ioutil" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/utils/binary" + "gopkg.in/src-d/go-git.v4/utils/ioutil" ) var ( @@ -198,7 +199,7 @@ func (s *Scanner) discardObjectIfNeeded() error { } h := s.pendingObject - n, _, err := s.NextObject(ioutil.Discard) + n, _, err := s.NextObject(stdioutil.Discard) if err != nil { return err } @@ -275,8 +276,7 @@ func (s *Scanner) NextObject(w io.Writer) (written int64, crc32 uint32, err erro // ReadRegularObject reads and write a non-deltified object // from it zlib stream in an object entry in the packfile. -func (s *Scanner) copyObject(w io.Writer) (int64, error) { - var err error +func (s *Scanner) copyObject(w io.Writer) (n int64, err error) { if s.zr == nil { zr, err := zlib.NewReader(s.r) if err != nil { @@ -290,14 +290,9 @@ func (s *Scanner) copyObject(w io.Writer) (int64, error) { } } - defer func() { - closeErr := s.zr.Close() - if err == nil { - err = closeErr - } - }() - - return io.Copy(w, s.zr) + defer ioutil.CheckClose(s.zr, &err) + n, err = io.Copy(w, s.zr) + return } // SeekFromStart sets a new offset from start, returns the old position before @@ -329,7 +324,7 @@ func (s *Scanner) Checksum() (plumbing.Hash, error) { // Close reads the reader until io.EOF func (s *Scanner) Close() error { - _, err := io.Copy(ioutil.Discard, s.r) + _, err := io.Copy(stdioutil.Discard, s.r) return err } |