From bcaede84719f0fd36b944a1b4f78e7ecc1ba10fe Mon Sep 17 00:00:00 2001 From: Yuichi Watanabe Date: Fri, 17 May 2019 13:58:30 +0900 Subject: storage/filesystem: dotgit, Reproduce packfile parse error. Fixes #1149 Signed-off-by: Yuichi Watanabe --- storage/filesystem/dotgit/dotgit_test.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'storage/filesystem/dotgit') diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go index 73b0291..4cda2f9 100644 --- a/storage/filesystem/dotgit/dotgit_test.go +++ b/storage/filesystem/dotgit/dotgit_test.go @@ -463,6 +463,11 @@ func testObjectPacks(c *C, fs billy.Filesystem, dir *DotGit, f *fixtures.Fixture c.Assert(err, IsNil) err = badFile.Close() c.Assert(err, IsNil) + // temporary file generated by git gc + tmpFile, err := fs.Create("objects/pack/.tmp-11111-pack-58rf8y4wm1b1k52bpe0kdlx6lpreg6ahso8n3ylc.pack") + c.Assert(err, IsNil) + err = tmpFile.Close() + c.Assert(err, IsNil) hashes2, err := dir.ObjectPacks() c.Assert(err, IsNil) -- cgit From 1da0bac9d6e7142b46f1fb9ff007cbc90ca9af97 Mon Sep 17 00:00:00 2001 From: Yuichi Watanabe Date: Fri, 17 May 2019 14:13:34 +0900 Subject: storage/filesystem: dotgit, Add prefix check to packfile name. Fixes #1149 Signed-off-by: Yuichi Watanabe --- storage/filesystem/dotgit/dotgit.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'storage/filesystem/dotgit') diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go index 111769b..d80d420 100644 --- a/storage/filesystem/dotgit/dotgit.go +++ b/storage/filesystem/dotgit/dotgit.go @@ -33,8 +33,9 @@ const ( tmpPackedRefsPrefix = "._packed-refs" - packExt = ".pack" - idxExt = ".idx" + packPrefix = "pack-" + packExt = ".pack" + idxExt = ".idx" ) var ( @@ -224,11 +225,11 @@ func (d *DotGit) objectPacks() ([]plumbing.Hash, error) { var packs []plumbing.Hash for _, f := range files { - if !strings.HasSuffix(f.Name(), packExt) { + n := f.Name() + if !strings.HasPrefix(n, packPrefix) || !strings.HasSuffix(n, packExt) { continue } - n := f.Name() h := plumbing.NewHash(n[5 : len(n)-5]) //pack-(hash).pack if h.IsZero() { // Ignore files with badly-formatted names. -- cgit From 51320886176abed6647d2d7bab5bd6df17c4d44f Mon Sep 17 00:00:00 2001 From: Yuichi Watanabe Date: Fri, 17 May 2019 14:25:55 +0900 Subject: storage/filesystem: dotgit, Change the order of checking packfile name prefix and suffix. Fixes #1149 Signed-off-by: Yuichi Watanabe --- storage/filesystem/dotgit/dotgit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'storage/filesystem/dotgit') diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go index d80d420..7989e53 100644 --- a/storage/filesystem/dotgit/dotgit.go +++ b/storage/filesystem/dotgit/dotgit.go @@ -226,7 +226,7 @@ func (d *DotGit) objectPacks() ([]plumbing.Hash, error) { var packs []plumbing.Hash for _, f := range files { n := f.Name() - if !strings.HasPrefix(n, packPrefix) || !strings.HasSuffix(n, packExt) { + if !strings.HasSuffix(n, packExt) || !strings.HasPrefix(n, packPrefix) { continue } -- cgit