Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c7462acc
提交
c7462acc
authored
5月 25, 2017
作者:
Jeromy Johnson
提交者:
GitHub
5月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3843 from ipfs/kevina/pin-verify
"pin verify".
上级
4cf046c4
b4a00872
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
143 行增加
和
0 行删除
+143
-0
pin.go
core/commands/pin.go
+143
-0
没有找到文件。
core/commands/pin.go
浏览文件 @
c7462acc
...
...
@@ -27,6 +27,7 @@ var PinCmd = &cmds.Command{
"add"
:
addPinCmd
,
"rm"
:
rmPinCmd
,
"ls"
:
listPinCmd
,
"verify"
:
verifyPinCmd
,
"update"
:
updatePinCmd
,
},
}
...
...
@@ -410,6 +411,64 @@ new pin and removing the old one.
},
}
var
verifyPinCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Verify that recursive pins are complete."
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"verbose"
,
"Also write the hashes of non-broken pins."
),
cmds
.
BoolOption
(
"quiet"
,
"q"
,
"Write just hashes of broken pins."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
verbose
,
_
,
_
:=
res
.
Request
()
.
Option
(
"verbose"
)
.
Bool
()
quiet
,
_
,
_
:=
res
.
Request
()
.
Option
(
"quiet"
)
.
Bool
()
if
verbose
&&
quiet
{
res
.
SetError
(
fmt
.
Errorf
(
"The --verbose and --quiet options can not be used at the same time"
),
cmds
.
ErrNormal
)
}
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
()
}
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
},
},
}
type
RefKeyObject
struct
{
Type
string
}
...
...
@@ -492,6 +551,90 @@ func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string
return
keys
,
nil
}
// PinVerifyRes is the result returned for each pin checked in "pin verify"
type
PinVerifyRes
struct
{
Cid
string
PinStatus
}
// PinStatus is part of PinVerifyRes, do not use directly
type
PinStatus
struct
{
Ok
bool
BadNodes
[]
BadNode
`json:",omitempty"`
}
// BadNode is used in PinVerifyRes
type
BadNode
struct
{
Cid
string
Err
string
}
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
)
PinStatus
checkPin
=
func
(
root
*
cid
.
Cid
)
PinStatus
{
key
:=
root
.
String
()
if
status
,
ok
:=
visited
[
key
];
ok
{
return
status
}
links
,
err
:=
getLinks
(
ctx
,
root
)
if
err
!=
nil
{
status
:=
PinStatus
{
Ok
:
false
}
if
opts
.
explain
{
status
.
BadNodes
=
[]
BadNode
{
BadNode
{
Cid
:
key
,
Err
:
err
.
Error
()}}
}
visited
[
key
]
=
status
return
status
}
status
:=
PinStatus
{
Ok
:
true
}
for
_
,
lnk
:=
range
links
{
res
:=
checkPin
(
lnk
.
Cid
)
if
!
res
.
Ok
{
status
.
Ok
=
false
status
.
BadNodes
=
append
(
status
.
BadNodes
,
res
.
BadNodes
...
)
}
}
visited
[
key
]
=
status
return
status
}
out
:=
make
(
chan
interface
{})
go
func
()
{
defer
close
(
out
)
for
_
,
cid
:=
range
recPins
{
pinStatus
:=
checkPin
(
cid
)
if
!
pinStatus
.
Ok
||
opts
.
includeOk
{
out
<-
&
PinVerifyRes
{
cid
.
String
(),
pinStatus
}
}
}
}()
return
out
}
// 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
.
Cid
)
for
_
,
e
:=
range
r
.
BadNodes
{
fmt
.
Fprintf
(
out
,
" %s: %s
\n
"
,
e
.
Cid
,
e
.
Err
)
}
}
}
func
cidsToStrings
(
cs
[]
*
cid
.
Cid
)
[]
string
{
out
:=
make
([]
string
,
0
,
len
(
cs
))
for
_
,
c
:=
range
cs
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论