Prevents 'ipfs name publish' when /ipns is mounted.
License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io>
Stephen Whitmore committed
Feb 9, 2016 at 16:03 UTC
0afbd1857f6b5266dcbe488e30409462e913333e
3 files changed
+77
-4
core/commands/publish.go
+5
@@ -74,6 +74,11 @@ Publish an <ipfs-path> to another public key (not implemented):
74
}
75
}
76
77
+ if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() {
78
+ res.SetError(errors.New("You cannot manually publish while IPNS is mounted."), cmds.ErrNormal)
79
+ return
80
+ }
81
+
82
pstr := req.Arguments()[0]
83
84
if n.Identity == "" {
fuse/ipns/ipns_test.go
+1
-4
@@ -151,10 +151,7 @@ func TestIpnsLocalLink(t *testing.T) {
151
defer mnt.Close()
152
name := mnt.Dir + "/local"
153
154
- _, err := os.Stat(name)
155
- if err != nil {
156
- t.Fatal(err)
157
- }
154
+ checkExists(t, name)
155
156
linksto, err := os.Readlink(name)
157
if err != nil {
test/sharness/t0031-mount-publish.sh
new
+71
@@ -0,0 +1,71 @@
1
+#!/bin/sh
2
+#
3
+# MIT Licensed; see the LICENSE file in this repository.
4
+#
5
+
6
+test_description="Test mount command in conjunction with publishing"
7
+
8
+. lib/test-lib.sh
9
+
10
+# if in travis CI, dont test mount (no fuse)
11
+if ! test_have_prereq FUSE; then
12
+ skip_all='skipping mount tests, fuse not available'
13
+
14
+ test_done
15
+fi
16
+
17
+test_init_ipfs
18
+
19
+# start iptb
20
+iptb init -n 2 -f --bootstrap=star --port=$PORT_SWARM
21
+iptb start --wait
22
+BADDR="/ip4/127.0.0.1/tcp/$PORT_SWARM/ipfs/"
23
+ADDR1="${BADDR}$(iptb get id 0)"
24
+ADDR2="${BADDR}$(iptb get id 1)"
25
+
26
+# bootstrap to the iptb peers
27
+test_expect_success "bootstrap to iptb peers" '
28
+ ipfs bootstrap add '$ADDR1' &&
29
+ ipfs bootstrap add '$ADDR2'
30
+'
31
+
32
+# launch the daemon
33
+test_launch_ipfs_daemon
34
+
35
+# wait for peer bootstrapping
36
+# TODO(noffle): this is very fragile -- how can we wait for this to happen for sure?
37
+sleep 3
38
+
39
+# pre-mount publish
40
+HASH=$(echo 'hello warld' | ipfs add -q)
41
+test_expect_success "can publish before mounting /ipns" '
42
+ ipfs name publish '$HASH'
43
+'
44
+
45
+# mount
46
+test_mount_ipfs
47
+
48
+test_expect_success "cannot publish after mounting /ipns" '
49
+ echo "Error: You cannot manually publish while IPNS is mounted." >expected &&
50
+ test_must_fail ipfs name publish '$HASH' 2>actual &&
51
+ test_cmp expected actual
52
+'
53
+
54
+
55
+test_expect_success "unmount /ipns out-of-band" '
56
+ fusermount -u ipns
57
+'
58
+
59
+# wait a moment for the daemon to notice and clean up
60
+# TODO(noffle): this is very fragile -- how can we wait for this to happen for sure?
61
+sleep 2
62
+
63
+test_expect_success "can publish after unmounting /ipns" '
64
+ ipfs name publish '$HASH'
65
+'
66
+
67
+# clean-up
68
+test_kill_ipfs_daemon
69
+iptb stop
70
+
71
+test_done