Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7a579bbf
提交
7a579bbf
authored
1月 13, 2015
作者:
Matt Bell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands: Moved files code into 'commands/files' subpackage
上级
b6670da5
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
131 行增加
和
117 行删除
+131
-117
parse.go
commands/cli/parse.go
+12
-11
file.go
commands/files/file.go
+31
-0
file_test.go
commands/files/file_test.go
+1
-1
multipartfile.go
commands/files/multipartfile.go
+1
-92
readerfile.go
commands/files/readerfile.go
+34
-0
slicefile.go
commands/files/slicefile.go
+36
-0
multifilereader.go
commands/http/multifilereader.go
+3
-3
parse.go
commands/http/parse.go
+3
-2
request.go
commands/request.go
+7
-6
add.go
core/commands/add.go
+3
-2
没有找到文件。
commands/cli/parse.go
浏览文件 @
7a579bbf
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"strings"
"strings"
cmds
"github.com/jbenet/go-ipfs/commands"
cmds
"github.com/jbenet/go-ipfs/commands"
cmdsFiles
"github.com/jbenet/go-ipfs/commands/files"
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
)
)
...
@@ -65,7 +66,7 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
...
@@ -65,7 +66,7 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
}
}
req
.
SetArguments
(
stringArgs
)
req
.
SetArguments
(
stringArgs
)
file
:=
&
cmds
.
SliceFile
{
""
,
fileArgs
}
file
:=
&
cmds
Files
.
SliceFile
{
""
,
fileArgs
}
req
.
SetFiles
(
file
)
req
.
SetFiles
(
file
)
err
=
cmd
.
CheckArguments
(
req
)
err
=
cmd
.
CheckArguments
(
req
)
...
@@ -139,7 +140,7 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
...
@@ -139,7 +140,7 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
return
opts
,
args
,
nil
return
opts
,
args
,
nil
}
}
func
parseArgs
(
inputs
[]
string
,
stdin
*
os
.
File
,
argDefs
[]
cmds
.
Argument
,
recursive
bool
)
([]
string
,
[]
cmds
.
File
,
error
)
{
func
parseArgs
(
inputs
[]
string
,
stdin
*
os
.
File
,
argDefs
[]
cmds
.
Argument
,
recursive
bool
)
([]
string
,
[]
cmds
Files
.
File
,
error
)
{
// ignore stdin on Windows
// ignore stdin on Windows
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
stdin
=
nil
stdin
=
nil
...
@@ -176,7 +177,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
...
@@ -176,7 +177,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
}
}
stringArgs
:=
make
([]
string
,
0
,
numInputs
)
stringArgs
:=
make
([]
string
,
0
,
numInputs
)
fileArgs
:=
make
([]
cmds
.
File
,
0
,
numInputs
)
fileArgs
:=
make
([]
cmds
Files
.
File
,
0
,
numInputs
)
argDefIndex
:=
0
// the index of the current argument definition
argDefIndex
:=
0
// the index of the current argument definition
for
i
:=
0
;
i
<
numInputs
;
i
++
{
for
i
:=
0
;
i
<
numInputs
;
i
++
{
...
@@ -263,7 +264,7 @@ func appendStdinAsString(args []string, stdin *os.File) ([]string, *os.File, err
...
@@ -263,7 +264,7 @@ func appendStdinAsString(args []string, stdin *os.File) ([]string, *os.File, err
return
append
(
args
,
buf
.
String
()),
nil
,
nil
return
append
(
args
,
buf
.
String
()),
nil
,
nil
}
}
func
appendFile
(
args
[]
cmds
.
File
,
inputs
[]
string
,
argDef
*
cmds
.
Argument
,
recursive
bool
)
([]
cmd
s
.
File
,
[]
string
,
error
)
{
func
appendFile
(
args
[]
cmds
Files
.
File
,
inputs
[]
string
,
argDef
*
cmds
.
Argument
,
recursive
bool
)
([]
cmdsFile
s
.
File
,
[]
string
,
error
)
{
path
:=
inputs
[
0
]
path
:=
inputs
[
0
]
file
,
err
:=
os
.
Open
(
path
)
file
,
err
:=
os
.
Open
(
path
)
...
@@ -297,13 +298,13 @@ func appendFile(args []cmds.File, inputs []string, argDef *cmds.Argument, recurs
...
@@ -297,13 +298,13 @@ func appendFile(args []cmds.File, inputs []string, argDef *cmds.Argument, recurs
return
append
(
args
,
arg
),
inputs
[
1
:
],
nil
return
append
(
args
,
arg
),
inputs
[
1
:
],
nil
}
}
func
appendStdinAsFile
(
args
[]
cmds
.
File
,
stdin
*
os
.
File
)
([]
cmd
s
.
File
,
*
os
.
File
)
{
func
appendStdinAsFile
(
args
[]
cmds
Files
.
File
,
stdin
*
os
.
File
)
([]
cmdsFile
s
.
File
,
*
os
.
File
)
{
arg
:=
&
cmds
.
ReaderFile
{
""
,
stdin
}
arg
:=
&
cmds
Files
.
ReaderFile
{
""
,
stdin
}
return
append
(
args
,
arg
),
nil
return
append
(
args
,
arg
),
nil
}
}
// recursively get file or directory contents as a cmds.File
// recursively get file or directory contents as a cmds
Files
.File
func
openPath
(
file
*
os
.
File
,
path
string
)
(
cmds
.
File
,
error
)
{
func
openPath
(
file
*
os
.
File
,
path
string
)
(
cmds
Files
.
File
,
error
)
{
stat
,
err
:=
file
.
Stat
()
stat
,
err
:=
file
.
Stat
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -311,7 +312,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
...
@@ -311,7 +312,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
// for non-directories, return a ReaderFile
// for non-directories, return a ReaderFile
if
!
stat
.
IsDir
()
{
if
!
stat
.
IsDir
()
{
return
&
cmds
.
ReaderFile
{
path
,
file
},
nil
return
&
cmds
Files
.
ReaderFile
{
path
,
file
},
nil
}
}
// for directories, recursively iterate though children then return as a SliceFile
// for directories, recursively iterate though children then return as a SliceFile
...
@@ -323,7 +324,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
...
@@ -323,7 +324,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
// make sure contents are sorted so -- repeatably -- we get the same inputs.
// make sure contents are sorted so -- repeatably -- we get the same inputs.
sort
.
Sort
(
sortFIByName
(
contents
))
sort
.
Sort
(
sortFIByName
(
contents
))
files
:=
make
([]
cmds
.
File
,
0
,
len
(
contents
))
files
:=
make
([]
cmds
Files
.
File
,
0
,
len
(
contents
))
for
_
,
child
:=
range
contents
{
for
_
,
child
:=
range
contents
{
childPath
:=
fp
.
Join
(
path
,
child
.
Name
())
childPath
:=
fp
.
Join
(
path
,
child
.
Name
())
childFile
,
err
:=
os
.
Open
(
childPath
)
childFile
,
err
:=
os
.
Open
(
childPath
)
...
@@ -339,7 +340,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
...
@@ -339,7 +340,7 @@ func openPath(file *os.File, path string) (cmds.File, error) {
files
=
append
(
files
,
f
)
files
=
append
(
files
,
f
)
}
}
return
&
cmds
.
SliceFile
{
path
,
files
},
nil
return
&
cmds
Files
.
SliceFile
{
path
,
files
},
nil
}
}
// isTerminal returns true if stdin is a Stdin pipe (e.g. `cat file | ipfs`),
// isTerminal returns true if stdin is a Stdin pipe (e.g. `cat file | ipfs`),
...
...
commands/files/file.go
0 → 100644
浏览文件 @
7a579bbf
package
files
import
(
"errors"
"io"
)
var
(
ErrNotDirectory
=
errors
.
New
(
"Couln't call NextFile(), this isn't a directory"
)
ErrNotReader
=
errors
.
New
(
"This file is a directory, can't use Reader functions"
)
)
// File is an interface that provides functionality for handling files/directories
// as values that can be supplied to commands. For directories, child files are
// accessed serially by calling `NextFile()`.
type
File
interface
{
// Files implement ReadCloser, but can only be read from or closed if they are not directories
io
.
ReadCloser
// FileName returns a full filename path associated with this file
FileName
()
string
// IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`)
// and false if the File is a normal file (and therefor supports calling `Read` and `Close`)
IsDirectory
()
bool
// NextFile returns the next child file available (if the File is a directory).
// It will return (nil, io.EOF) if no more files are available.
// If the file is a regular file (not a directory), NextFile will return a non-nil error.
NextFile
()
(
File
,
error
)
}
commands/file_test.go
→
commands/file
s/file
_test.go
浏览文件 @
7a579bbf
package
command
s
package
file
s
import
(
import
(
"io"
"io"
...
...
commands/file.go
→
commands/file
s/multipartfile
.go
浏览文件 @
7a579bbf
package
command
s
package
file
s
import
(
import
(
"errors"
"io"
"mime"
"mime"
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
...
@@ -15,31 +13,6 @@ const (
...
@@ -15,31 +13,6 @@ const (
contentTypeHeader
=
"Content-Type"
contentTypeHeader
=
"Content-Type"
)
)
var
(
ErrNotDirectory
=
errors
.
New
(
"Couln't call NextFile(), this isn't a directory"
)
ErrNotReader
=
errors
.
New
(
"This file is a directory, can't use Reader functions"
)
)
// File is an interface that provides functionality for handling files/directories
// as values that can be supplied to commands. For directories, child files are
// accessed serially by calling `NextFile()`.
type
File
interface
{
// Files implement ReadCloser, but can only be read from or closed if they are not directories
io
.
ReadCloser
// FileName returns a full filename path associated with this file
FileName
()
string
// IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`)
// and false if the File is a normal file (and therefor supports calling `Read` and `Close`)
IsDirectory
()
bool
// NextFile returns the next child file available (if the File is a directory).
// It will return (nil, io.EOF) if no more files are available.
// If the file is a regular file (not a directory), NextFile will return a non-nil error.
NextFile
()
(
File
,
error
)
}
// MultipartFile implements File, and is created from a `multipart.Part`.
// MultipartFile implements File, and is created from a `multipart.Part`.
// It can be either a directory or file (checked by calling `IsDirectory()`).
// It can be either a directory or file (checked by calling `IsDirectory()`).
type
MultipartFile
struct
{
type
MultipartFile
struct
{
...
@@ -110,67 +83,3 @@ func (f *MultipartFile) Close() error {
...
@@ -110,67 +83,3 @@ func (f *MultipartFile) Close() error {
}
}
return
f
.
Part
.
Close
()
return
f
.
Part
.
Close
()
}
}
// SliceFile implements File, and provides simple directory handling.
// It contains children files, and is created from a `[]File`.
// SliceFiles are always directories, and can't be read from or closed.
type
SliceFile
struct
{
Filename
string
Files
[]
File
}
func
(
f
*
SliceFile
)
IsDirectory
()
bool
{
return
true
}
func
(
f
*
SliceFile
)
NextFile
()
(
File
,
error
)
{
if
len
(
f
.
Files
)
==
0
{
return
nil
,
io
.
EOF
}
file
:=
f
.
Files
[
0
]
f
.
Files
=
f
.
Files
[
1
:
]
return
file
,
nil
}
func
(
f
*
SliceFile
)
FileName
()
string
{
return
f
.
Filename
}
func
(
f
*
SliceFile
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
return
0
,
ErrNotReader
}
func
(
f
*
SliceFile
)
Close
()
error
{
return
ErrNotReader
}
// ReaderFile is a implementation of File created from an `io.Reader`.
// ReaderFiles are never directories, and can be read from and closed.
type
ReaderFile
struct
{
Filename
string
Reader
io
.
Reader
}
func
(
f
*
ReaderFile
)
IsDirectory
()
bool
{
return
false
}
func
(
f
*
ReaderFile
)
NextFile
()
(
File
,
error
)
{
return
nil
,
ErrNotDirectory
}
func
(
f
*
ReaderFile
)
FileName
()
string
{
return
f
.
Filename
}
func
(
f
*
ReaderFile
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
return
f
.
Reader
.
Read
(
p
)
}
func
(
f
*
ReaderFile
)
Close
()
error
{
closer
,
ok
:=
f
.
Reader
.
(
io
.
Closer
)
if
!
ok
{
return
nil
}
return
closer
.
Close
()
}
commands/files/readerfile.go
0 → 100644
浏览文件 @
7a579bbf
package
files
import
"io"
// ReaderFile is a implementation of File created from an `io.Reader`.
// ReaderFiles are never directories, and can be read from and closed.
type
ReaderFile
struct
{
Filename
string
Reader
io
.
Reader
}
func
(
f
*
ReaderFile
)
IsDirectory
()
bool
{
return
false
}
func
(
f
*
ReaderFile
)
NextFile
()
(
File
,
error
)
{
return
nil
,
ErrNotDirectory
}
func
(
f
*
ReaderFile
)
FileName
()
string
{
return
f
.
Filename
}
func
(
f
*
ReaderFile
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
return
f
.
Reader
.
Read
(
p
)
}
func
(
f
*
ReaderFile
)
Close
()
error
{
closer
,
ok
:=
f
.
Reader
.
(
io
.
Closer
)
if
!
ok
{
return
nil
}
return
closer
.
Close
()
}
commands/files/slicefile.go
0 → 100644
浏览文件 @
7a579bbf
package
files
import
"io"
// SliceFile implements File, and provides simple directory handling.
// It contains children files, and is created from a `[]File`.
// SliceFiles are always directories, and can't be read from or closed.
type
SliceFile
struct
{
Filename
string
Files
[]
File
}
func
(
f
*
SliceFile
)
IsDirectory
()
bool
{
return
true
}
func
(
f
*
SliceFile
)
NextFile
()
(
File
,
error
)
{
if
len
(
f
.
Files
)
==
0
{
return
nil
,
io
.
EOF
}
file
:=
f
.
Files
[
0
]
f
.
Files
=
f
.
Files
[
1
:
]
return
file
,
nil
}
func
(
f
*
SliceFile
)
FileName
()
string
{
return
f
.
Filename
}
func
(
f
*
SliceFile
)
Read
(
p
[]
byte
)
(
int
,
error
)
{
return
0
,
ErrNotReader
}
func
(
f
*
SliceFile
)
Close
()
error
{
return
ErrNotReader
}
commands/http/multifilereader.go
浏览文件 @
7a579bbf
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"net/textproto"
"net/textproto"
"sync"
"sync"
cmds
"github.com/jbenet/go-ipfs/command
s"
files
"github.com/jbenet/go-ipfs/commands/file
s"
)
)
// MultiFileReader reads from a `commands.File` (which can be a directory of files
// MultiFileReader reads from a `commands.File` (which can be a directory of files
...
@@ -16,7 +16,7 @@ import (
...
@@ -16,7 +16,7 @@ import (
type
MultiFileReader
struct
{
type
MultiFileReader
struct
{
io
.
Reader
io
.
Reader
files
cmd
s
.
File
files
file
s
.
File
currentFile
io
.
Reader
currentFile
io
.
Reader
buf
bytes
.
Buffer
buf
bytes
.
Buffer
mpWriter
*
multipart
.
Writer
mpWriter
*
multipart
.
Writer
...
@@ -31,7 +31,7 @@ type MultiFileReader struct {
...
@@ -31,7 +31,7 @@ type MultiFileReader struct {
// NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`.
// NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`.
// If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data',
// If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data',
// if `form` is false, the Content-Type will be 'multipart/mixed'.
// if `form` is false, the Content-Type will be 'multipart/mixed'.
func
NewMultiFileReader
(
file
cmd
s
.
File
,
form
bool
)
*
MultiFileReader
{
func
NewMultiFileReader
(
file
file
s
.
File
,
form
bool
)
*
MultiFileReader
{
mfr
:=
&
MultiFileReader
{
mfr
:=
&
MultiFileReader
{
files
:
file
,
files
:
file
,
form
:
form
,
form
:
form
,
...
...
commands/http/parse.go
浏览文件 @
7a579bbf
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"strings"
"strings"
cmds
"github.com/jbenet/go-ipfs/commands"
cmds
"github.com/jbenet/go-ipfs/commands"
files
"github.com/jbenet/go-ipfs/commands/files"
)
)
// Parse parses the data in a http.Request and returns a command Request object
// Parse parses the data in a http.Request and returns a command Request object
...
@@ -94,9 +95,9 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
...
@@ -94,9 +95,9 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
contentType
:=
r
.
Header
.
Get
(
contentTypeHeader
)
contentType
:=
r
.
Header
.
Get
(
contentTypeHeader
)
mediatype
,
_
,
_
:=
mime
.
ParseMediaType
(
contentType
)
mediatype
,
_
,
_
:=
mime
.
ParseMediaType
(
contentType
)
var
f
*
cmd
s
.
MultipartFile
var
f
*
file
s
.
MultipartFile
if
mediatype
==
"multipart/form-data"
{
if
mediatype
==
"multipart/form-data"
{
f
=
&
cmd
s
.
MultipartFile
{
Mediatype
:
mediatype
}
f
=
&
file
s
.
MultipartFile
{
Mediatype
:
mediatype
}
f
.
Reader
,
err
=
r
.
MultipartReader
()
f
.
Reader
,
err
=
r
.
MultipartReader
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
commands/request.go
浏览文件 @
7a579bbf
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/commands/files"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/repo/config"
"github.com/jbenet/go-ipfs/repo/config"
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
...
@@ -71,8 +72,8 @@ type Request interface {
...
@@ -71,8 +72,8 @@ type Request interface {
SetOptions
(
opts
map
[
string
]
interface
{})
error
SetOptions
(
opts
map
[
string
]
interface
{})
error
Arguments
()
[]
string
Arguments
()
[]
string
SetArguments
([]
string
)
SetArguments
([]
string
)
Files
()
File
Files
()
files
.
File
SetFiles
(
File
)
SetFiles
(
files
.
File
)
Context
()
*
Context
Context
()
*
Context
SetContext
(
Context
)
SetContext
(
Context
)
Command
()
*
Command
Command
()
*
Command
...
@@ -84,7 +85,7 @@ type request struct {
...
@@ -84,7 +85,7 @@ type request struct {
path
[]
string
path
[]
string
options
optMap
options
optMap
arguments
[]
string
arguments
[]
string
files
File
files
files
.
File
cmd
*
Command
cmd
*
Command
ctx
Context
ctx
Context
optionDefs
map
[
string
]
Option
optionDefs
map
[
string
]
Option
...
@@ -159,11 +160,11 @@ func (r *request) SetArguments(args []string) {
...
@@ -159,11 +160,11 @@ func (r *request) SetArguments(args []string) {
r
.
arguments
=
args
r
.
arguments
=
args
}
}
func
(
r
*
request
)
Files
()
File
{
func
(
r
*
request
)
Files
()
files
.
File
{
return
r
.
files
return
r
.
files
}
}
func
(
r
*
request
)
SetFiles
(
f
File
)
{
func
(
r
*
request
)
SetFiles
(
f
files
.
File
)
{
r
.
files
=
f
r
.
files
=
f
}
}
...
@@ -259,7 +260,7 @@ func NewEmptyRequest() (Request, error) {
...
@@ -259,7 +260,7 @@ func NewEmptyRequest() (Request, error) {
// NewRequest returns a request initialized with given arguments
// NewRequest returns a request initialized with given arguments
// An non-nil error will be returned if the provided option values are invalid
// An non-nil error will be returned if the provided option values are invalid
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
string
,
file
File
,
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
string
,
file
files
.
File
,
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
if
path
==
nil
{
if
path
==
nil
{
path
=
make
([]
string
,
0
)
path
=
make
([]
string
,
0
)
}
}
...
...
core/commands/add.go
浏览文件 @
7a579bbf
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"path"
"path"
cmds
"github.com/jbenet/go-ipfs/commands"
cmds
"github.com/jbenet/go-ipfs/commands"
files
"github.com/jbenet/go-ipfs/commands/files"
core
"github.com/jbenet/go-ipfs/core"
core
"github.com/jbenet/go-ipfs/core"
importer
"github.com/jbenet/go-ipfs/importer"
importer
"github.com/jbenet/go-ipfs/importer"
"github.com/jbenet/go-ipfs/importer/chunk"
"github.com/jbenet/go-ipfs/importer/chunk"
...
@@ -138,7 +139,7 @@ func addNode(n *core.IpfsNode, node *dag.Node) error {
...
@@ -138,7 +139,7 @@ func addNode(n *core.IpfsNode, node *dag.Node) error {
return
nil
return
nil
}
}
func
addFile
(
n
*
core
.
IpfsNode
,
file
cmd
s
.
File
,
out
chan
interface
{})
(
*
dag
.
Node
,
error
)
{
func
addFile
(
n
*
core
.
IpfsNode
,
file
file
s
.
File
,
out
chan
interface
{})
(
*
dag
.
Node
,
error
)
{
if
file
.
IsDirectory
()
{
if
file
.
IsDirectory
()
{
return
addDir
(
n
,
file
,
out
)
return
addDir
(
n
,
file
,
out
)
}
}
...
@@ -155,7 +156,7 @@ func addFile(n *core.IpfsNode, file cmds.File, out chan interface{}) (*dag.Node,
...
@@ -155,7 +156,7 @@ func addFile(n *core.IpfsNode, file cmds.File, out chan interface{}) (*dag.Node,
return
dns
[
len
(
dns
)
-
1
],
nil
// last dag node is the file.
return
dns
[
len
(
dns
)
-
1
],
nil
// last dag node is the file.
}
}
func
addDir
(
n
*
core
.
IpfsNode
,
dir
cmd
s
.
File
,
out
chan
interface
{})
(
*
dag
.
Node
,
error
)
{
func
addDir
(
n
*
core
.
IpfsNode
,
dir
file
s
.
File
,
out
chan
interface
{})
(
*
dag
.
Node
,
error
)
{
log
.
Infof
(
"adding directory: %s"
,
dir
.
FileName
())
log
.
Infof
(
"adding directory: %s"
,
dir
.
FileName
())
tree
:=
&
dag
.
Node
{
Data
:
ft
.
FolderPBData
()}
tree
:=
&
dag
.
Node
{
Data
:
ft
.
FolderPBData
()}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论