提交 6ab1e714 作者: Kevin Atkinson

Avoid changing hash for empty non-raw leaves.

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 485a5e59
......@@ -36,7 +36,7 @@ var helloStr = "hello, world!"
var emptyDir = coreapi.ResolvedPath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn", nil, nil)
// `echo -n | ipfs add`
var emptyFile = coreapi.ResolvedPath("/ipfs/Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW", nil, nil)
var emptyFile = coreapi.ResolvedPath("/ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH", nil, nil)
func makeAPIIdent(ctx context.Context, fullIdentity bool) (*core.IpfsNode, coreiface.CoreAPI, error) {
var ident config.Identity
......
......@@ -122,7 +122,10 @@ func (db *DagBuilderHelper) NewUnixfsNode() *UnixfsNode {
return n
}
// NewLeaf creates a leaf node filled with data
// NewLeaf creates a leaf node filled with data. If rawLeaves is
// defined than a raw leaf will be returned. Otherwise, if data is
// nil the type field will be TRaw (for backwards compatibility), if
// data is defined (but possibly empty) the type field will be TRaw.
func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) {
if len(data) > BlockSizeLimit {
return nil, ErrSizeLimitExceeded
......@@ -145,6 +148,10 @@ func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) {
}, nil
}
if data == nil {
return db.NewUnixfsNode(), nil
}
blk := db.newUnixfsBlock()
blk.SetData(data)
return blk, nil
......
......@@ -174,7 +174,7 @@ test_add_cat_file() {
'
test_expect_success "zero length file has correct hash" '
test "$ZEROHASH" = Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW
test "$ZEROHASH" = QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH
'
test_expect_success "cat zero length file" '
......
......@@ -14,7 +14,7 @@ test_launch_ipfs_daemon --writable
test_expect_success "ipfs daemon --writable overrides config" '
curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
grep "HTTP/1.1 201 Created" outfile &&
grep "Location: /ipfs/Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW" outfile
grep "Location: /ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" outfile
'
test_kill_ipfs_daemon
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论