Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8679af7a
提交
8679af7a
authored
8月 17, 2016
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"block rm": add "--force" and "--quiet" option
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
92f6747a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
65 行增加
和
4 行删除
+65
-4
block.go
core/commands/block.go
+21
-4
t0050-block.sh
test/sharness/t0050-block.sh
+44
-0
没有找到文件。
core/commands/block.go
浏览文件 @
8679af7a
...
...
@@ -13,6 +13,7 @@ import (
key
"github.com/ipfs/go-ipfs/blocks/key"
cmds
"github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/pin"
ds
"gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore"
mh
"gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
)
...
...
@@ -200,6 +201,10 @@ It takes a list of base58 encoded multihashs to remove.
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"hash"
,
true
,
true
,
"Bash58 encoded multihash of block(s) to remove."
),
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"force"
,
"f"
,
"Ignore nonexistent blocks."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"quiet"
,
"q"
,
"Write minimal output."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
...
...
@@ -207,6 +212,8 @@ It takes a list of base58 encoded multihashs to remove.
return
}
hashes
:=
req
.
Arguments
()
force
,
_
,
_
:=
req
.
Option
(
"force"
)
.
Bool
()
quiet
,
_
,
_
:=
req
.
Option
(
"quiet"
)
.
Bool
()
keys
:=
make
([]
key
.
Key
,
0
,
len
(
hashes
))
for
_
,
hash
:=
range
hashes
{
k
:=
key
.
B58KeyDecode
(
hash
)
...
...
@@ -217,7 +224,10 @@ It takes a list of base58 encoded multihashs to remove.
go
func
()
{
defer
close
(
outChan
)
pinning
:=
n
.
Pinning
err
:=
rmBlocks
(
n
.
Blockstore
,
pinning
,
outChan
,
keys
)
err
:=
rmBlocks
(
n
.
Blockstore
,
pinning
,
outChan
,
keys
,
rmBlocksOpts
{
quiet
:
quiet
,
force
:
force
,
})
if
err
!=
nil
{
outChan
<-
&
RemovedBlock
{
Error
:
err
.
Error
()}
}
...
...
@@ -260,7 +270,12 @@ type RemovedBlock struct {
Error
string
`json:",omitempty"`
}
func
rmBlocks
(
blocks
bs
.
GCBlockstore
,
pins
pin
.
Pinner
,
out
chan
<-
interface
{},
keys
[]
key
.
Key
)
error
{
type
rmBlocksOpts
struct
{
quiet
bool
force
bool
}
func
rmBlocks
(
blocks
bs
.
GCBlockstore
,
pins
pin
.
Pinner
,
out
chan
<-
interface
{},
keys
[]
key
.
Key
,
opts
rmBlocksOpts
)
error
{
unlocker
:=
blocks
.
GCLock
()
defer
unlocker
.
Unlock
()
...
...
@@ -271,9 +286,11 @@ func rmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, k
for
_
,
k
:=
range
stillOkay
{
err
:=
blocks
.
DeleteBlock
(
k
)
if
err
!=
nil
{
if
err
!=
nil
&&
opts
.
force
&&
(
err
==
bs
.
ErrNotFound
||
err
==
ds
.
ErrNotFound
)
{
// ignore non-existent blocks
}
else
if
err
!=
nil
{
out
<-
&
RemovedBlock
{
Hash
:
k
.
String
(),
Error
:
err
.
Error
()}
}
else
{
}
else
if
!
opts
.
quiet
{
out
<-
&
RemovedBlock
{
Hash
:
k
.
String
()}
}
}
...
...
test/sharness/t0050-block.sh
浏览文件 @
8679af7a
...
...
@@ -12,6 +12,10 @@ test_init_ipfs
HASH
=
"QmRKqGMAM6EZngbpjSqrvYzq5Qd8b1bSWymjSUY9zQSNDk"
#
# "block put tests"
#
test_expect_success
"'ipfs block put' succeeds"
'
echo "Hello Mars!" >expected_in &&
ipfs block put <expected_in >actual_out
...
...
@@ -22,6 +26,10 @@ test_expect_success "'ipfs block put' output looks good" '
test_cmp expected_out actual_out
'
#
# "block get" tests
#
test_expect_success
"'ipfs block get' succeeds"
'
ipfs block get $HASH >actual_in
'
...
...
@@ -30,6 +38,10 @@ test_expect_success "'ipfs block get' output looks good" '
test_cmp expected_in actual_in
'
#
# "block stat" tests
#
test_expect_success
"'ipfs block stat' succeeds"
'
ipfs block stat $HASH >actual_stat
'
...
...
@@ -40,6 +52,10 @@ test_expect_success "'ipfs block stat' output looks good" '
test_cmp expected_stat actual_stat
'
#
# "block rm" tests
#
test_expect_success
"'ipfs block rm' succeeds"
'
ipfs block rm $HASH >actual_rm
'
...
...
@@ -129,6 +145,34 @@ test_expect_success "error reported on removing non-existent block" '
grep -q "cannot remove $RANDOMHASH" block_rm_err
'
test_expect_success
"'add some blocks' succeeds"
'
echo "Hello Mars!" | ipfs block put &&
echo "Hello Venus!" | ipfs block put
'
test_expect_success
"multi-block 'ipfs block rm -f' with non existent blocks succeed"
'
ipfs block rm -f $HASH $RANDOMHASH $HASH2
'
test_expect_success
"existent blocks removed"
'
test_must_fail ipfs block stat $HASH &&
test_must_fail ipfs block stat $HASH2
'
test_expect_success
"'add some blocks' succeeds"
'
echo "Hello Mars!" | ipfs block put &&
echo "Hello Venus!" | ipfs block put
'
test_expect_success
"multi-block 'ipfs block rm -q' produces no output"
'
ipfs block rm -q $HASH $HASH2 > block_rm_out &&
test ! -s block_rm_out
'
#
# Misc tests
#
test_expect_success
"'ipfs block stat' with nothing from stdin doesnt crash"
'
test_expect_code 1 ipfs block stat < /dev/null 2> stat_out
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论