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
b420ba1e
Commit
b420ba1e
authored
Nov 02, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands2: Added preliminary 'add' command
parent
6bab1f47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
core/commands2/add.go
core/commands2/add.go
+58
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/add.go
0 → 100644
View file @
b420ba1e
package
commands
import
(
"fmt"
"io"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/importer"
dag
"github.com/jbenet/go-ipfs/merkledag"
)
// Error indicating the max depth has been exceded.
var
ErrDepthLimitExceeded
=
fmt
.
Errorf
(
"depth limit exceeded"
)
var
addCmd
=
&
cmds
.
Command
{
Options
:
[]
cmds
.
Option
{
cmds
.
Option
{[]
string
{
"recursive"
,
"r"
},
cmds
.
Bool
},
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
Argument
{
"file"
,
cmds
.
ArgFile
,
false
,
true
},
},
Help
:
"TODO"
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
n
:=
req
.
Context
()
.
Node
// if recursive, set depth to reflect so
//opt, found := req.Option("r")
//if r, _ := opt.(bool); found && r {
//}
// add every path in args
for
_
,
arg
:=
range
req
.
Arguments
()
{
// Add the file
node
,
err
:=
add
(
n
,
arg
.
(
io
.
Reader
))
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
}
fmt
.
Println
(
node
.
Key
())
}
},
}
func
add
(
n
*
core
.
IpfsNode
,
in
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
node
,
err
:=
importer
.
NewDagFromReader
(
in
)
if
err
!=
nil
{
return
nil
,
err
}
// add the file to the graph + local storage
err
=
n
.
DAG
.
AddRecursive
(
node
)
if
err
!=
nil
{
return
nil
,
err
}
// ensure we keep it
return
node
,
n
.
Pinning
.
Pin
(
node
,
true
)
}
core/commands2/root.go
View file @
b420ba1e
...
...
@@ -57,6 +57,7 @@ var rootSubcommands = map[string]*cmds.Command{
"ls"
:
lsCmd
,
"commands"
:
commandsCmd
,
"publish"
:
publishCmd
,
"add"
:
addCmd
,
// test subcommands
// TODO: remove these when we don't need them anymore
...
...
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