From f2e4b4d0b73f9ae1a53adc4479991bf651dfb99a Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Wed, 19 Jul 2017 12:45:15 +0200 Subject: packfile: check close error in UpdateObjectStorage --- plumbing/format/packfile/common.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'plumbing/format') diff --git a/plumbing/format/packfile/common.go b/plumbing/format/packfile/common.go index 6402cd0..728cb16 100644 --- a/plumbing/format/packfile/common.go +++ b/plumbing/format/packfile/common.go @@ -4,6 +4,7 @@ import ( "io" "gopkg.in/src-d/go-git.v4/plumbing/storer" + "gopkg.in/src-d/go-git.v4/utils/ioutil" ) var signature = []byte{'P', 'A', 'C', 'K'} @@ -24,14 +25,7 @@ const ( // packfile. func UpdateObjectStorage(s storer.EncodedObjectStorer, packfile io.Reader) error { if sw, ok := s.(storer.PackfileWriter); ok { - w, err := sw.PackfileWriter() - if err != nil { - return err - } - - defer w.Close() - _, err = io.Copy(w, packfile) - return err + return writePackfileToObjectStorage(sw, packfile) } stream := NewScanner(packfile) @@ -43,3 +37,15 @@ func UpdateObjectStorage(s storer.EncodedObjectStorer, packfile io.Reader) error _, err = d.Decode() return err } + +func writePackfileToObjectStorage(sw storer.PackfileWriter, packfile io.Reader) error { + var err error + w, err := sw.PackfileWriter() + if err != nil { + return err + } + + defer ioutil.CheckClose(w, &err) + _, err = io.Copy(w, packfile) + return err +} -- cgit