Skip to content

Commit

Permalink
Merge pull request #12 from alcortesm/hotfix-close-packfile
Browse files Browse the repository at this point in the history
missing call to Close on Fetch return value (ReadCloser)
  • Loading branch information
mcuadros committed Jan 11, 2016
2 parents cebec78 + 6d19be9 commit 37cc5cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions common_test.go
Expand Up @@ -15,6 +15,7 @@ func Test(t *testing.T) { TestingT(t) }

type MockGitUploadPackService struct {
Auth common.AuthMethod
RC io.ReadCloser
}

func (s *MockGitUploadPackService) Connect(url common.Endpoint) error {
Expand All @@ -40,8 +41,9 @@ func (s *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
}

func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadCloser, error) {
r, _ := os.Open("formats/packfile/fixtures/git-fixture.ref-delta")
return r, nil
var err error
s.RC, err = os.Open("formats/packfile/fixtures/git-fixture.ref-delta")
return s.RC, err
}

var fixtureRepos = [...]struct {
Expand Down
5 changes: 4 additions & 1 deletion repository.go
Expand Up @@ -53,7 +53,7 @@ func NewPlainRepository() *Repository {
}
}

func (r *Repository) Pull(remoteName, branch string) error {
func (r *Repository) Pull(remoteName, branch string) (err error) {
remote, ok := r.Remotes[remoteName]
if !ok {
return fmt.Errorf("unable to find remote %q", remoteName)
Expand All @@ -75,6 +75,9 @@ func (r *Repository) Pull(remoteName, branch string) error {
if err != nil {
return err
}
defer func() {
err = reader.Close()
}()

pr := packfile.NewReader(reader)
if _, err = pr.Read(r.Storage); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions repository_test.go
Expand Up @@ -31,6 +31,11 @@ func (s *SuiteRepository) TestPull(c *C) {

c.Assert(err, IsNil)
c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)

mock, ok := (r.Remotes["origin"].upSrv).(*MockGitUploadPackService)
c.Assert(ok, Equals, true)
err = mock.RC.Close()
c.Assert(err, Not(IsNil), Commentf("pull leaks an open fd from the fetch"))
}

func (s *SuiteRepository) TestCommit(c *C) {
Expand Down

0 comments on commit 37cc5cf

Please sign in to comment.