Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9adcfe7b
提交
9adcfe7b
authored
1月 20, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
address concerns from PR
上级
ccb36277
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
35 行增加
和
26 行删除
+35
-26
pin.go
core/commands/pin.go
+10
-2
pinning.go
core/repo/pinning.go
+2
-2
pin.go
pin/pin.go
+5
-4
t0080-repo.sh
test/sharness/t0080-repo.sh
+18
-18
没有找到文件。
core/commands/pin.go
浏览文件 @
9adcfe7b
...
...
@@ -71,9 +71,17 @@ on disk.
return
nil
,
u
.
ErrCast
()
}
var
pintype
string
rec
,
_
,
_
:=
res
.
Request
()
.
Option
(
"recursive"
)
.
Bool
()
if
rec
{
pintype
=
"recursively"
}
else
{
pintype
=
"directly"
}
buf
:=
new
(
bytes
.
Buffer
)
for
_
,
k
:=
range
added
.
Pinned
{
fmt
.
Fprintf
(
buf
,
"
Pinned %s
\n
"
,
k
)
fmt
.
Fprintf
(
buf
,
"
pinned %s %s
\n
"
,
k
,
pintype
)
}
return
buf
,
nil
},
...
...
@@ -127,7 +135,7 @@ collected if needed.
buf
:=
new
(
bytes
.
Buffer
)
for
_
,
k
:=
range
added
.
Pinned
{
fmt
.
Fprintf
(
buf
,
"
U
npinned %s
\n
"
,
k
)
fmt
.
Fprintf
(
buf
,
"
u
npinned %s
\n
"
,
k
)
}
return
buf
,
nil
},
...
...
core/repo/pinning.go
浏览文件 @
9adcfe7b
...
...
@@ -14,7 +14,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
for
_
,
path
:=
range
paths
{
dagnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin
error: %v
"
,
err
)
return
nil
,
fmt
.
Errorf
(
"pin
: %s
"
,
err
)
}
dagnodes
=
append
(
dagnodes
,
dagnode
)
}
...
...
@@ -28,7 +28,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
err
=
n
.
Pinning
.
Pin
(
dagnode
,
recursive
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"pin: %
v
"
,
err
)
return
nil
,
fmt
.
Errorf
(
"pin: %
s
"
,
err
)
}
out
=
append
(
out
,
k
)
}
...
...
pin/pin.go
浏览文件 @
9adcfe7b
...
...
@@ -5,6 +5,7 @@ package pin
import
(
"encoding/json"
"errors"
"fmt"
"sync"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
...
...
@@ -103,7 +104,7 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
}
}
else
{
if
p
.
recursePin
.
HasKey
(
k
)
{
return
errors
.
New
(
"Key already pinned recursively."
)
return
fmt
.
Errorf
(
"%s already pinned recursively"
,
k
.
B58String
()
)
}
p
.
directPin
.
AddBlock
(
k
)
}
...
...
@@ -124,15 +125,15 @@ func (p *pinner) Unpin(k util.Key, recursive bool) error {
return
p
.
unpinLinks
(
node
)
}
else
{
return
errors
.
New
(
"Key pinned recursively."
)
return
fmt
.
Errorf
(
"%s is pinned recursively"
,
k
)
}
}
else
if
p
.
directPin
.
HasKey
(
k
)
{
p
.
directPin
.
RemoveBlock
(
k
)
return
nil
}
else
if
p
.
indirPin
.
HasKey
(
k
)
{
return
errors
.
New
(
"Cannot unpin indirectly pinned block."
)
return
fmt
.
Errorf
(
"%s is pinned indirectly. indirect pins cannot be removed directly"
,
k
)
}
else
{
return
errors
.
New
(
"Given key was not pinned."
)
return
fmt
.
Errorf
(
"%s is not pinned"
,
k
)
}
}
...
...
test/sharness/t0080-repo.sh
浏览文件 @
9adcfe7b
...
...
@@ -24,15 +24,15 @@ test_expect_success "added file was pinned" '
# TODO: run gc, then ipfs cat file, should still be there
test_expect_success
"'ipfs pin rm' succeeds"
'
echo
Unpinned `cat hashfile` > expected
ipfs pin rm -r `cat hashfile` > actual
test_cmp expected
actual
echo
unpinned `cat hashfile` > expected1
ipfs pin rm -r `cat hashfile` > actual
1
test_cmp expected
1 actual1
'
test_expect_success
"file no longer pinned"
'
echo -n "" > expected
ipfs pin ls -type=recursive > actual
test_cmp expected
actual
echo -n "" > expected
2
ipfs pin ls -type=recursive > actual
2
test_cmp expected
2 actual2
'
test_expect_success
"recursively pin afile"
'
...
...
@@ -40,28 +40,28 @@ test_expect_success "recursively pin afile" '
'
test_expect_success
"pinning directly should fail now"
'
echo
"Error: pin: Key already pinned recursively." > expected
ipfs pin add `cat hashfile` 2> actual
test_cmp expected
actual
echo
Error: pin: `cat hashfile` already pinned recursively > expected3
ipfs pin add `cat hashfile` 2> actual
3
test_cmp expected
3 actual3
'
test_expect_success
"'ipfs pin rm <hash>' should fail"
'
echo Error:
Key pinned recursively. > expected
ipfs pin rm `cat hashfile` 2>
error
test_cmp expected
error
echo Error:
`cat hashfile` is pinned recursively > expected4
ipfs pin rm `cat hashfile` 2>
actual4
test_cmp expected
4 actual4
'
test_expect_success
"remove recursive pin, add direct"
'
echo
Unpinned `cat hashfile` > expected
ipfs pin rm -r `cat hashfile` > actual
test_cmp expected
actual
echo
unpinned `cat hashfile` > expected5
ipfs pin rm -r `cat hashfile` > actual
5
test_cmp expected
5 actual5
ipfs pin add `cat hashfile`
'
test_expect_success
"remove direct pin"
'
echo
Unpinned `cat hashfile` > expected
ipfs pin rm `cat hashfile` > actual
test_cmp expected
actual
echo
unpinned `cat hashfile` > expected6
ipfs pin rm `cat hashfile` > actual
6
test_cmp expected
6 actual6
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论