Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b4a00872
提交
b4a00872
authored
5月 25, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"pin verify": fix API
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
7a4031dd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
74 行增加
和
38 行删除
+74
-38
pin.go
core/commands/pin.go
+74
-38
没有找到文件。
core/commands/pin.go
浏览文件 @
b4a00872
...
...
@@ -429,21 +429,43 @@ var verifyPinCmd = &cmds.Command{
verbose
,
_
,
_
:=
res
.
Request
()
.
Option
(
"verbose"
)
.
Bool
()
quiet
,
_
,
_
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
rdr
,
wtr
:=
io
.
Pipe
()
out
:=
pinVerify
(
req
.
Context
(),
n
)
if
verbose
&&
quiet
{
res
.
SetError
(
fmt
.
Errorf
(
"The --verbose and --quiet options can not be used at the same time"
),
cmds
.
ErrNormal
)
}
go
func
()
{
defer
wtr
.
Close
()
for
r
:=
range
out
{
if
quiet
&&
len
(
r
.
badNodes
)
>
0
{
fmt
.
Fprintf
(
wtr
,
"%s
\n
"
,
r
.
cid
)
}
else
if
!
quiet
{
r
.
Format
(
wtr
,
verbose
)
}
opts
:=
pinVerifyOpts
{
explain
:
!
quiet
,
includeOk
:
verbose
,
}
out
:=
pinVerify
(
req
.
Context
(),
n
,
opts
)
res
.
SetOutput
(
out
)
},
Type
:
PinVerifyRes
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
quiet
,
_
,
_
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
outChan
,
ok
:=
res
.
Output
()
.
(
<-
chan
interface
{})
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
}()
res
.
SetOutput
(
rdr
)
rdr
,
wtr
:=
io
.
Pipe
()
go
func
()
{
defer
wtr
.
Close
()
for
r0
:=
range
outChan
{
r
:=
r0
.
(
*
PinVerifyRes
)
if
quiet
&&
!
r
.
Ok
{
fmt
.
Fprintf
(
wtr
,
"%s
\n
"
,
r
.
Cid
)
}
else
if
!
quiet
{
r
.
Format
(
wtr
)
}
}
}()
return
rdr
,
nil
},
},
}
...
...
@@ -529,27 +551,36 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string
return
keys
,
nil
}
type
pinStatus
struct
{
badNodes
[]
badNode
// PinVerifyRes is the result returned for each pin checked in "pin verify"
type
PinVerifyRes
struct
{
Cid
string
PinStatus
}
type
badNode
struct
{
cid
*
cid
.
Cid
err
error
// PinStatus is part of PinVerifyRes, do not use directly
type
PinStatus
struct
{
Ok
bool
BadNodes
[]
BadNode
`json:",omitempty"`
}
type
pinVerifyRes
struct
{
cid
*
cid
.
Cid
pinStatus
// BadNode is used in PinVerifyRes
type
BadNode
struct
{
Cid
string
Err
string
}
func
pinVerify
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
)
<-
chan
pinVerifyRes
{
visited
:=
make
(
map
[
string
]
pinStatus
)
type
pinVerifyOpts
struct
{
explain
bool
includeOk
bool
}
func
pinVerify
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
opts
pinVerifyOpts
)
<-
chan
interface
{}
{
visited
:=
make
(
map
[
string
]
PinStatus
)
getLinks
:=
n
.
DAG
.
GetOfflineLinkService
()
.
GetLinks
recPins
:=
n
.
Pinning
.
RecursiveKeys
()
var
checkPin
func
(
root
*
cid
.
Cid
)
p
inStatus
checkPin
=
func
(
root
*
cid
.
Cid
)
p
inStatus
{
var
checkPin
func
(
root
*
cid
.
Cid
)
P
inStatus
checkPin
=
func
(
root
*
cid
.
Cid
)
P
inStatus
{
key
:=
root
.
String
()
if
status
,
ok
:=
visited
[
key
];
ok
{
return
status
...
...
@@ -557,16 +588,20 @@ func pinVerify(ctx context.Context, n *core.IpfsNode) <-chan pinVerifyRes {
links
,
err
:=
getLinks
(
ctx
,
root
)
if
err
!=
nil
{
status
:=
pinStatus
{[]
badNode
{
badNode
{
cid
:
root
,
err
:
err
}}}
status
:=
PinStatus
{
Ok
:
false
}
if
opts
.
explain
{
status
.
BadNodes
=
[]
BadNode
{
BadNode
{
Cid
:
key
,
Err
:
err
.
Error
()}}
}
visited
[
key
]
=
status
return
status
}
status
:=
pinStatus
{
}
status
:=
PinStatus
{
Ok
:
true
}
for
_
,
lnk
:=
range
links
{
res
:=
checkPin
(
lnk
.
Cid
)
if
len
(
res
.
badNodes
)
>
0
{
status
.
badNodes
=
append
(
status
.
badNodes
,
res
.
badNodes
...
)
if
!
res
.
Ok
{
status
.
Ok
=
false
status
.
BadNodes
=
append
(
status
.
BadNodes
,
res
.
BadNodes
...
)
}
}
...
...
@@ -574,27 +609,28 @@ func pinVerify(ctx context.Context, n *core.IpfsNode) <-chan pinVerifyRes {
return
status
}
out
:=
make
(
chan
pinVerifyRes
)
out
:=
make
(
chan
interface
{}
)
go
func
()
{
defer
close
(
out
)
for
_
,
cid
:=
range
recPins
{
pinStatus
:=
checkPin
(
cid
)
out
<-
pinVerifyRes
{
cid
,
pinStatus
}
if
!
pinStatus
.
Ok
||
opts
.
includeOk
{
out
<-
&
PinVerifyRes
{
cid
.
String
(),
pinStatus
}
}
}
}()
return
out
}
func
(
r
pinVerifyRes
)
Format
(
out
io
.
Writer
,
verbose
bool
)
{
if
len
(
r
.
badNodes
)
==
0
{
if
verbose
{
fmt
.
Fprintf
(
out
,
"%s ok
\n
"
,
r
.
cid
)
}
// Format formats PinVerifyRes
func
(
r
PinVerifyRes
)
Format
(
out
io
.
Writer
)
{
if
r
.
Ok
{
fmt
.
Fprintf
(
out
,
"%s ok
\n
"
,
r
.
Cid
)
}
else
{
fmt
.
Fprintf
(
out
,
"%s broken
\n
"
,
r
.
c
id
)
for
_
,
e
:=
range
r
.
b
adNodes
{
fmt
.
Fprintf
(
out
,
" %s: %s
\n
"
,
e
.
cid
,
e
.
e
rr
)
fmt
.
Fprintf
(
out
,
"%s broken
\n
"
,
r
.
C
id
)
for
_
,
e
:=
range
r
.
B
adNodes
{
fmt
.
Fprintf
(
out
,
" %s: %s
\n
"
,
e
.
Cid
,
e
.
E
rr
)
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论