dag: fix git plugin
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Aug 9, 2017 at 19:31 UTC
7f208ce043efb2852ecca22bb4a79fc1c88e3300
1 file changed
+14
-3
plugin/plugins/git/git.go
+14
-3
@@ -2,12 +2,15 @@ package git
2
3
import (
4
"compress/zlib"
5
+ "fmt"
6
"io"
7
+ "math"
8
9
"github.com/ipfs/go-ipfs/core/coredag"
10
"github.com/ipfs/go-ipfs/plugin"
11
12
"gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
13
+ mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
14
"gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
15
git "gx/ipfs/Qma7Kuwun7w8SZphjEPDVxvGfetBkqdNGmigDA13sJdLex/go-ipld-git"
16
)
@@ -44,7 +47,15 @@ func (*gitPlugin) RegisterInputEncParsers(iec coredag.InputEncParsers) error {
47
return nil
48
}
49
47
-func parseRawGit(r io.Reader) ([]format.Node, error) {
50
+func parseRawGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) {
51
+ if mhType != math.MaxUint64 && mhType != mh.SHA1 {
52
+ return nil, fmt.Errorf("unsupported mhType %d", mhType)
53
+ }
54
+
55
+ if mhLen != -1 && mhLen != mh.DefaultLengths[mh.SHA1] {
56
+ return nil, fmt.Errorf("invalid mhLen %d", mhType)
57
+ }
58
+
59
nd, err := git.ParseObject(r)
60
if err != nil {
61
return nil, err
@@ -53,12 +64,12 @@ func parseRawGit(r io.Reader) ([]format.Node, error) {
64
return []format.Node{nd}, nil
65
}
66
56
-func parseZlibGit(r io.Reader) ([]format.Node, error) {
67
+func parseZlibGit(r io.Reader, mhType uint64, mhLen int) ([]format.Node, error) {
68
rc, err := zlib.NewReader(r)
69
if err != nil {
70
return nil, err
71
}
72
73
defer rc.Close()
63
- return parseRawGit(rc)
74
+ return parseRawGit(rc, mhType, mhLen)
75
}