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
1fe28bc6
Commit
1fe28bc6
authored
Dec 14, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
files2.0: split adder.addFile into subtyped functions
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
a92a1745
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
27 deletions
+31
-27
core/coreunix/add.go
core/coreunix/add.go
+31
-27
No files found.
core/coreunix/add.go
View file @
1fe28bc6
...
...
@@ -322,7 +322,7 @@ func AddR(n *core.IpfsNode, root string) (key string, err error) {
return
""
,
err
}
err
=
fileAdder
.
addFile
(
filepath
.
Base
(
root
),
f
)
err
=
fileAdder
.
addFile
Node
(
filepath
.
Base
(
root
),
f
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -348,7 +348,7 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.No
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
err
=
fileAdder
.
addFile
(
filename
,
files
.
NewReaderFile
(
r
))
err
=
fileAdder
.
addFile
Node
(
filename
,
files
.
NewReaderFile
(
r
))
if
err
!=
nil
{
return
""
,
nil
,
err
}
...
...
@@ -416,7 +416,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
// semantics.
it
:=
tf
.
Entries
()
for
it
.
Next
()
{
if
err
:=
adder
.
addFile
(
it
.
Name
(),
it
.
Node
());
err
!=
nil
{
if
err
:=
adder
.
addFile
Node
(
it
.
Name
(),
it
.
Node
());
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -425,7 +425,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
}
break
default
:
if
err
:=
adder
.
addFile
(
""
,
file
);
err
!=
nil
{
if
err
:=
adder
.
addFile
Node
(
""
,
file
);
err
!=
nil
{
return
nil
,
err
}
break
...
...
@@ -443,7 +443,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
return
nd
,
adder
.
PinRoot
()
}
func
(
adder
*
Adder
)
addFile
(
path
string
,
file
files
.
Node
)
error
{
func
(
adder
*
Adder
)
addFile
Node
(
path
string
,
file
files
.
Node
)
error
{
defer
file
.
Close
()
err
:=
adder
.
maybePauseForGC
()
if
err
!=
nil
{
...
...
@@ -464,34 +464,38 @@ func (adder *Adder) addFile(path string, file files.Node) error {
}
adder
.
liveNodes
++
if
dir
,
ok
:=
file
.
(
files
.
Directory
);
ok
{
return
adder
.
addDir
(
path
,
dir
)
switch
f
:=
file
.
(
type
)
{
case
files
.
Directory
:
return
adder
.
addDir
(
path
,
f
)
case
*
files
.
Symlink
:
return
adder
.
addSymlink
(
path
,
f
)
case
files
.
File
:
return
adder
.
addFile
(
path
,
f
)
default
:
return
errors
.
New
(
"unknown file type"
)
}
}
// case for symlink
if
s
,
ok
:=
file
.
(
*
files
.
Symlink
);
ok
{
sdata
,
err
:=
unixfs
.
SymlinkData
(
s
.
Target
)
if
err
!=
nil
{
return
err
}
dagnode
:=
dag
.
NodeWithData
(
sdata
)
dagnode
.
SetCidBuilder
(
adder
.
CidBuilder
)
err
=
adder
.
dagService
.
Add
(
adder
.
ctx
,
dagnode
)
if
err
!=
nil
{
return
err
}
func
(
adder
*
Adder
)
addSymlink
(
path
string
,
l
*
files
.
Symlink
)
error
{
sdata
,
err
:=
unixfs
.
SymlinkData
(
l
.
Target
)
if
err
!=
nil
{
return
err
}
return
adder
.
addNode
(
dagnode
,
path
)
dagnode
:=
dag
.
NodeWithData
(
sdata
)
dagnode
.
SetCidBuilder
(
adder
.
CidBuilder
)
err
=
adder
.
dagService
.
Add
(
adder
.
ctx
,
dagnode
)
if
err
!=
nil
{
return
err
}
// case for regular file
return
adder
.
addNode
(
dagnode
,
path
)
}
func
(
adder
*
Adder
)
addFile
(
path
string
,
file
files
.
File
)
error
{
// if the progress flag was specified, wrap the file so that we can send
// progress updates to the client (over the output channel)
reader
,
ok
:=
file
.
(
io
.
Reader
)
if
!
ok
{
return
errors
.
New
(
"file doesn't support reading"
)
}
var
reader
io
.
Reader
=
file
if
adder
.
Progress
{
rdr
:=
&
progressReader
{
file
:
reader
,
path
:
path
,
out
:
adder
.
Out
}
if
fi
,
ok
:=
file
.
(
files
.
FileInfo
);
ok
{
...
...
@@ -542,7 +546,7 @@ func (adder *Adder) addDir(path string, dir files.Directory) error {
log
.
Infof
(
"%s is hidden, skipping"
,
fpath
)
continue
}
err
=
adder
.
addFile
(
fpath
,
it
.
Node
())
err
=
adder
.
addFile
Node
(
fpath
,
it
.
Node
())
if
err
!=
nil
{
return
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