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
2509631c
Commit
2509631c
authored
Apr 18, 2016
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2531 from noffle/output-dirs-on-add
Outputs added directories as they are traversed.
parents
a8b7c9ad
e61e6858
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
15 deletions
+73
-15
core/commands/add.go
core/commands/add.go
+4
-4
core/coreunix/add.go
core/coreunix/add.go
+27
-10
mfs/dir.go
mfs/dir.go
+16
-0
mfs/ops.go
mfs/ops.go
+1
-1
test/sharness/t0040-add-and-cat.sh
test/sharness/t0040-add-and-cat.sh
+25
-0
No files found.
core/commands/add.go
View file @
2509631c
...
@@ -183,16 +183,16 @@ You can now refer to the added file in a gateway, like so:
...
@@ -183,16 +183,16 @@ You can now refer to the added file in a gateway, like so:
}
}
}
}
if
hash
{
return
nil
}
// copy intermediary nodes from editor to our actual dagservice
// copy intermediary nodes from editor to our actual dagservice
_
,
err
:=
fileAdder
.
Finalize
()
_
,
err
:=
fileAdder
.
Finalize
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
hash
{
return
nil
}
return
fileAdder
.
PinRoot
()
return
fileAdder
.
PinRoot
()
}
}
...
...
core/coreunix/add.go
View file @
2509631c
...
@@ -174,20 +174,27 @@ func (adder *Adder) PinRoot() error {
...
@@ -174,20 +174,27 @@ func (adder *Adder) PinRoot() error {
}
}
func
(
adder
*
Adder
)
Finalize
()
(
*
dag
.
Node
,
error
)
{
func
(
adder
*
Adder
)
Finalize
()
(
*
dag
.
Node
,
error
)
{
root
:=
adder
.
mr
.
GetValue
()
// cant just call adder.RootNode() here as we need the name for printing
// cant just call adder.RootNode() here as we need the name for printing
root
,
err
:=
adder
.
mr
.
GetValue
()
.
GetNode
()
root
Node
,
err
:=
root
.
GetNode
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
var
name
string
var
name
string
if
!
adder
.
Wrap
{
if
!
adder
.
Wrap
{
name
=
root
.
Links
[
0
]
.
Name
name
=
rootNode
.
Links
[
0
]
.
Name
child
,
err
:=
root
.
Links
[
0
]
.
GetNode
(
adder
.
ctx
,
adder
.
node
.
DAG
)
dir
,
ok
:=
adder
.
mr
.
GetValue
()
.
(
*
mfs
.
Directory
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"root is not a directory"
)
}
root
,
err
=
dir
.
Child
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
root
=
child
}
}
err
=
adder
.
outputDirs
(
name
,
root
)
err
=
adder
.
outputDirs
(
name
,
root
)
...
@@ -200,21 +207,31 @@ func (adder *Adder) Finalize() (*dag.Node, error) {
...
@@ -200,21 +207,31 @@ func (adder *Adder) Finalize() (*dag.Node, error) {
return
nil
,
err
return
nil
,
err
}
}
return
root
,
nil
return
root
.
GetNode
()
}
}
func
(
adder
*
Adder
)
outputDirs
(
path
string
,
nd
*
dag
.
Node
)
error
{
func
(
adder
*
Adder
)
outputDirs
(
path
string
,
fs
mfs
.
FSNode
)
error
{
if
!
bytes
.
Equal
(
nd
.
Data
,
folderData
)
{
nd
,
err
:=
fs
.
GetNode
()
if
err
!=
nil
{
return
err
}
if
!
bytes
.
Equal
(
nd
.
Data
,
folderData
)
||
fs
.
Type
()
!=
mfs
.
TDir
{
return
nil
return
nil
}
}
for
_
,
l
:=
range
nd
.
Links
{
dir
,
ok
:=
fs
.
(
*
mfs
.
Directory
)
child
,
err
:=
l
.
GetNode
(
adder
.
ctx
,
adder
.
node
.
DAG
)
if
!
ok
{
return
fmt
.
Errorf
(
"received FSNode of type TDir that was not a Directory"
)
}
for
_
,
name
:=
range
dir
.
ListNames
()
{
child
,
err
:=
dir
.
Child
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
err
=
adder
.
outputDirs
(
gopath
.
Join
(
path
,
l
.
N
ame
),
child
)
err
=
adder
.
outputDirs
(
gopath
.
Join
(
path
,
n
ame
),
child
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
mfs/dir.go
View file @
2509631c
...
@@ -116,6 +116,11 @@ func (d *Directory) childNode(name string) (FSNode, error) {
...
@@ -116,6 +116,11 @@ func (d *Directory) childNode(name string) (FSNode, error) {
return
nil
,
err
return
nil
,
err
}
}
return
d
.
cacheNode
(
name
,
nd
)
}
// cacheNode caches a node into d.childDirs or d.files and returns the FSNode.
func
(
d
*
Directory
)
cacheNode
(
name
string
,
nd
*
dag
.
Node
)
(
FSNode
,
error
)
{
i
,
err
:=
ft
.
FromBytes
(
nd
.
Data
)
i
,
err
:=
ft
.
FromBytes
(
nd
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -334,6 +339,17 @@ func (d *Directory) AddChild(name string, nd *dag.Node) error {
...
@@ -334,6 +339,17 @@ func (d *Directory) AddChild(name string, nd *dag.Node) error {
d
.
modTime
=
time
.
Now
()
d
.
modTime
=
time
.
Now
()
if
len
(
nd
.
Links
)
==
0
{
nfi
,
err
:=
NewFile
(
name
,
nd
,
d
,
d
.
dserv
)
if
err
!=
nil
{
return
err
}
d
.
files
[
name
]
=
nfi
}
else
{
ndir
:=
NewDirectory
(
d
.
ctx
,
name
,
nd
,
d
,
d
.
dserv
)
d
.
childDirs
[
name
]
=
ndir
}
return
nil
return
nil
}
}
...
...
mfs/ops.go
View file @
2509631c
...
@@ -102,7 +102,7 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
...
@@ -102,7 +102,7 @@ func PutNode(r *Root, path string, nd *dag.Node) error {
// intermediary directories as needed if 'mkparents' is set to true
// intermediary directories as needed if 'mkparents' is set to true
func
Mkdir
(
r
*
Root
,
pth
string
,
mkparents
bool
,
flush
bool
)
error
{
func
Mkdir
(
r
*
Root
,
pth
string
,
mkparents
bool
,
flush
bool
)
error
{
if
pth
==
""
{
if
pth
==
""
{
return
nil
return
fmt
.
Errorf
(
"no path given to Mkdir"
)
}
}
parts
:=
path
.
SplitList
(
pth
)
parts
:=
path
.
SplitList
(
pth
)
if
parts
[
0
]
==
""
{
if
parts
[
0
]
==
""
{
...
...
test/sharness/t0040-add-and-cat.sh
View file @
2509631c
...
@@ -285,6 +285,31 @@ test_expect_success "'ipfs add -r' output looks good" '
...
@@ -285,6 +285,31 @@ test_expect_success "'ipfs add -r' output looks good" '
test_cmp expected actual
test_cmp expected actual
'
'
test_expect_success
"'ipfs add -rn' succeeds"
'
mkdir -p mountdir/moons/jupiter &&
mkdir -p mountdir/moons/saturn &&
echo "Hello Europa!" >mountdir/moons/jupiter/europa.txt &&
echo "Hello Titan!" >mountdir/moons/saturn/titan.txt &&
echo "hey youre no moon!" >mountdir/moons/mercury.txt &&
ipfs add -rn mountdir/moons >actual
'
test_expect_success
"'ipfs add -rn' output looks good"
'
MOONS="QmVKvomp91nMih5j6hYBA8KjbiaYvEetU2Q7KvtZkLe9nQ" &&
EUROPA="Qmbjg7zWdqdMaK2BucPncJQDxiALExph5k3NkQv5RHpccu" &&
JUPITER="QmS5mZddhFPLWFX3w6FzAy9QxyYkaxvUpsWCtZ3r7jub9J" &&
SATURN="QmaMagZT4rTE7Nonw8KGSK4oe1bh533yhZrCo1HihSG8FK" &&
TITAN="QmZzppb9WHn552rmRqpPfgU5FEiHH6gDwi3MrB9cTdPwdb" &&
MERCURY="QmUJjVtnN8YEeYcS8VmUeWffTWhnMQAkk5DzZdKnPhqUdK" &&
echo "added $EUROPA moons/jupiter/europa.txt" >expected &&
echo "added $MERCURY moons/mercury.txt" >>expected &&
echo "added $TITAN moons/saturn/titan.txt" >>expected &&
echo "added $JUPITER moons/jupiter" >>expected &&
echo "added $SATURN moons/saturn" >>expected &&
echo "added $MOONS moons" >>expected &&
test_cmp expected actual
'
test_expect_success
"ipfs cat accept many hashes from stdin"
'
test_expect_success
"ipfs cat accept many hashes from stdin"
'
{ echo "$MARS"; echo "$VENUS"; } | ipfs cat >actual
{ echo "$MARS"; echo "$VENUS"; } | ipfs cat >actual
'
'
...
...
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