updates from PR, tests tests tests!
Jeromy committed
Jan 21, 2015 at 08:50 UTC
8e7d98475169b797a78c734527084a66b48530c6
4 files changed
+76
-24
core/commands/repo.go
+9
-1
@@ -42,11 +42,19 @@ order to reclaim hard disk space.
42
return nil, err
43
}
44
45
- outChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context)
45
+ gcOutChan, err := corerepo.GarbageCollectBlockstore(n, req.Context().Context)
46
if err != nil {
47
return nil, err
48
}
49
50
+ outChan := make(chan interface{})
51
+ go func() {
52
+ defer close(outChan)
53
+ for k := range gcOutChan {
54
+ outChan <- k
55
+ }
56
+ }()
57
+
58
return outChan, nil
59
},
60
Type: corerepo.KeyRemoved{},
core/commands/root.go
+1
-1
@@ -81,7 +81,7 @@ var rootSubcommands = map[string]*cmds.Command{
81
"pin": PinCmd,
82
"ping": PingCmd,
83
"refs": RefsCmd,
84
- "repo": RepoCmd,
84
+ "repo": RepoCmd,
85
"swarm": SwarmCmd,
86
"update": UpdateCmd,
87
"version": VersionCmd,
core/repo/gc.go
+3
-2
@@ -14,14 +14,14 @@ type KeyRemoved struct {
14
Key u.Key
15
}
16
17
-func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan interface{}, error) {
17
+func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan *KeyRemoved, error) {
18
19
keychan, err := n.Blockstore.AllKeysChan(ctx, 0, 1<<16)
20
if err != nil {
21
return nil, err
22
}
23
24
- output := make(chan interface{})
24
+ output := make(chan *KeyRemoved)
25
go func() {
26
defer close(output)
27
for {
@@ -34,6 +34,7 @@ func GarbageCollectBlockstore(n *core.IpfsNode, ctx context.Context) (<-chan int
34
err := n.Blockstore.DeleteBlock(k)
35
if err != nil {
36
log.Errorf("Error removing key from blockstore: %s", err)
37
+ continue
38
}
39
select {
40
case output <- &KeyRemoved{k}:
test/sharness/t0080-repo.sh
+63
-20
@@ -18,68 +18,111 @@ test_expect_success "'ipfs add afile' succeeds" '
18
'
19
20
test_expect_success "added file was pinned" '
21
- ipfs pin ls -type=recursive | grep `cat hashfile`
21
+ ipfs pin ls -type=recursive | grep $HASH
22
'
23
24
test_expect_success "'ipfs repo gc' doesnt remove file" '
25
- ipfs repo gc
26
- ipfs cat `cat hashfile` > out
25
+ echo -n "" > empty
26
+ ipfs repo gc > gc_out_actual
27
+ test_cmp empty gc_out_actual
28
+ ipfs cat $HASH > out
29
test_cmp out afile
30
'
31
32
test_expect_success "'ipfs pin rm' succeeds" '
31
- echo unpinned `cat hashfile` > expected1
32
- ipfs pin rm -r `cat hashfile` > actual1
33
+ echo unpinned $HASH > expected1
34
+ ipfs pin rm -r $HASH > actual1
35
test_cmp expected1 actual1
36
'
37
38
test_expect_success "file no longer pinned" '
37
- echo -n "" > expected2
39
ipfs pin ls -type=recursive > actual2
39
- test_cmp expected2 actual2
40
+ test_cmp empty actual2
41
'
42
43
test_expect_success "recursively pin afile" '
43
- ipfs pin add -r `cat hashfile`
44
+ ipfs pin add -r $HASH
45
'
46
47
test_expect_success "pinning directly should fail now" '
47
- echo Error: pin: `cat hashfile` already pinned recursively > expected3
48
- ipfs pin add `cat hashfile` 2> actual3
48
+ echo Error: pin: $HASH already pinned recursively > expected3
49
+ ipfs pin add $HASH 2> actual3
50
test_cmp expected3 actual3
51
'
52
53
test_expect_success "'ipfs pin rm <hash>' should fail" '
53
- echo Error: `cat hashfile` is pinned recursively > expected4
54
- ipfs pin rm `cat hashfile` 2> actual4
54
+ echo Error: $HASH is pinned recursively > expected4
55
+ ipfs pin rm $HASH 2> actual4
56
test_cmp expected4 actual4
57
'
58
59
test_expect_success "remove recursive pin, add direct" '
59
- echo unpinned `cat hashfile` > expected5
60
- ipfs pin rm -r `cat hashfile` > actual5
60
+ echo unpinned $HASH > expected5
61
+ ipfs pin rm -r $HASH > actual5
62
test_cmp expected5 actual5
62
- ipfs pin add `cat hashfile`
63
+ ipfs pin add $HASH
64
'
65
66
test_expect_success "remove direct pin" '
66
- echo unpinned `cat hashfile` > expected6
67
- ipfs pin rm `cat hashfile` > actual6
67
+ echo unpinned $HASH > expected6
68
+ ipfs pin rm $HASH > actual6
69
test_cmp expected6 actual6
70
'
71
72
test_expect_success "'ipfs repo gc' removes file" '
72
- echo removed `cat hashfile` > expected7
73
+ echo removed $HASH > expected7
74
ipfs repo gc > actual7
75
test_cmp expected7 actual7
76
'
77
78
test_expect_success "'ipfs refs local' no longer shows file" '
78
- echo -n "" > expected8
79
ipfs refs local > actual8
80
- test_cmp expected8 actual8
80
+ test_cmp empty actual8
81
'
82
83
+test_expect_success "adding multiblock random file succeeds" '
84
+ random 1000000 > multiblock
85
+ MBLOCKHASH=`ipfs add -q multiblock`
86
+'
87
+
88
+test_expect_success "'ipfs pin ls -type=indirect' is correct" '
89
+ ipfs refs $MBLOCKHASH | sort > refsout
90
+ ipfs pin ls -type=indirect | sort > indirectpins
91
+ test_cmp refsout indirectpins
92
+'
93
+
94
+test_expect_success "pin something directly" '
95
+ echo "ipfs is so awesome" > awesome
96
+ DIRECTPIN=`ipfs add -q awesome`
97
+ echo unpinned $DIRECTPIN > expected9
98
+ ipfs pin rm -r $DIRECTPIN > actual9
99
+ test_cmp expected9 actual9
100
+
101
+ echo pinned $DIRECTPIN directly > expected10
102
+ ipfs pin add $DIRECTPIN > actual10
103
+ test_cmp expected10 actual10
104
+'
105
+
106
+test_expect_success "'ipfs pin ls -type=direct' is correct" '
107
+ echo $DIRECTPIN > directpinhash
108
+ ipfs pin ls -type=direct > directpinout
109
+ test_cmp directpinhash directpinout
110
+'
111
+
112
+test_expect_success "'ipfs pin ls -type=recursive' is correct" '
113
+ echo $MBLOCKHASH > rp_expected
114
+ ipfs pin ls -type=recursive > rp_actual
115
+ test_cmp rp_expected rp_actual
116
+'
117
+
118
+test_expect_success "'ipfs pin ls -type=all' is correct" '
119
+ cat directpinout > allpins
120
+ cat rp_actual >> allpins
121
+ cat indirectpins >> allpins
122
+ cat allpins | sort > allpins_sorted
123
+ ipfs pin ls -type=all | sort > actual_allpins
124
+ test_cmp allpins_sorted actual_allpins
125
+'
126
127
test_kill_ipfs_daemon
128