Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f796ee45
提交
f796ee45
authored
5月 15, 2016
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2699 from ipfs/use-consts-for-pin-modes
Use consts for pin modes
上级
c390c88b
39f23677
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
63 行增加
和
21 行删除
+63
-21
pin.go
core/commands/pin.go
+7
-1
pin.go
pin/pin.go
+56
-20
没有找到文件。
core/commands/pin.go
浏览文件 @
f796ee45
...
...
@@ -11,6 +11,7 @@ import (
corerepo
"github.com/ipfs/go-ipfs/core/corerepo"
dag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
pin
"github.com/ipfs/go-ipfs/pin"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
...
...
@@ -273,7 +274,12 @@ func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsN
return
nil
,
err
}
pinType
,
pinned
,
err
:=
n
.
Pinning
.
IsPinnedWithType
(
k
,
typeStr
)
mode
,
ok
:=
pin
.
StringToPinMode
(
typeStr
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid pin mode '%s'"
,
typeStr
)
}
pinType
,
pinned
,
err
:=
n
.
Pinning
.
IsPinnedWithType
(
k
,
mode
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pin/pin.go
浏览文件 @
f796ee45
...
...
@@ -22,8 +22,13 @@ var pinDatastoreKey = ds.NewKey("/local/pins")
var
emptyKey
=
key
.
B58KeyDecode
(
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
)
const
(
linkDirect
=
"direct"
linkRecursive
=
"recursive"
linkDirect
=
"direct"
linkIndirect
=
"indirect"
linkInternal
=
"internal"
linkNotPinned
=
"not pinned"
linkAny
=
"any"
linkAll
=
"all"
)
type
PinMode
int
...
...
@@ -31,12 +36,42 @@ type PinMode int
const
(
Recursive
PinMode
=
iota
Direct
Indirect
Internal
NotPinned
Any
)
func
PinModeToString
(
mode
PinMode
)
(
string
,
bool
)
{
m
:=
map
[
PinMode
]
string
{
Recursive
:
linkRecursive
,
Direct
:
linkDirect
,
Indirect
:
linkIndirect
,
Internal
:
linkInternal
,
NotPinned
:
linkNotPinned
,
Any
:
linkAny
,
}
s
,
ok
:=
m
[
mode
]
return
s
,
ok
}
func
StringToPinMode
(
s
string
)
(
PinMode
,
bool
)
{
m
:=
map
[
string
]
PinMode
{
linkRecursive
:
Recursive
,
linkDirect
:
Direct
,
linkIndirect
:
Indirect
,
linkInternal
:
Internal
,
linkNotPinned
:
NotPinned
,
linkAny
:
Any
,
linkAll
:
Any
,
// "all" and "any" means the same thing
}
mode
,
ok
:=
m
[
s
]
return
mode
,
ok
}
type
Pinner
interface
{
IsPinned
(
key
.
Key
)
(
string
,
bool
,
error
)
IsPinnedWithType
(
key
.
Key
,
string
)
(
string
,
bool
,
error
)
IsPinnedWithType
(
key
.
Key
,
PinMode
)
(
string
,
bool
,
error
)
Pin
(
context
.
Context
,
*
mdag
.
Node
,
bool
)
error
Unpin
(
context
.
Context
,
key
.
Key
,
bool
)
error
...
...
@@ -129,7 +164,7 @@ var ErrNotPinned = fmt.Errorf("not pinned")
func
(
p
*
pinner
)
Unpin
(
ctx
context
.
Context
,
k
key
.
Key
,
recursive
bool
)
error
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
reason
,
pinned
,
err
:=
p
.
isPinnedWithType
(
k
,
"all"
)
reason
,
pinned
,
err
:=
p
.
isPinnedWithType
(
k
,
Any
)
if
err
!=
nil
{
return
err
}
...
...
@@ -162,46 +197,47 @@ func (p *pinner) isInternalPin(key key.Key) bool {
func
(
p
*
pinner
)
IsPinned
(
k
key
.
Key
)
(
string
,
bool
,
error
)
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
isPinnedWithType
(
k
,
"all"
)
return
p
.
isPinnedWithType
(
k
,
Any
)
}
func
(
p
*
pinner
)
IsPinnedWithType
(
k
key
.
Key
,
typeStr
string
)
(
string
,
bool
,
error
)
{
func
(
p
*
pinner
)
IsPinnedWithType
(
k
key
.
Key
,
mode
PinMode
)
(
string
,
bool
,
error
)
{
p
.
lock
.
RLock
()
defer
p
.
lock
.
RUnlock
()
return
p
.
isPinnedWithType
(
k
,
typeStr
)
return
p
.
isPinnedWithType
(
k
,
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
(
k
key
.
Key
,
typeStr
string
)
(
string
,
bool
,
error
)
{
switch
typeStr
{
case
"all"
,
"direct"
,
"indirect"
,
"recursive"
,
"internal"
:
func
(
p
*
pinner
)
isPinnedWithType
(
k
key
.
Key
,
mode
PinMode
)
(
string
,
bool
,
error
)
{
switch
mode
{
case
Any
,
Direct
,
Indirect
,
Recursive
,
Internal
:
default
:
err
:=
fmt
.
Errorf
(
"Invalid type '%s', must be one of {direct, indirect, recursive, internal, all}"
,
typeStr
)
err
:=
fmt
.
Errorf
(
"Invalid Pin Mode '%d', must be one of {%d, %d, %d, %d, %d}"
,
mode
,
Direct
,
Indirect
,
Recursive
,
Internal
,
Any
)
return
""
,
false
,
err
}
if
(
typeStr
==
"recursive"
||
typeStr
==
"all"
)
&&
p
.
recursePin
.
HasKey
(
k
)
{
return
"recursive"
,
true
,
nil
if
(
mode
==
Recursive
||
mode
==
Any
)
&&
p
.
recursePin
.
HasKey
(
k
)
{
return
linkRecursive
,
true
,
nil
}
if
typeStr
==
"recursive"
{
if
mode
==
Recursive
{
return
""
,
false
,
nil
}
if
(
typeStr
==
"direct"
||
typeStr
==
"all"
)
&&
p
.
directPin
.
HasKey
(
k
)
{
return
"direct"
,
true
,
nil
if
(
mode
==
Direct
||
mode
==
Any
)
&&
p
.
directPin
.
HasKey
(
k
)
{
return
linkDirect
,
true
,
nil
}
if
typeStr
==
"direct"
{
if
mode
==
Direct
{
return
""
,
false
,
nil
}
if
(
typeStr
==
"internal"
||
typeStr
==
"all"
)
&&
p
.
isInternalPin
(
k
)
{
return
"internal"
,
true
,
nil
if
(
mode
==
Internal
||
mode
==
Any
)
&&
p
.
isInternalPin
(
k
)
{
return
linkInternal
,
true
,
nil
}
if
typeStr
==
"internal"
{
if
mode
==
Internal
{
return
""
,
false
,
nil
}
// Default is
"indirect"
// Default is
Indirect
for
_
,
rk
:=
range
p
.
recursePin
.
GetKeys
()
{
rnd
,
err
:=
p
.
dserv
.
Get
(
context
.
Background
(),
rk
)
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论