aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-07-19 12:45:15 +0200
committerSantiago M. Mola <santi@mola.io>2017-07-19 14:48:42 +0200
commitf2e4b4d0b73f9ae1a53adc4479991bf651dfb99a (patch)
tree709fddd0ba300c2d766648506277b6fc07e65873 /plumbing/format
parentfdbdad58d6c4fbbc97a6f566f36436a0c7f64a5d (diff)
downloadgo-git-f2e4b4d0b73f9ae1a53adc4479991bf651dfb99a.tar.gz
packfile: check close error in UpdateObjectStorage
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/packfile/common.go22
1 files changed, 14 insertions, 8 deletions
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
+}