diff options
author | Miguel Molina <miguel@erizocosmi.co> | 2018-08-09 12:36:37 +0200 |
---|---|---|
committer | Miguel Molina <miguel@erizocosmi.co> | 2018-08-09 12:36:37 +0200 |
commit | 038cf238e6250094c7aeb387fd7ea92438719699 (patch) | |
tree | 2d2f4a1cbfecd4e5c70b49540390374cadd248f8 | |
parent | 65dc4f9f192cc013e4765fb1162ce6ebda16573d (diff) | |
download | go-git-038cf238e6250094c7aeb387fd7ea92438719699.tar.gz |
storage: filesystem, close Packfile after iterating objects
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
-rw-r--r-- | plumbing/object/blob_test.go | 7 | ||||
-rw-r--r-- | storage/filesystem/object.go | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/plumbing/object/blob_test.go b/plumbing/object/blob_test.go index 181436d..e08ff25 100644 --- a/plumbing/object/blob_test.go +++ b/plumbing/object/blob_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/format/packfile" . "gopkg.in/check.v1" ) @@ -70,6 +71,12 @@ func (s *BlobsSuite) TestBlobIter(c *C) { blobs := []*Blob{} iter.ForEach(func(b *Blob) error { + var err error + b.obj, err = packfile.MemoryObjectFromDisk(b.obj) + if err != nil { + return err + } + blobs = append(blobs, b) return nil }) diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index 4757938..86d0da9 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -457,12 +457,14 @@ func (it *lazyPackfilesIter) Close() { } type packfileIter struct { + pack billy.File iter storer.EncodedObjectIter seen map[plumbing.Hash]struct{} } // NewPackfileIter returns a new EncodedObjectIter for the provided packfile -// and object type. +// and object type. Packfile and index file will be closed after they're +// used. func NewPackfileIter( f billy.File, idxFile billy.File, @@ -473,6 +475,10 @@ func NewPackfileIter( return nil, err } + if err := idxFile.Close(); err != nil { + return nil, err + } + return newPackfileIter(f, t, make(map[plumbing.Hash]struct{}), idx, nil) } @@ -489,6 +495,7 @@ func newPackfileIter( } return &packfileIter{ + pack: f, iter: iter, seen: seen, }, nil @@ -514,6 +521,7 @@ func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error { o, err := iter.Next() if err != nil { if err == io.EOF { + iter.Close() return nil } return err @@ -527,6 +535,7 @@ func (iter *packfileIter) ForEach(cb func(plumbing.EncodedObject) error) error { func (iter *packfileIter) Close() { iter.iter.Close() + _ = iter.pack.Close() } type objectsIter struct { |