Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
24e31760
提交
24e31760
authored
12月 18, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi/unixfs: Use path instead of raw hash in AddEvent
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
5a42289a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
66 行增加
和
46 行删除
+66
-46
add.go
core/commands/add.go
+27
-5
tar.go
core/commands/tar.go
+3
-4
path.go
core/coreapi/interface/path.go
+1
-0
unixfs.go
core/coreapi/interface/unixfs.go
+3
-4
unixfs_test.go
core/coreapi/unixfs_test.go
+24
-11
add.go
core/coreunix/add.go
+5
-19
add_test.go
core/coreunix/add_test.go
+3
-3
没有找到文件。
core/commands/add.go
浏览文件 @
24e31760
package
commands
import
(
"errors"
"fmt"
"io"
"os"
...
...
@@ -19,6 +20,13 @@ import (
// ErrDepthLimitExceeded indicates that the max depth has been exceeded.
var
ErrDepthLimitExceeded
=
fmt
.
Errorf
(
"depth limit exceeded"
)
type
AddEvent
struct
{
Name
string
Hash
string
`json:",omitempty"`
Bytes
int64
`json:",omitempty"`
Size
string
`json:",omitempty"`
}
const
(
quietOptionName
=
"quiet"
quieterOptionName
=
"quieter"
...
...
@@ -210,9 +218,23 @@ You can now check what blocks have been created by:
_
,
err
=
api
.
Unixfs
()
.
Add
(
req
.
Context
,
req
.
Files
,
opts
...
)
}()
err
=
res
.
Emit
(
events
)
if
err
!=
nil
{
return
err
for
event
:=
range
events
{
output
,
ok
:=
event
.
(
*
coreiface
.
AddEvent
)
if
!
ok
{
return
errors
.
New
(
"unknown event type"
)
}
h
:=
""
if
output
.
Path
!=
nil
{
h
=
output
.
Path
.
Cid
()
.
String
()
}
res
.
Emit
(
&
AddEvent
{
Name
:
output
.
Name
,
Hash
:
h
,
Bytes
:
output
.
Bytes
,
Size
:
output
.
Size
,
})
}
return
<-
errCh
...
...
@@ -269,7 +291,7 @@ You can now check what blocks have been created by:
break
LOOP
}
output
:=
out
.
(
*
coreiface
.
AddEvent
)
output
:=
out
.
(
*
AddEvent
)
if
len
(
output
.
Hash
)
>
0
{
lastHash
=
output
.
Hash
if
quieter
{
...
...
@@ -357,5 +379,5 @@ You can now check what blocks have been created by:
}
},
},
Type
:
coreiface
.
AddEvent
{},
Type
:
AddEvent
{},
}
core/commands/tar.go
浏览文件 @
24e31760
...
...
@@ -6,7 +6,6 @@ import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
tar
"github.com/ipfs/go-ipfs/tar"
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
...
...
@@ -57,14 +56,14 @@ represent it.
c
:=
node
.
Cid
()
return
cmds
.
EmitOnce
(
res
,
&
coreiface
.
AddEvent
{
return
cmds
.
EmitOnce
(
res
,
&
AddEvent
{
Name
:
it
.
Name
(),
Hash
:
c
.
String
(),
})
},
Type
:
coreiface
.
AddEvent
{},
Type
:
AddEvent
{},
Encoders
:
cmds
.
EncoderMap
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
coreiface
.
AddEvent
)
error
{
cmds
.
Text
:
cmds
.
MakeTypedEncoder
(
func
(
req
*
cmds
.
Request
,
w
io
.
Writer
,
out
*
AddEvent
)
error
{
fmt
.
Fprintln
(
w
,
out
.
Hash
)
return
nil
}),
...
...
core/coreapi/interface/path.go
浏览文件 @
24e31760
...
...
@@ -46,6 +46,7 @@ type ResolvedPath interface {
// cidRoot := {"A": {"/": cidA }}
//
// And resolve paths:
//
// * "/ipfs/${cidRoot}"
// * Calling Cid() will return `cidRoot`
// * Calling Root() will return `cidRoot`
...
...
core/coreapi/interface/unixfs.go
浏览文件 @
24e31760
...
...
@@ -9,12 +9,11 @@ import (
ipld
"gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
)
// TODO: ideas on making this more coreapi-ish without breaking the http API?
type
AddEvent
struct
{
Name
string
Hash
string
`json:",omitempty"`
Bytes
int64
`json:",omitempty"`
Size
string
`json:",omitempty"`
Path
ResolvedPath
`json:",omitempty"`
Bytes
int64
`json:",omitempty"`
Size
string
`json:",omitempty"`
}
// UnixfsAPI is the basic interface to immutable files in IPFS
...
...
core/coreapi/unixfs_test.go
浏览文件 @
24e31760
...
...
@@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"fmt"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
"io"
"io/ioutil"
"math"
...
...
@@ -178,6 +179,14 @@ func TestAdd(t *testing.T) {
t
.
Error
(
err
)
}
p
:=
func
(
h
string
)
coreiface
.
ResolvedPath
{
c
,
err
:=
cid
.
Parse
(
h
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
coreiface
.
IpfsPath
(
c
)
}
cases
:=
[]
struct
{
name
string
data
func
()
files
.
Node
...
...
@@ -406,7 +415,7 @@ func TestAdd(t *testing.T) {
data
:
strFile
(
helloStr
),
path
:
"/ipfs/zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd"
,
events
:
[]
coreiface
.
AddEvent
{
{
Name
:
"zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd"
,
Hash
:
"zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd"
,
Size
:
strconv
.
Itoa
(
len
(
helloStr
))},
{
Name
:
"zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd"
,
Path
:
p
(
"zb2rhdhmJjJZs9qkhQCpCQ7VREFkqWw3h1r8utjVvQugwHPFd"
)
,
Size
:
strconv
.
Itoa
(
len
(
helloStr
))},
},
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
RawLeaves
(
true
)},
},
...
...
@@ -415,8 +424,8 @@ func TestAdd(t *testing.T) {
data
:
twoLevelDir
(),
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
events
:
[]
coreiface
.
AddEvent
{
{
Name
:
"t/abc"
,
Hash
:
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
,
Size
:
"62"
},
{
Name
:
"t"
,
Hash
:
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
Size
:
"229"
},
{
Name
:
"t/abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
)
,
Size
:
"62"
},
{
Name
:
"t"
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
)
,
Size
:
"229"
},
},
wrap
:
"t"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Silent
(
true
)},
...
...
@@ -426,11 +435,11 @@ func TestAdd(t *testing.T) {
data
:
twoLevelDir
(),
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
events
:
[]
coreiface
.
AddEvent
{
{
Name
:
"t/abc/def"
,
Hash
:
"QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk"
,
Size
:
"13"
},
{
Name
:
"t/bar"
,
Hash
:
"QmS21GuXiRMvJKHos4ZkEmQDmRBqRaF5tQS2CQCu2ne9sY"
,
Size
:
"14"
},
{
Name
:
"t/foo"
,
Hash
:
"QmfAjGiVpTN56TXi6SBQtstit5BEw3sijKj1Qkxn6EXKzJ"
,
Size
:
"14"
},
{
Name
:
"t/abc"
,
Hash
:
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
,
Size
:
"62"
},
{
Name
:
"t"
,
Hash
:
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
Size
:
"229"
},
{
Name
:
"t/abc/def"
,
Path
:
p
(
"QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk"
)
,
Size
:
"13"
},
{
Name
:
"t/bar"
,
Path
:
p
(
"QmS21GuXiRMvJKHos4ZkEmQDmRBqRaF5tQS2CQCu2ne9sY"
)
,
Size
:
"14"
},
{
Name
:
"t/foo"
,
Path
:
p
(
"QmfAjGiVpTN56TXi6SBQtstit5BEw3sijKj1Qkxn6EXKzJ"
)
,
Size
:
"14"
},
{
Name
:
"t/abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
)
,
Size
:
"62"
},
{
Name
:
"t"
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
)
,
Size
:
"229"
},
},
wrap
:
"t"
,
},
...
...
@@ -445,7 +454,7 @@ func TestAdd(t *testing.T) {
{
Name
:
""
,
Bytes
:
524288
},
{
Name
:
""
,
Bytes
:
786432
},
{
Name
:
""
,
Bytes
:
1000000
},
{
Name
:
"QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD"
,
Hash
:
"QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD"
,
Size
:
"1000256"
},
{
Name
:
"QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD"
,
Path
:
p
(
"QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD"
)
,
Size
:
"1000256"
},
},
wrap
:
""
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Progress
(
true
)},
...
...
@@ -497,8 +506,12 @@ func TestAdd(t *testing.T) {
t
.
Errorf
(
"Event.Name didn't match, %s != %s"
,
expected
[
0
]
.
Name
,
event
.
Name
)
}
if
expected
[
0
]
.
Hash
!=
event
.
Hash
{
t
.
Errorf
(
"Event.Hash didn't match, %s != %s"
,
expected
[
0
]
.
Hash
,
event
.
Hash
)
if
expected
[
0
]
.
Path
!=
nil
&&
event
.
Path
!=
nil
{
if
expected
[
0
]
.
Path
.
Cid
()
.
String
()
!=
event
.
Path
.
Cid
()
.
String
()
{
t
.
Errorf
(
"Event.Hash didn't match, %s != %s"
,
expected
[
0
]
.
Path
,
event
.
Path
)
}
}
else
if
event
.
Path
!=
expected
[
0
]
.
Path
{
t
.
Errorf
(
"Event.Hash didn't match, %s != %s"
,
expected
[
0
]
.
Path
,
event
.
Path
)
}
if
expected
[
0
]
.
Bytes
!=
event
.
Bytes
{
t
.
Errorf
(
"Event.Bytes didn't match, %d != %d"
,
expected
[
0
]
.
Bytes
,
event
.
Bytes
)
...
...
core/coreunix/add.go
浏览文件 @
24e31760
...
...
@@ -41,12 +41,6 @@ type Link struct {
Size
uint64
}
type
Object
struct
{
Hash
string
Links
[]
Link
Size
string
}
// NewAdder Returns a new Adder used for a file add operation.
func
NewAdder
(
ctx
context
.
Context
,
p
pin
.
Pinner
,
bs
bstore
.
GCLocker
,
ds
ipld
.
DAGService
)
(
*
Adder
,
error
)
{
bufferedDS
:=
ipld
.
NewBufferedDAG
(
ctx
,
ds
)
...
...
@@ -580,7 +574,7 @@ func outputDagnode(out chan<- interface{}, name string, dn ipld.Node) error {
}
out
<-
&
coreiface
.
AddEvent
{
Hash
:
o
.
Has
h
,
Path
:
o
.
Pat
h
,
Name
:
name
,
Size
:
o
.
Size
,
}
...
...
@@ -589,24 +583,16 @@ func outputDagnode(out chan<- interface{}, name string, dn ipld.Node) error {
}
// from core/commands/object.go
func
getOutput
(
dagnode
ipld
.
Node
)
(
*
Objec
t
,
error
)
{
func
getOutput
(
dagnode
ipld
.
Node
)
(
*
coreiface
.
AddEven
t
,
error
)
{
c
:=
dagnode
.
Cid
()
s
,
err
:=
dagnode
.
Size
()
if
err
!=
nil
{
return
nil
,
err
}
output
:=
&
Object
{
Hash
:
c
.
String
(),
Size
:
strconv
.
FormatUint
(
s
,
10
),
Links
:
make
([]
Link
,
len
(
dagnode
.
Links
())),
}
for
i
,
link
:=
range
dagnode
.
Links
()
{
output
.
Links
[
i
]
=
Link
{
Name
:
link
.
Name
,
Size
:
link
.
Size
,
}
output
:=
&
coreiface
.
AddEvent
{
Path
:
coreiface
.
IpfsPath
(
c
),
Size
:
strconv
.
FormatUint
(
s
,
10
),
}
return
output
,
nil
...
...
core/coreunix/add_test.go
浏览文件 @
24e31760
...
...
@@ -100,7 +100,7 @@ func TestAddGCLive(t *testing.T) {
addedHashes
:=
make
(
map
[
string
]
struct
{})
select
{
case
o
:=
<-
out
:
addedHashes
[
o
.
(
*
coreiface
.
AddEvent
)
.
Hash
]
=
struct
{}{}
addedHashes
[
o
.
(
*
coreiface
.
AddEvent
)
.
Path
.
Cid
()
.
String
()
]
=
struct
{}{}
case
<-
addDone
:
t
.
Fatal
(
"add shouldnt complete yet"
)
}
...
...
@@ -128,7 +128,7 @@ func TestAddGCLive(t *testing.T) {
// receive next object from adder
o
:=
<-
out
addedHashes
[
o
.
(
*
coreiface
.
AddEvent
)
.
Hash
]
=
struct
{}{}
addedHashes
[
o
.
(
*
coreiface
.
AddEvent
)
.
Path
.
Cid
()
.
String
()
]
=
struct
{}{}
<-
gcstarted
...
...
@@ -144,7 +144,7 @@ func TestAddGCLive(t *testing.T) {
var
last
cid
.
Cid
for
a
:=
range
out
{
// wait for it to finish
c
,
err
:=
cid
.
Decode
(
a
.
(
*
coreiface
.
AddEvent
)
.
Hash
)
c
,
err
:=
cid
.
Decode
(
a
.
(
*
coreiface
.
AddEvent
)
.
Path
.
Cid
()
.
String
()
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论