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
ec40a29b
Commit
ec40a29b
authored
Sep 12, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change ExecuteCommand to return an error
parent
80dc4b35
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
21 deletions
+34
-21
cmd/ipfs/add.go
cmd/ipfs/add.go
+4
-1
cmd/ipfs/cat.go
cmd/ipfs/cat.go
+5
-1
cmd/ipfs/ls.go
cmd/ipfs/ls.go
+4
-1
daemon/daemon.go
daemon/daemon.go
+21
-18
No files found.
cmd/ipfs/add.go
View file @
ec40a29b
...
...
@@ -50,7 +50,10 @@ func addCmd(c *commander.Command, inp []string) error {
return
err
}
daemon
.
ExecuteCommand
(
cmd
,
n
,
os
.
Stdout
)
err
:=
daemon
.
ExecuteCommand
(
cmd
,
n
,
os
.
Stdout
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
return
nil
}
cmd/ipfs/cat.go
View file @
ec40a29b
package
main
import
(
"fmt"
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
...
...
@@ -38,7 +39,10 @@ func catCmd(c *commander.Command, inp []string) error {
return
err
}
daemon
.
ExecuteCommand
(
com
,
n
,
os
.
Stdout
)
err
:=
daemon
.
ExecuteCommand
(
com
,
n
,
os
.
Stdout
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
return
nil
}
cmd/ipfs/ls.go
View file @
ec40a29b
...
...
@@ -42,7 +42,10 @@ func lsCmd(c *commander.Command, inp []string) error {
return
err
}
daemon
.
ExecuteCommand
(
com
,
n
,
os
.
Stdout
)
err
:=
daemon
.
ExecuteCommand
(
com
,
n
,
os
.
Stdout
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
return
nil
...
...
daemon/daemon.go
View file @
ec40a29b
...
...
@@ -74,10 +74,13 @@ func (dl *DaemonListener) handleConnection(conn net.Conn) {
}
u
.
DOut
(
"Got command: %v
\n
"
,
command
)
ExecuteCommand
(
&
command
,
dl
.
node
,
conn
)
err
:=
ExecuteCommand
(
&
command
,
dl
.
node
,
conn
)
if
err
!=
nil
{
fmt
.
Fprintln
(
conn
,
"%v
\n
"
,
err
)
}
}
func
ExecuteCommand
(
com
*
Command
,
ipfsnode
*
core
.
IpfsNode
,
out
io
.
Writer
)
{
func
ExecuteCommand
(
com
*
Command
,
ipfsnode
*
core
.
IpfsNode
,
out
io
.
Writer
)
error
{
u
.
DOut
(
"executing command: %s
\n
"
,
com
.
Command
)
switch
com
.
Command
{
case
"add"
:
...
...
@@ -86,38 +89,40 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) {
depth
=
-
1
}
for
_
,
path
:=
range
com
.
Args
{
_
,
err
:=
commands
.
AddPath
(
ipfsnode
,
path
,
depth
)
nd
,
err
:=
commands
.
AddPath
(
ipfsnode
,
path
,
depth
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"addFile error: %v"
,
err
)
}
k
,
err
:=
nd
.
Key
()
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"addFile error: %v
\n
"
,
err
)
continue
return
fmt
.
Errorf
(
"addFile error: %v"
,
err
)
}
fmt
.
Fprintf
(
out
,
"Added node: %s = %s
\n
"
,
path
,
k
.
Pretty
())
}
case
"cat"
:
for
_
,
fn
:=
range
com
.
Args
{
dagnode
,
err
:=
ipfsnode
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"catFile error: %v
\n
"
,
err
)
return
return
fmt
.
Errorf
(
"catFile error: %v"
,
err
)
}
read
,
err
:=
dag
.
NewDagReader
(
dagnode
,
ipfsnode
.
DAG
)
if
err
!=
nil
{
fmt
.
Fprintln
(
out
,
err
)
continue
return
fmt
.
Errorf
(
"cat error: %v"
,
err
)
}
_
,
err
=
io
.
Copy
(
out
,
read
)
if
err
!=
nil
{
fmt
.
Fprintln
(
out
,
err
)
continue
return
fmt
.
Errorf
(
"cat error: %v"
,
err
)
}
}
case
"ls"
:
for
_
,
fn
:=
range
com
.
Args
{
dagnode
,
err
:=
ipfsnode
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"ls error: %v
\n
"
,
err
)
return
return
fmt
.
Errorf
(
"ls error: %v"
,
err
)
}
for
_
,
link
:=
range
dagnode
.
Links
{
...
...
@@ -128,18 +133,16 @@ func ExecuteCommand(com *Command, ipfsnode *core.IpfsNode, out io.Writer) {
for
_
,
fn
:=
range
com
.
Args
{
dagnode
,
err
:=
ipfsnode
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"pin error: %v
\n
"
,
err
)
return
return
fmt
.
Errorf
(
"pin error: %v"
,
err
)
}
err
=
ipfsnode
.
PinDagNode
(
dagnode
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"pin: %v
\n
"
,
err
)
return
return
fmt
.
Errorf
(
"pin: %v"
,
err
)
}
}
default
:
fmt
.
Fprintf
(
out
,
"Invalid Command: '%s'
\n
"
,
com
.
Command
)
return
fmt
.
Errord
(
"Invalid Command: '%s'"
,
com
.
Command
)
}
}
...
...
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