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
71ac1175
Commit
71ac1175
authored
Oct 30, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address concerns in PR
parent
18ada93e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
core/commands/add.go
core/commands/add.go
+11
-1
importer/importer.go
importer/importer.go
+3
-12
No files found.
core/commands/add.go
View file @
71ac1175
...
...
@@ -10,8 +10,11 @@ import (
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/importer"
"github.com/jbenet/go-ipfs/importer/chunk"
dag
"github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/pin"
ft
"github.com/jbenet/go-ipfs/unixfs"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
)
// Error indicating the max depth has been exceded.
...
...
@@ -87,7 +90,14 @@ func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node
}
func
addFile
(
n
*
core
.
IpfsNode
,
fpath
string
,
depth
int
,
out
io
.
Writer
)
(
*
dag
.
Node
,
error
)
{
root
,
err
:=
importer
.
NewDagFromFileWServer
(
fpath
,
n
.
DAG
,
n
.
Pinning
)
dw
:=
uio
.
NewDagWriter
(
n
.
DAG
,
chunk
.
DefaultSplitter
)
mp
,
ok
:=
n
.
Pinning
.
(
pin
.
ManualPinner
)
if
!
ok
{
return
nil
,
errors
.
New
(
"invalid pinner type! expected manual pinner"
)
}
dw
.
Pinner
=
mp
root
,
err
:=
importer
.
ImportFileDag
(
fpath
,
dw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
importer/importer.go
View file @
71ac1175
package
importer
import
(
"errors"
"fmt"
"io"
"os"
"github.com/jbenet/go-ipfs/importer/chunk"
dag
"github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/pin"
ft
"github.com/jbenet/go-ipfs/unixfs"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
"github.com/jbenet/go-ipfs/util"
...
...
@@ -76,7 +74,7 @@ func NewDagFromFile(fpath string) (*dag.Node, error) {
return
NewDagFromReader
(
f
)
}
func
NewDagFromFileWServer
(
fpath
string
,
dserv
dag
.
DAGService
,
p
pin
.
Pinn
er
)
(
*
dag
.
Node
,
error
)
{
func
ImportFileDag
(
fpath
string
,
dw
*
uio
.
DagWrit
er
)
(
*
dag
.
Node
,
error
)
{
stat
,
err
:=
os
.
Stat
(
fpath
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -92,17 +90,10 @@ func NewDagFromFileWServer(fpath string, dserv dag.DAGService, p pin.Pinner) (*d
}
defer
f
.
Close
()
return
NewDagFromReaderWServer
(
f
,
dserv
,
p
)
return
ImportReaderDag
(
f
,
dw
)
}
func
NewDagFromReaderWServer
(
r
io
.
Reader
,
dserv
dag
.
DAGService
,
p
pin
.
Pinner
)
(
*
dag
.
Node
,
error
)
{
dw
:=
uio
.
NewDagWriter
(
dserv
,
chunk
.
DefaultSplitter
)
mp
,
ok
:=
p
.
(
pin
.
ManualPinner
)
if
!
ok
{
return
nil
,
errors
.
New
(
"Needed to be passed a manual pinner!"
)
}
dw
.
Pinner
=
mp
func
ImportReaderDag
(
r
io
.
Reader
,
dw
*
uio
.
DagWriter
)
(
*
dag
.
Node
,
error
)
{
_
,
err
:=
io
.
Copy
(
dw
,
r
)
if
err
!=
nil
{
return
nil
,
err
...
...
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