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
bb84c232
Commit
bb84c232
authored
Oct 10, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make add command use absolute paths and print properly, issue #151
parent
26574b53
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
33 deletions
+32
-33
cmd/ipfs/add.go
cmd/ipfs/add.go
+6
-4
cmd/ipfs/gen.go
cmd/ipfs/gen.go
+17
-6
core/commands/add.go
core/commands/add.go
+9
-23
No files found.
cmd/ipfs/add.go
View file @
bb84c232
...
...
@@ -2,6 +2,7 @@ package main
import
(
"fmt"
"path/filepath"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
...
...
@@ -30,8 +31,9 @@ func init() {
}
var
addCmd
=
makeCommand
(
command
{
name
:
"add"
,
args
:
1
,
flags
:
[]
string
{
"r"
},
cmdFn
:
commands
.
Add
,
name
:
"add"
,
args
:
1
,
flags
:
[]
string
{
"r"
},
cmdFn
:
commands
.
Add
,
argFilter
:
filepath
.
Abs
,
})
cmd/ipfs/gen.go
View file @
bb84c232
...
...
@@ -13,11 +13,12 @@ import (
// command is the descriptor of an ipfs daemon command.
// Used with makeCommand to proxy over commands via the daemon.
type
command
struct
{
name
string
args
int
flags
[]
string
online
bool
cmdFn
commands
.
CmdFunc
name
string
args
int
flags
[]
string
online
bool
cmdFn
commands
.
CmdFunc
argFilter
func
(
string
)
(
string
,
error
)
}
// commanderFunc is a function that can be passed into the Commander library as
...
...
@@ -39,7 +40,17 @@ func makeCommand(cmdDesc command) commanderFunc {
cmd
:=
daemon
.
NewCommand
()
cmd
.
Command
=
cmdDesc
.
name
cmd
.
Args
=
inp
if
cmdDesc
.
argFilter
!=
nil
{
for
_
,
a
:=
range
inp
{
s
,
err
:=
cmdDesc
.
argFilter
(
a
)
if
err
!=
nil
{
return
err
}
cmd
.
Args
=
append
(
cmd
.
Args
,
s
)
}
}
else
{
cmd
.
Args
=
inp
}
for
_
,
a
:=
range
cmdDesc
.
flags
{
cmd
.
Opts
[
a
]
=
c
.
Flag
.
Lookup
(
a
)
.
Value
.
Get
()
...
...
core/commands/add.go
View file @
bb84c232
...
...
@@ -12,7 +12,6 @@ import (
"github.com/jbenet/go-ipfs/importer"
dag
"github.com/jbenet/go-ipfs/merkledag"
ft
"github.com/jbenet/go-ipfs/unixfs"
u
"github.com/jbenet/go-ipfs/util"
)
// Error indicating the max depth has been exceded.
...
...
@@ -30,14 +29,8 @@ func Add(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
// add every path in args
for
_
,
path
:=
range
args
{
// get absolute path, as incoming arg may be relative
path
,
err
:=
filepath
.
Abs
(
path
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"addFile error: %v"
,
err
)
}
// Add the file
_
,
err
=
AddPath
(
n
,
path
,
depth
)
_
,
err
:
=
AddPath
(
n
,
path
,
depth
,
out
)
if
err
!=
nil
{
if
err
==
ErrDepthLimitExceeded
&&
depth
==
1
{
err
=
errors
.
New
(
"use -r to recursively add directories"
)
...
...
@@ -58,7 +51,7 @@ func Add(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
}
// AddPath adds a particular path to ipfs.
func
AddPath
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
)
(
*
dag
.
Node
,
error
)
{
func
AddPath
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
,
out
io
.
Writer
)
(
*
dag
.
Node
,
error
)
{
if
depth
==
0
{
return
nil
,
ErrDepthLimitExceeded
}
...
...
@@ -69,13 +62,13 @@ func AddPath(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
}
if
fi
.
IsDir
()
{
return
addDir
(
n
,
fpath
,
depth
)
return
addDir
(
n
,
fpath
,
depth
,
out
)
}
return
addFile
(
n
,
fpath
,
depth
)
return
addFile
(
n
,
fpath
,
depth
,
out
)
}
func
addDir
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
)
(
*
dag
.
Node
,
error
)
{
func
addDir
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
,
out
io
.
Writer
)
(
*
dag
.
Node
,
error
)
{
tree
:=
&
dag
.
Node
{
Data
:
ft
.
FolderPBData
()}
files
,
err
:=
ioutil
.
ReadDir
(
fpath
)
...
...
@@ -86,7 +79,7 @@ func addDir(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
// construct nodes for containing files.
for
_
,
f
:=
range
files
{
fp
:=
filepath
.
Join
(
fpath
,
f
.
Name
())
nd
,
err
:=
AddPath
(
n
,
fp
,
depth
-
1
)
nd
,
err
:=
AddPath
(
n
,
fp
,
depth
-
1
,
out
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -99,7 +92,7 @@ func addDir(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
return
tree
,
addNode
(
n
,
tree
,
fpath
)
}
func
addFile
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
)
(
*
dag
.
Node
,
error
)
{
func
addFile
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
,
out
io
.
Writer
)
(
*
dag
.
Node
,
error
)
{
root
,
err
:=
importer
.
NewDagFromFile
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -110,9 +103,9 @@ func addFile(n *core.IpfsNode, fpath string, depth int) (*dag.Node, error) {
return
nil
,
err
}
log
.
Info
(
"Adding file: %s = %s
\n
"
,
fpath
,
k
)
fmt
.
Fprintf
(
out
,
"Adding file: %s = %s
\n
"
,
fpath
,
k
)
for
_
,
l
:=
range
root
.
Links
{
log
.
Info
(
"SubBlock: %s
\n
"
,
l
.
Hash
.
B58String
())
fmt
.
Fprintf
(
out
,
"SubBlock: %s
\n
"
,
l
.
Hash
.
B58String
())
}
return
root
,
addNode
(
n
,
root
,
fpath
)
...
...
@@ -126,13 +119,6 @@ func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
return
err
}
k
,
err
:=
nd
.
Key
()
if
err
!=
nil
{
return
err
}
u
.
POut
(
"added %s %s
\n
"
,
k
,
fpath
)
// ensure we keep it. atm no-op
return
n
.
PinDagNodeRecursively
(
nd
,
-
1
)
}
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