aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/packfile.go
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-08-01 09:07:47 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-08-01 11:07:34 +0200
commitb173cc03edd25af3e868d83037168663ef84a329 (patch)
tree1fe466ab40e697139a917f4ed4ed7099424a57be /plumbing/format/packfile/packfile.go
parentd314e86c179f755ca9c92c60d6b0aedd9f568767 (diff)
parent6f7fc05543861ee074aa17f75e1d1b5c1b948d48 (diff)
downloadgo-git-b173cc03edd25af3e868d83037168663ef84a329.tar.gz
Merge pull request #907 from erizocosmico/feature/fix-tests
plumbing: packfile, fix package tests Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
Diffstat (limited to 'plumbing/format/packfile/packfile.go')
-rw-r--r--plumbing/format/packfile/packfile.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/plumbing/format/packfile/packfile.go b/plumbing/format/packfile/packfile.go
index 00014f6..2e831f2 100644
--- a/plumbing/format/packfile/packfile.go
+++ b/plumbing/format/packfile/packfile.go
@@ -3,6 +3,7 @@ package packfile
import (
"bytes"
"io"
+ "os"
billy "gopkg.in/src-d/go-billy.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -55,6 +56,10 @@ func (p *Packfile) GetByOffset(o int64) (plumbing.EncodedObject, error) {
}
if _, err := p.s.SeekFromStart(o); err != nil {
+ if err == io.EOF || isInvalid(err) {
+ return nil, plumbing.ErrObjectNotFound
+ }
+
return nil, err
}
@@ -187,6 +192,9 @@ func (p *Packfile) getObjectType(h *ObjectHeader) (typ plumbing.ObjectType, err
func (p *Packfile) nextObject() (plumbing.EncodedObject, error) {
h, err := p.nextObjectHeader()
if err != nil {
+ if err == io.EOF || isInvalid(err) {
+ return nil, plumbing.ErrObjectNotFound
+ }
return nil, err
}
@@ -403,3 +411,21 @@ func (i *objectIter) ForEach(f func(plumbing.EncodedObject) error) error {
func (i *objectIter) Close() {
i.iter.Close()
}
+
+// isInvalid checks whether an error is an os.PathError with an os.ErrInvalid
+// error inside. It also checks for the windows error, which is different from
+// os.ErrInvalid.
+func isInvalid(err error) bool {
+ pe, ok := err.(*os.PathError)
+ if !ok {
+ return false
+ }
+
+ errstr := pe.Err.Error()
+ return errstr == errInvalidUnix || errstr == errInvalidWindows
+}
+
+// errInvalidWindows is the Windows equivalent to os.ErrInvalid
+const errInvalidWindows = "The parameter is incorrect."
+
+var errInvalidUnix = os.ErrInvalid.Error()