aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-19 22:05:00 +0200
committerGitHub <noreply@github.com>2017-07-19 22:05:00 +0200
commit2d10f1023e609894174b21bdf8d3738010099335 (patch)
tree929b050b54039af69b4eae6306429feafa9d8268 /storage/filesystem/internal
parent8738a04708b91683d5804b4c648c871fdeb87f82 (diff)
parent87888eaab1caa52b6b073f610508e0f65b4141f6 (diff)
downloadgo-git-2d10f1023e609894174b21bdf8d3738010099335.tar.gz
Merge pull request #491 from smola/error-checks
*: add more IO error checks
Diffstat (limited to 'storage/filesystem/internal')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go8
-rw-r--r--storage/filesystem/internal/dotgit/writers_test.go28
2 files changed, 30 insertions, 6 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index b672d4b..e2ff51b 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -253,10 +253,10 @@ func (d *DotGit) SetRef(r *plumbing.Reference) error {
return err
}
- if _, err := f.Write([]byte(content)); err != nil {
- return err
- }
- return f.Close()
+ defer ioutil.CheckClose(f, &err)
+
+ _, err = f.Write([]byte(content))
+ return err
}
// Refs scans the git directory collecting references, which it returns.
diff --git a/storage/filesystem/internal/dotgit/writers_test.go b/storage/filesystem/internal/dotgit/writers_test.go
index d2c7b6f..1342396 100644
--- a/storage/filesystem/internal/dotgit/writers_test.go
+++ b/storage/filesystem/internal/dotgit/writers_test.go
@@ -12,6 +12,7 @@ import (
. "gopkg.in/check.v1"
"gopkg.in/src-d/go-billy.v3/osfs"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
)
func (s *SuiteDotGit) TestNewObjectPack(c *C) {
@@ -35,13 +36,30 @@ func (s *SuiteDotGit) TestNewObjectPack(c *C) {
c.Assert(w.Close(), IsNil)
- stat, err := fs.Stat(fmt.Sprintf("objects/pack/pack-%s.pack", f.PackfileHash))
+ pfPath := fmt.Sprintf("objects/pack/pack-%s.pack", f.PackfileHash)
+ idxPath := fmt.Sprintf("objects/pack/pack-%s.idx", f.PackfileHash)
+
+ stat, err := fs.Stat(pfPath)
c.Assert(err, IsNil)
c.Assert(stat.Size(), Equals, int64(84794))
- stat, err = fs.Stat(fmt.Sprintf("objects/pack/pack-%s.idx", f.PackfileHash))
+ stat, err = fs.Stat(idxPath)
c.Assert(err, IsNil)
c.Assert(stat.Size(), Equals, int64(1940))
+
+ pf, err := fs.Open(pfPath)
+ c.Assert(err, IsNil)
+ pfs := packfile.NewScanner(pf)
+ _, objects, err := pfs.Header()
+ c.Assert(err, IsNil)
+ for i := uint32(0); i < objects; i++ {
+ _, err := pfs.NextObjectHeader()
+ if err != nil {
+ c.Assert(err, IsNil)
+ break
+ }
+ }
+ c.Assert(pfs.Close(), IsNil)
}
func (s *SuiteDotGit) TestNewObjectPackUnused(c *C) {
@@ -63,6 +81,12 @@ func (s *SuiteDotGit) TestNewObjectPackUnused(c *C) {
info, err := fs.ReadDir("objects/pack")
c.Assert(err, IsNil)
c.Assert(info, HasLen, 0)
+
+ // check clean up of temporary files
+ info, err = fs.ReadDir("")
+ for _, fi := range info {
+ c.Assert(fi.IsDir(), Equals, true)
+ }
}
func (s *SuiteDotGit) TestSyncedReader(c *C) {