cmds: nicer error on no mountpoint
Juan Batiz-Benet committed
Nov 14, 2014 at 03:09 UTC
f30161b063feabb422056edfaedf8dfdda8e37e1
1 file changed
+20
-4
core/commands2/mount_unix.go
+20
-4
@@ -4,10 +4,11 @@ package commands
4
5
import (
6
"fmt"
7
+ "strings"
8
"time"
9
10
cmds "github.com/jbenet/go-ipfs/commands"
10
- "github.com/jbenet/go-ipfs/config"
11
+ config "github.com/jbenet/go-ipfs/config"
12
core "github.com/jbenet/go-ipfs/core"
13
ipns "github.com/jbenet/go-ipfs/fuse/ipns"
14
rofs "github.com/jbenet/go-ipfs/fuse/readonly"
@@ -17,6 +18,9 @@ import (
18
// TODO is this non-deterministic?
19
const mountTimeout = time.Second
20
21
+// fuseNoDirectory used to check the returning fuse error
22
+const fuseNoDirectory = "fusermount: failed to access mountpoint"
23
+
24
var mountCmd = &cmds.Command{
25
Helptext: cmds.HelpText{
26
Tagline: "Mounts IPFS to the filesystem (read-only)",
@@ -25,7 +29,7 @@ Mount ipfs at a read-only mountpoint on the OS (default: /ipfs and /ipns).
29
All ipfs objects will be accessible under that directory. Note that the
30
root will not be listable, as it is virtual. Access known paths directly.
31
28
-You may kave to create /ipfs and /ipfs before using 'ipfs mount':
32
+You may have to create /ipfs and /ipfs before using 'ipfs mount':
33
34
> sudo mkdir /ipfs /ipns
35
> sudo chown ` + "`" + `whoami` + "`" + ` /ipfs /ipns
@@ -36,6 +40,8 @@ Mount ipfs at a read-only mountpoint on the OS (default: /ipfs and /ipns).
40
All ipfs objects will be accessible under that directory. Note that the
41
root will not be listable, as it is virtual. Access known paths directly.
42
43
+You may have to create /ipfs and /ipfs before using 'ipfs mount':
44
+
45
> sudo mkdir /ipfs /ipns
46
> sudo chown ` + "`" + `whoami` + "`" + ` /ipfs /ipns
47
> ipfs mount
@@ -117,12 +123,22 @@ baz
123
124
nsdone := mountIpns(node, nsdir, fsdir)
125
126
+ fmtFuseErr := func(err error) error {
127
+ s := err.Error()
128
+ if strings.Contains(s, fuseNoDirectory) {
129
+ s = strings.Replace(s, `fusermount: "fusermount:`, "", -1)
130
+ s = strings.Replace(s, `\n", exit status 1`, "", -1)
131
+ return cmds.ClientError(s)
132
+ }
133
+ return err
134
+ }
135
+
136
// wait until mounts return an error (or timeout if successful)
137
select {
138
case err := <-fsdone:
123
- return nil, err
139
+ return nil, fmtFuseErr(err)
140
case err := <-nsdone:
125
- return nil, err
141
+ return nil, fmtFuseErr(err)
142
143
// mounted successfully, we timed out with no errors
144
case <-time.After(mountTimeout):