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
196c6aa4
Commit
196c6aa4
authored
Apr 27, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1127 from wking/add-single-reader
core/commands/add: Change add() to only accept a single reader
parents
c9bf4703
641c20b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
26 deletions
+20
-26
core/commands/add.go
core/commands/add.go
+9
-14
core/coreunix/add.go
core/coreunix/add.go
+11
-12
No files found.
core/commands/add.go
View file @
196c6aa4
...
...
@@ -213,23 +213,18 @@ remains to be implemented.
Type
:
AddedObject
{},
}
func
add
(
n
*
core
.
IpfsNode
,
readers
[]
io
.
Reader
)
([]
*
dag
.
Node
,
error
)
{
dagnodes
:=
make
([]
*
dag
.
Node
,
0
)
for
_
,
reader
:=
range
readers
{
node
,
err
:=
importer
.
BuildDagFromReader
(
reader
,
n
.
DAG
,
nil
,
chunk
.
DefaultSplitter
)
if
err
!=
nil
{
return
nil
,
err
}
dagnodes
=
append
(
dagnodes
,
node
)
func
add
(
n
*
core
.
IpfsNode
,
reader
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
node
,
err
:=
importer
.
BuildDagFromReader
(
reader
,
n
.
DAG
,
nil
,
chunk
.
DefaultSplitter
)
if
err
!=
nil
{
return
nil
,
err
}
err
:
=
n
.
Pinning
.
Flush
()
err
=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
dag
node
s
,
nil
return
node
,
nil
}
func
addFile
(
n
*
core
.
IpfsNode
,
file
files
.
File
,
out
chan
interface
{},
progress
bool
,
wrap
bool
)
(
*
dag
.
Node
,
error
)
{
...
...
@@ -256,16 +251,16 @@ func addFile(n *core.IpfsNode, file files.File, out chan interface{}, progress b
return
dagnode
,
nil
}
d
ns
,
err
:=
add
(
n
,
[]
io
.
Reader
{
reader
}
)
d
agnode
,
err
:=
add
(
n
,
reader
)
if
err
!=
nil
{
return
nil
,
err
}
log
.
Infof
(
"adding file: %s"
,
file
.
FileName
())
if
err
:=
outputDagnode
(
out
,
file
.
FileName
(),
d
ns
[
len
(
dns
)
-
1
]
);
err
!=
nil
{
if
err
:=
outputDagnode
(
out
,
file
.
FileName
(),
d
agnode
);
err
!=
nil
{
return
nil
,
err
}
return
dns
[
len
(
dns
)
-
1
],
nil
// last
dag
node
is the file.
return
dagnode
,
nil
}
func
addDir
(
n
*
core
.
IpfsNode
,
dir
files
.
File
,
out
chan
interface
{},
progress
bool
)
(
*
dag
.
Node
,
error
)
{
...
...
core/coreunix/add.go
View file @
196c6aa4
...
...
@@ -86,24 +86,23 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, *merkle
return
gopath
.
Join
(
k
.
String
(),
filename
),
dagnode
,
nil
}
func
add
(
n
*
core
.
IpfsNode
,
reader
s
[]
io
.
Reader
)
(
[]
*
merkledag
.
Node
,
error
)
{
func
add
(
n
*
core
.
IpfsNode
,
reader
io
.
Reader
)
(
*
merkledag
.
Node
,
error
)
{
mp
,
ok
:=
n
.
Pinning
.
(
pin
.
ManualPinner
)
if
!
ok
{
return
nil
,
errors
.
New
(
"invalid pinner type! expected manual pinner"
)
}
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
for
_
,
reader
:=
range
readers
{
node
,
err
:=
importer
.
BuildDagFromReader
(
reader
,
n
.
DAG
,
mp
,
chunk
.
DefaultSplitter
)
if
err
!=
nil
{
return
nil
,
err
}
dagnodes
=
append
(
dagnodes
,
node
)
node
,
err
:=
importer
.
BuildDagFromReader
(
reader
,
n
.
DAG
,
mp
,
chunk
.
DefaultSplitter
)
if
err
!=
nil
{
return
nil
,
err
}
err
:=
n
.
Pinning
.
Flush
()
err
=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
nil
,
err
}
return
dagnodes
,
nil
return
node
,
nil
}
func
addNode
(
n
*
core
.
IpfsNode
,
node
*
merkledag
.
Node
)
error
{
...
...
@@ -125,12 +124,12 @@ func addFile(n *core.IpfsNode, file files.File) (*merkledag.Node, error) {
return
addDir
(
n
,
file
)
}
d
ns
,
err
:=
add
(
n
,
[]
io
.
Reader
{
file
}
)
d
agnode
,
err
:=
add
(
n
,
file
)
if
err
!=
nil
{
return
nil
,
err
}
return
dns
[
len
(
dns
)
-
1
],
nil
// last
dag
node
is the file.
return
dagnode
,
nil
}
func
addDir
(
n
*
core
.
IpfsNode
,
dir
files
.
File
)
(
*
merkledag
.
Node
,
error
)
{
...
...
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