@cryptotaxi247 / kubo / commits / 6ab1e7147

Avoid changing hash for empty non-raw leaves.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed May 31, 2018 at 04:05 UTC 6ab1e714731c833a4c18efdf3ff550ad2e156210
4 files changed +11 -4
core/coreapi/unixfs_test.go
+1 -1
@@ -36,7 +36,7 @@ var helloStr = "hello, world!"
36 var emptyDir = coreapi.ResolvedPath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn", nil, nil)
37
38 // `echo -n | ipfs add`
39 -var emptyFile = coreapi.ResolvedPath("/ipfs/Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW", nil, nil)
39 +var emptyFile = coreapi.ResolvedPath("/ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH", nil, nil)
40
41 func makeAPIIdent(ctx context.Context, fullIdentity bool) (*core.IpfsNode, coreiface.CoreAPI, error) {
42 var ident config.Identity
importer/helpers/dagbuilder.go
+8 -1
@@ -122,7 +122,10 @@ func (db *DagBuilderHelper) NewUnixfsNode() *UnixfsNode {
122 return n
123 }
124
125 -// NewLeaf creates a leaf node filled with data
125 +// NewLeaf creates a leaf node filled with data. If rawLeaves is
126 +// defined than a raw leaf will be returned. Otherwise, if data is
127 +// nil the type field will be TRaw (for backwards compatibility), if
128 +// data is defined (but possibly empty) the type field will be TRaw.
129 func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) {
130 if len(data) > BlockSizeLimit {
131 return nil, ErrSizeLimitExceeded
@@ -145,6 +148,10 @@ func (db *DagBuilderHelper) NewLeaf(data []byte) (*UnixfsNode, error) {
148 }, nil
149 }
150
151 + if data == nil {
152 + return db.NewUnixfsNode(), nil
153 + }
154 +
155 blk := db.newUnixfsBlock()
156 blk.SetData(data)
157 return blk, nil
test/sharness/t0040-add-and-cat.sh
+1 -1
@@ -174,7 +174,7 @@ test_add_cat_file() {
174 '
175
176 test_expect_success "zero length file has correct hash" '
177 - test "$ZEROHASH" = Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW
177 + test "$ZEROHASH" = QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH
178 '
179
180 test_expect_success "cat zero length file" '
test/sharness/t0111-gateway-writeable.sh
+1 -1
@@ -14,7 +14,7 @@ test_launch_ipfs_daemon --writable
14 test_expect_success "ipfs daemon --writable overrides config" '
15 curl -v -X POST http://$GWAY_ADDR/ipfs/ 2> outfile &&
16 grep "HTTP/1.1 201 Created" outfile &&
17 - grep "Location: /ipfs/Qmdsf68UUYTSSx3i4GtDJfxzpAEZt7Mp23m3qa36LYMSiW" outfile
17 + grep "Location: /ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" outfile
18 '
19 test_kill_ipfs_daemon
20