提交 8e7d9847 作者: Jeromy

updates from PR, tests tests tests!

上级 4de881a1
...@@ -42,11 +42,19 @@ order to reclaim hard disk space. ...@@ -42,11 +42,19 @@ order to reclaim hard disk space.
return nil, err return nil, err
} }
outChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context) gcOutChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context)
if err != nil { if err != nil {
return nil, err return nil, err
} }
outChan := make(chan interface{})
go func() {
defer close(outChan)
for k := range gcOutChan {
outChan <- k
}
}()
return outChan, nil return outChan, nil
}, },
Type: corerepo.KeyRemoved{}, Type: corerepo.KeyRemoved{},
......
...@@ -81,7 +81,7 @@ var rootSubcommands = map[string]*cmds.Command{ ...@@ -81,7 +81,7 @@ var rootSubcommands = map[string]*cmds.Command{
"pin": PinCmd, "pin": PinCmd,
"ping": PingCmd, "ping": PingCmd,
"refs": RefsCmd, "refs": RefsCmd,
"repo": RepoCmd, "repo": RepoCmd,
"swarm": SwarmCmd, "swarm": SwarmCmd,
"update": UpdateCmd, "update": UpdateCmd,
"version": VersionCmd, "version": VersionCmd,
......
...@@ -14,14 +14,14 @@ type KeyRemoved struct { ...@@ -14,14 +14,14 @@ type KeyRemoved struct {
Key u.Key Key u.Key
} }
func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan interface{}, error) { func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan *KeyRemoved, error) {
keychan, err := n.Blockstore.AllKeysChan(ctx, 0, 1<<16) keychan, err := n.Blockstore.AllKeysChan(ctx, 0, 1<<16)
if err != nil { if err != nil {
return nil, err return nil, err
} }
output := make(chan interface{}) output := make(chan *KeyRemoved)
go func() { go func() {
defer close(output) defer close(output)
for { for {
...@@ -34,6 +34,7 @@ func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan int ...@@ -34,6 +34,7 @@ func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan int
err := n.Blockstore.DeleteBlock(k) err := n.Blockstore.DeleteBlock(k)
if err != nil { if err != nil {
log.Errorf("Error removing key from blockstore: %s", err) log.Errorf("Error removing key from blockstore: %s", err)
continue
} }
select { select {
case output <- &KeyRemoved{k}: case output <- &KeyRemoved{k}:
......
...@@ -18,68 +18,111 @@ test_expect_success "'ipfs add afile' succeeds" ' ...@@ -18,68 +18,111 @@ test_expect_success "'ipfs add afile' succeeds" '
' '
test_expect_success "added file was pinned" ' test_expect_success "added file was pinned" '
ipfs pin ls -type=recursive | grep `cat hashfile` ipfs pin ls -type=recursive | grep $HASH
' '
test_expect_success "'ipfs repo gc' doesnt remove file" ' test_expect_success "'ipfs repo gc' doesnt remove file" '
ipfs repo gc echo -n "" > empty
ipfs cat `cat hashfile` > out ipfs repo gc > gc_out_actual
test_cmp empty gc_out_actual
ipfs cat $HASH > out
test_cmp out afile test_cmp out afile
' '
test_expect_success "'ipfs pin rm' succeeds" ' test_expect_success "'ipfs pin rm' succeeds" '
echo unpinned `cat hashfile` > expected1 echo unpinned $HASH > expected1
ipfs pin rm -r `cat hashfile` > actual1 ipfs pin rm -r $HASH > actual1
test_cmp expected1 actual1 test_cmp expected1 actual1
' '
test_expect_success "file no longer pinned" ' test_expect_success "file no longer pinned" '
echo -n "" > expected2
ipfs pin ls -type=recursive > actual2 ipfs pin ls -type=recursive > actual2
test_cmp expected2 actual2 test_cmp empty actual2
' '
test_expect_success "recursively pin afile" ' test_expect_success "recursively pin afile" '
ipfs pin add -r `cat hashfile` ipfs pin add -r $HASH
' '
test_expect_success "pinning directly should fail now" ' test_expect_success "pinning directly should fail now" '
echo Error: pin: `cat hashfile` already pinned recursively > expected3 echo Error: pin: $HASH already pinned recursively > expected3
ipfs pin add `cat hashfile` 2> actual3 ipfs pin add $HASH 2> actual3
test_cmp expected3 actual3 test_cmp expected3 actual3
' '
test_expect_success "'ipfs pin rm <hash>' should fail" ' test_expect_success "'ipfs pin rm <hash>' should fail" '
echo Error: `cat hashfile` is pinned recursively > expected4 echo Error: $HASH is pinned recursively > expected4
ipfs pin rm `cat hashfile` 2> actual4 ipfs pin rm $HASH 2> actual4
test_cmp expected4 actual4 test_cmp expected4 actual4
' '
test_expect_success "remove recursive pin, add direct" ' test_expect_success "remove recursive pin, add direct" '
echo unpinned `cat hashfile` > expected5 echo unpinned $HASH > expected5
ipfs pin rm -r `cat hashfile` > actual5 ipfs pin rm -r $HASH > actual5
test_cmp expected5 actual5 test_cmp expected5 actual5
ipfs pin add `cat hashfile` ipfs pin add $HASH
' '
test_expect_success "remove direct pin" ' test_expect_success "remove direct pin" '
echo unpinned `cat hashfile` > expected6 echo unpinned $HASH > expected6
ipfs pin rm `cat hashfile` > actual6 ipfs pin rm $HASH > actual6
test_cmp expected6 actual6 test_cmp expected6 actual6
' '
test_expect_success "'ipfs repo gc' removes file" ' test_expect_success "'ipfs repo gc' removes file" '
echo removed `cat hashfile` > expected7 echo removed $HASH > expected7
ipfs repo gc > actual7 ipfs repo gc > actual7
test_cmp expected7 actual7 test_cmp expected7 actual7
' '
test_expect_success "'ipfs refs local' no longer shows file" ' test_expect_success "'ipfs refs local' no longer shows file" '
echo -n "" > expected8
ipfs refs local > actual8 ipfs refs local > actual8
test_cmp expected8 actual8 test_cmp empty actual8
' '
test_expect_success "adding multiblock random file succeeds" '
random 1000000 > multiblock
MBLOCKHASH=`ipfs add -q multiblock`
'
test_expect_success "'ipfs pin ls -type=indirect' is correct" '
ipfs refs $MBLOCKHASH | sort > refsout
ipfs pin ls -type=indirect | sort > indirectpins
test_cmp refsout indirectpins
'
test_expect_success "pin something directly" '
echo "ipfs is so awesome" > awesome
DIRECTPIN=`ipfs add -q awesome`
echo unpinned $DIRECTPIN > expected9
ipfs pin rm -r $DIRECTPIN > actual9
test_cmp expected9 actual9
echo pinned $DIRECTPIN directly > expected10
ipfs pin add $DIRECTPIN > actual10
test_cmp expected10 actual10
'
test_expect_success "'ipfs pin ls -type=direct' is correct" '
echo $DIRECTPIN > directpinhash
ipfs pin ls -type=direct > directpinout
test_cmp directpinhash directpinout
'
test_expect_success "'ipfs pin ls -type=recursive' is correct" '
echo $MBLOCKHASH > rp_expected
ipfs pin ls -type=recursive > rp_actual
test_cmp rp_expected rp_actual
'
test_expect_success "'ipfs pin ls -type=all' is correct" '
cat directpinout > allpins
cat rp_actual >> allpins
cat indirectpins >> allpins
cat allpins | sort > allpins_sorted
ipfs pin ls -type=all | sort > actual_allpins
test_cmp allpins_sorted actual_allpins
'
test_kill_ipfs_daemon test_kill_ipfs_daemon
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论