diff options
author | Santiago M. Mola <santi@mola.io> | 2017-07-19 12:59:16 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-07-19 14:48:46 +0200 |
commit | 87888eaab1caa52b6b073f610508e0f65b4141f6 (patch) | |
tree | 1ddaa824f7baa26350aa50607877d4bf9e207f13 /storage/filesystem/object.go | |
parent | ebc25df06ce7d11afe88339af7bb097926599b7d (diff) | |
download | go-git-87888eaab1caa52b6b073f610508e0f65b4141f6.tar.gz |
storage/filesystem: check all Close errors
Diffstat (limited to 'storage/filesystem/object.go')
-rw-r--r-- | storage/filesystem/object.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index dc88108..8bf84f2 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -11,6 +11,7 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/storer" "gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit" "gopkg.in/src-d/go-git.v4/storage/memory" + "gopkg.in/src-d/go-git.v4/utils/ioutil" "gopkg.in/src-d/go-billy.v3" ) @@ -53,10 +54,11 @@ func (s *ObjectStorage) loadIdxFile(h plumbing.Hash) error { if err != nil { return err } - defer idxfile.Close() + defer ioutil.CheckClose(idxfile, &err) s.index[h] = make(idx) - return s.index[h].Decode(idxfile) + err = s.index[h].Decode(idxfile) + return err } func (s *ObjectStorage) NewEncodedObject() plumbing.EncodedObject { @@ -94,14 +96,14 @@ func (s *ObjectStorage) SetEncodedObject(o plumbing.EncodedObject) (plumbing.Has return plumbing.ZeroHash, err } - defer ow.Close() + defer ioutil.CheckClose(ow, &err) or, err := o.Reader() if err != nil { return plumbing.ZeroHash, err } - defer or.Close() + defer ioutil.CheckClose(or, &err) if err := ow.WriteHeader(o.Type(), o.Size()); err != nil { return plumbing.ZeroHash, err @@ -111,7 +113,7 @@ func (s *ObjectStorage) SetEncodedObject(o plumbing.EncodedObject) (plumbing.Has return plumbing.ZeroHash, err } - return o.Hash(), nil + return o.Hash(), err } // EncodedObject returns the object with the given hash, by searching for it in @@ -143,7 +145,7 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb return nil, err } - defer f.Close() + defer ioutil.CheckClose(f, &err) obj = s.NewEncodedObject() r, err := objfile.NewReader(f) @@ -151,7 +153,7 @@ func (s *ObjectStorage) getFromUnpacked(h plumbing.Hash) (obj plumbing.EncodedOb return nil, err } - defer r.Close() + defer ioutil.CheckClose(r, &err) t, size, err := r.Header() if err != nil { @@ -186,7 +188,7 @@ func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.EncodedObject return nil, err } - defer f.Close() + defer ioutil.CheckClose(f, &err) p := packfile.NewScanner(f) d, err := packfile.NewDecoder(p, memory.NewStorage()) @@ -195,7 +197,8 @@ func (s *ObjectStorage) getFromPackfile(h plumbing.Hash) (plumbing.EncodedObject } d.SetOffsets(s.index[pack]) - return d.DecodeObjectAt(offset) + obj, err := d.DecodeObjectAt(offset) + return obj, err } func (s *ObjectStorage) findObjectInPackfile(h plumbing.Hash) (plumbing.Hash, int64) { |