Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
7d254aef
Commit
7d254aef
authored
9 years ago
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1404 from ipfs/feat/patch-path
allow patch add-link to add at a path
parents
09f16003
d585e20e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
10 deletions
+63
-10
core/commands/object.go
core/commands/object.go
+49
-10
test/sharness/t0051-object.sh
test/sharness/t0051-object.sh
+14
-0
No files found.
core/commands/object.go
View file @
7d254aef
...
...
@@ -602,36 +602,75 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
return "", err
}
name
:= req.Arguments()[2]
path
:= req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
newkey, err := addLink(req.Context().Context, nd.DAG, root, name, childk)
parts := strings.Split(path, "/")
nnode, err := insertNodeAtPath(req.Context().Context, nd.DAG, root, parts, childk)
if err != nil {
return "", err
}
return newkey, nil
return nnode.Key()
}
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (
key.Key
, error) {
func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname string, childk key.Key) (
*dag.Node
, error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
childnd, err := ds.Get(ctx, childk)
if err != nil {
cancel()
return
""
, err
return
nil
, err
}
cancel()
err = root.AddNodeLinkClean(childname, childnd)
if err != nil {
return
""
, err
return
nil
, err
}
newkey
, err
:
= ds.Add(root)
_
, err = ds.Add(root)
if err != nil {
return
""
, err
return
nil
, err
}
return newkey, nil
return root, nil
}
func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, path []string, toinsert key.Key) (*dag.Node, error) {
if len(path) == 1 {
return addLink(ctx, ds, root, path[0], toinsert)
}
child, err := root.GetNodeLink(path[0])
if err != nil {
return nil, err
}
nd, err := child.GetNode(ctx, ds)
if err != nil {
return nil, err
}
ndprime, err := insertNodeAtPath(ctx, ds, nd, path[1:], toinsert)
if err != nil {
return nil, err
}
err = root.RemoveNodeLink(path[0])
if err != nil {
return nil, err
}
err = root.AddNodeLinkClean(path[0], ndprime)
if err != nil {
return nil, err
}
_, err = ds.Add(root)
if err != nil {
return nil, err
}
return root, nil
}
func nodeFromTemplate(template string) (*dag.Node, error) {
...
...
This diff is collapsed.
Click to expand it.
test/sharness/t0051-object.sh
View file @
7d254aef
...
...
@@ -100,6 +100,20 @@ test_object_cmd() {
OUTPUT=$(ipfs object patch $EMPTY_DIR add-link foo $EMPTY_DIR)
'
test_expect_success
"multilayer ipfs patch works"
'
echo "hello world" > hwfile &&
FILE=$(ipfs add -q hwfile) &&
EMPTY=$(ipfs object new unixfs-dir) &&
ONE=$(ipfs object patch $EMPTY add-link b $EMPTY) &&
TWO=$(ipfs object patch $EMPTY add-link a $ONE) &&
ipfs object patch $TWO add-link a/b/c $FILE > multi_patch
'
test_expect_success
"output looks good"
'
ipfs cat $(cat multi_patch)/a/b/c > hwfile_out &&
test_cmp hwfile hwfile_out
'
test_expect_success
"should have created dir within a dir"
'
ipfs ls $OUTPUT > patched_output
'
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment