diff options
Diffstat (limited to 'storage/filesystem')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 16 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit_test.go | 1 |
2 files changed, 11 insertions, 6 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index 9bbf4e8..e2ff51b 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -348,7 +348,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e return err } - defer ioutil.CheckClose(f, &err) // Creating the temp file in the same directory as the target file // improves our chances for rename operation to be atomic. @@ -357,10 +356,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e return err } - tmpPath := tmp.Name() - defer ioutil.CheckClose(tmp, &err) - defer d.fs.Remove(tmpPath) - s := bufio.NewScanner(f) found := false for s.Scan() { @@ -388,7 +383,16 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e return nil } - return d.fs.Rename(tmpPath, packedRefsPath) + if err := f.Close(); err != nil { + ioutil.CheckClose(tmp, &err) + return err + } + + if err := tmp.Close(); err != nil { + return err + } + + return d.fs.Rename(tmp.Name(), packedRefsPath) } // process lines from a packed-refs file diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go index d4cda0e..d935ec5 100644 --- a/storage/filesystem/internal/dotgit/dotgit_test.go +++ b/storage/filesystem/internal/dotgit/dotgit_test.go @@ -373,6 +373,7 @@ func (s *SuiteDotGit) TestObjectPackIdx(c *C) { idx, err := dir.ObjectPackIdx(f.PackfileHash) c.Assert(err, IsNil) c.Assert(filepath.Ext(idx.Name()), Equals, ".idx") + c.Assert(idx.Close(), IsNil) } func (s *SuiteDotGit) TestObjectPackNotFound(c *C) { |