ipfs object patch add-link supports paths
previously, paths were not supported as link values. this would not work, and now can: ipfs object patch $root add-link foo /ipfs/$hash/foo/bar License: MIT Signed-off-by: Juan Benet <juan@benet.ai>
jbenet committed
May 16, 2016 at 22:56 UTC
9f79dde058955585924698a183620615bafbf371
2 files changed
+18
-5
core/commands/object/patch.go
+8
-5
@@ -5,7 +5,6 @@ import (
5
"io/ioutil"
6
"strings"
7
8
- key "github.com/ipfs/go-ipfs/blocks/key"
8
cmds "github.com/ipfs/go-ipfs/commands"
9
core "github.com/ipfs/go-ipfs/core"
10
dag "github.com/ipfs/go-ipfs/merkledag"
@@ -273,8 +272,12 @@ a file containing 'bar', and returns the hash of the new object.
272
return
273
}
274
276
- path := req.Arguments()[1]
277
- childk := key.B58KeyDecode(req.Arguments()[2])
275
+ npath := req.Arguments()[1]
276
+ childp, err := path.ParsePath(req.Arguments()[2])
277
+ if err != nil {
278
+ res.SetError(err, cmds.ErrNormal)
279
+ return
280
+ }
281
282
create, _, err := req.Option("create").Bool()
283
if err != nil {
@@ -291,13 +294,13 @@ a file containing 'bar', and returns the hash of the new object.
294
295
e := dagutils.NewDagEditor(root, nd.DAG)
296
294
- childnd, err := nd.DAG.Get(req.Context(), childk)
297
+ childnd, err := core.Resolve(req.Context(), nd, childp)
298
if err != nil {
299
res.SetError(err, cmds.ErrNormal)
300
return
301
}
302
300
- err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc)
303
+ err = e.InsertNodeAtPath(req.Context(), npath, childnd, createfunc)
304
if err != nil {
305
res.SetError(err, cmds.ErrNormal)
306
return
test/sharness/t0051-object.sh
+10
@@ -180,6 +180,16 @@ test_object_cmd() {
180
ipfs object stat $OUTPUT
181
'
182
183
+ test_expect_success "'ipfs object patch add-link' should work with paths" '
184
+ EMPTY_DIR=$(ipfs object new unixfs-dir) &&
185
+ N1=$(ipfs object patch $EMPTY_DIR add-link baz $EMPTY_DIR) &&
186
+ N2=$(ipfs object patch $EMPTY_DIR add-link bar $N1) &&
187
+ N3=$(ipfs object patch $EMPTY_DIR add-link foo /ipfs/$N2/bar) &&
188
+ ipfs object stat /ipfs/$N3 &&
189
+ ipfs object stat $N3/foo &&
190
+ ipfs object stat /ipfs/$N3/foo/baz
191
+ '
192
+
193
test_expect_success "multilayer ipfs patch works" '
194
echo "hello world" > hwfile &&
195
FILE=$(ipfs add -q hwfile) &&