Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cd7c83a1
Unverified
提交
cd7c83a1
authored
11月 18, 2019
作者:
Michael Muré
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pin: fix a too aggressive refactor and connect some contexts
上级
097b684b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
8 行删除
+10
-8
pin.go
pin/pin.go
+10
-8
没有找到文件。
pin/pin.go
浏览文件 @
cd7c83a1
...
...
@@ -281,7 +281,9 @@ func (p *pinner) isInternalPin(c cid.Cid) bool {
// IsPinned returns whether or not the given key is pinned
// and an explanation of why its pinned
func
(
p
*
pinner
)
IsPinned
(
ctx
context
.
Context
,
c
cid
.
Cid
)
(
string
,
bool
,
error
)
{
return
p
.
isPinnedWithType
(
c
,
Any
)
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
isPinnedWithType
(
ctx
,
c
,
Any
)
}
// IsPinnedWithType returns whether or not the given cid is pinned with the
...
...
@@ -289,12 +291,12 @@ func (p *pinner) IsPinned(ctx context.Context, c cid.Cid) (string, bool, error)
func
(
p
*
pinner
)
IsPinnedWithType
(
ctx
context
.
Context
,
c
cid
.
Cid
,
mode
Mode
)
(
string
,
bool
,
error
)
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
isPinnedWithType
(
c
,
mode
)
return
p
.
isPinnedWithType
(
c
tx
,
c
,
mode
)
}
// isPinnedWithType is the implementation of IsPinnedWithType that does not lock.
// intended for use by other pinned methods that already take locks
func
(
p
*
pinner
)
isPinnedWithType
(
c
cid
.
Cid
,
mode
Mode
)
(
string
,
bool
,
error
)
{
func
(
p
*
pinner
)
isPinnedWithType
(
c
tx
context
.
Context
,
c
cid
.
Cid
,
mode
Mode
)
(
string
,
bool
,
error
)
{
switch
mode
{
case
Any
,
Direct
,
Indirect
,
Recursive
,
Internal
:
default
:
...
...
@@ -326,7 +328,7 @@ func (p *pinner) isPinnedWithType(c cid.Cid, mode Mode) (string, bool, error) {
// Default is Indirect
visitedSet
:=
cid
.
NewSet
()
for
_
,
rc
:=
range
p
.
recursePin
.
Keys
()
{
has
,
err
:=
hasChild
(
p
.
dserv
,
rc
,
c
,
visitedSet
.
Visit
)
has
,
err
:=
hasChild
(
ctx
,
p
.
dserv
,
rc
,
c
,
visitedSet
.
Visit
)
if
err
!=
nil
{
return
""
,
false
,
err
}
...
...
@@ -361,7 +363,7 @@ func (p *pinner) CheckIfPinned(ctx context.Context, cids ...cid.Cid) ([]Pinned,
// Now walk all recursive pins to check for indirect pins
var
checkChildren
func
(
cid
.
Cid
,
cid
.
Cid
)
error
checkChildren
=
func
(
rk
,
parentKey
cid
.
Cid
)
error
{
links
,
err
:=
ipld
.
GetLinks
(
c
ontext
.
TODO
()
,
p
.
dserv
,
parentKey
)
links
,
err
:=
ipld
.
GetLinks
(
c
tx
,
p
.
dserv
,
parentKey
)
if
err
!=
nil
{
return
err
}
...
...
@@ -607,8 +609,8 @@ func (p *pinner) PinWithMode(c cid.Cid, mode Mode) {
// hasChild recursively looks for a Cid among the children of a root Cid.
// The visit function can be used to shortcut already-visited branches.
func
hasChild
(
ng
ipld
.
NodeGetter
,
root
cid
.
Cid
,
child
cid
.
Cid
,
visit
func
(
cid
.
Cid
)
bool
)
(
bool
,
error
)
{
links
,
err
:=
ipld
.
GetLinks
(
c
ontext
.
TODO
()
,
ng
,
root
)
func
hasChild
(
ctx
context
.
Context
,
ng
ipld
.
NodeGetter
,
root
cid
.
Cid
,
child
cid
.
Cid
,
visit
func
(
cid
.
Cid
)
bool
)
(
bool
,
error
)
{
links
,
err
:=
ipld
.
GetLinks
(
c
tx
,
ng
,
root
)
if
err
!=
nil
{
return
false
,
err
}
...
...
@@ -618,7 +620,7 @@ func hasChild(ng ipld.NodeGetter, root cid.Cid, child cid.Cid, visit func(cid.Ci
return
true
,
nil
}
if
visit
(
c
)
{
has
,
err
:=
hasChild
(
ng
,
c
,
child
,
visit
)
has
,
err
:=
hasChild
(
ctx
,
ng
,
c
,
child
,
visit
)
if
err
!=
nil
{
return
false
,
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论