simple nofuse build tag to allow freebsd compilation and maybe pave the way towards windows as well
Henry committed
Mar 4, 2015 at 23:59 UTC
66f1035d933fe0923dd07ad9046bf0ab0deb7133
13 files changed
+197
-116
core/commands/mount_nofuse.go
new
+23
@@ -0,0 +1,23 @@
1
+// +build (linux darwin freebsd) and nofuse
2
+
3
+package commands
4
+
5
+import (
6
+ "errors"
7
+
8
+ cmds "github.com/jbenet/go-ipfs/commands"
9
+ "github.com/jbenet/go-ipfs/core"
10
+)
11
+
12
+var MountCmd = &cmds.Command{
13
+ Helptext: cmds.HelpText{
14
+ Tagline: "Mounts IPFS to the filesystem (read-only) - !!Disabled!!",
15
+ ShortDescription: `
16
+Caution! Your version ipfs is compiled _without_ fuse support.
17
+`,
18
+ },
19
+}
20
+
21
+func Mount(node *core.IpfsNode, fsdir, nsdir string) error {
22
+ return errors.New("not compiled in")
23
+}
core/commands/mount_unix.go
+1
-1
@@ -1,4 +1,4 @@
1
-// +build linux darwin freebsd
1
+// +build (linux darwin freebsd) and !nofuse
2
3
package commands
4
fuse/ipns/ipns_test.go
+3
-1
@@ -1,15 +1,17 @@
1
+// +build !nofuse
2
+
3
package ipns
4
5
import (
6
"bytes"
7
"crypto/rand"
6
- context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
8
"io/ioutil"
9
"os"
10
"testing"
11
"time"
12
13
fstest "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil"
14
+ context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
15
16
core "github.com/jbenet/go-ipfs/core"
17
u "github.com/jbenet/go-ipfs/util"
fuse/ipns/ipns_unix.go
+2
@@ -1,3 +1,5 @@
1
+// +build !nofuse
2
+
3
// package fuse/ipns implements a fuse filesystem that interfaces
4
// with ipns, the naming system for ipfs.
5
package ipns
fuse/ipns/link_unix.go
+2
@@ -1,3 +1,5 @@
1
+// +build !nofuse
2
+
3
package ipns
4
5
import (
fuse/ipns/mount_unix.go
+1
-1
@@ -1,4 +1,4 @@
1
-// +build linux darwin freebsd
1
+// +build (linux darwin freebsd) and !nofuse
2
3
package ipns
4
fuse/ipns/nofuse.go
new
+38
@@ -0,0 +1,38 @@
1
+// +build nofuse
2
+
3
+package ipns
4
+
5
+import (
6
+ "errors"
7
+
8
+ "github.com/jbenet/go-ipfs/core"
9
+ ci "github.com/jbenet/go-ipfs/p2p/crypto"
10
+)
11
+
12
+// InitializeKeyspace sets the ipns record for the given key to
13
+// point to an empty directory.
14
+func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
15
+ // emptyDir := &mdag.Node{Data: ft.FolderPBData()}
16
+ // nodek, err := n.DAG.Add(emptyDir)
17
+ // if err != nil {
18
+ // return err
19
+ // }
20
+
21
+ // err = n.Pinning.Pin(emptyDir, false)
22
+ // if err != nil {
23
+ // return err
24
+ // }
25
+
26
+ // err = n.Pinning.Flush()
27
+ // if err != nil {
28
+ // return err
29
+ // }
30
+
31
+ // pub := nsys.NewRoutingPublisher(n.Routing)
32
+ // err = pub.Publish(n.Context(), key, nodek)
33
+ // if err != nil {
34
+ // return err
35
+ // }
36
+
37
+ return errors.New("how is this fuse related?")
38
+}
fuse/ipns/repub_unix.go
+2
@@ -1,3 +1,5 @@
1
+// +build !nofuse
2
+
3
package ipns
4
5
import "time"
fuse/mount/fuse.go
new
+121
@@ -0,0 +1,121 @@
1
+// +build !nofuse
2
+
3
+package mount
4
+
5
+import (
6
+ "fmt"
7
+ "time"
8
+
9
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
10
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
11
+ "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
12
+)
13
+
14
+// mount implements go-ipfs/fuse/mount
15
+type mount struct {
16
+ mpoint string
17
+ filesys fs.FS
18
+ fuseConn *fuse.Conn
19
+ // closeErr error
20
+
21
+ cg ctxgroup.ContextGroup
22
+}
23
+
24
+// Mount mounts a fuse fs.FS at a given location, and returns a Mount instance.
25
+// parent is a ContextGroup to bind the mount's ContextGroup to.
26
+func NewMount(p ctxgroup.ContextGroup, fsys fs.FS, mountpoint string) (Mount, error) {
27
+ conn, err := fuse.Mount(mountpoint)
28
+ if err != nil {
29
+ return nil, err
30
+ }
31
+
32
+ m := &mount{
33
+ mpoint: mountpoint,
34
+ fuseConn: conn,
35
+ filesys: fsys,
36
+ cg: ctxgroup.WithParent(p), // link it to parent.
37
+ }
38
+ m.cg.SetTeardown(m.unmount)
39
+
40
+ // launch the mounting process.
41
+ if err := m.mount(); err != nil {
42
+ m.Unmount() // just in case.
43
+ return nil, err
44
+ }
45
+
46
+ return m, nil
47
+}
48
+
49
+func (m *mount) mount() error {
50
+ log.Infof("Mounting %s", m.MountPoint())
51
+
52
+ errs := make(chan error, 1)
53
+ go func() {
54
+ err := fs.Serve(m.fuseConn, m.filesys)
55
+ log.Debugf("Mounting %s -- fs.Serve returned (%s)", err)
56
+ errs <- err
57
+ close(errs)
58
+ }()
59
+
60
+ // wait for the mount process to be done, or timed out.
61
+ select {
62
+ case <-time.After(MountTimeout):
63
+ return fmt.Errorf("Mounting %s timed out.", m.MountPoint())
64
+ case err := <-errs:
65
+ return err
66
+ case <-m.fuseConn.Ready:
67
+ }
68
+
69
+ // check if the mount process has an error to report
70
+ if err := m.fuseConn.MountError; err != nil {
71
+ return err
72
+ }
73
+
74
+ log.Infof("Mounted %s", m.MountPoint())
75
+ return nil
76
+}
77
+
78
+// umount is called exactly once to unmount this service.
79
+// note that closing the connection will not always unmount
80
+// properly. If that happens, we bring out the big guns
81
+// (mount.ForceUnmountManyTimes, exec unmount).
82
+func (m *mount) unmount() error {
83
+ log.Infof("Unmounting %s", m.MountPoint())
84
+
85
+ // try unmounting with fuse lib
86
+ err := fuse.Unmount(m.MountPoint())
87
+ if err == nil {
88
+ return nil
89
+ }
90
+ log.Debug("fuse unmount err: %s", err)
91
+
92
+ // try closing the fuseConn
93
+ err = m.fuseConn.Close()
94
+ if err == nil {
95
+ return nil
96
+ }
97
+ if err != nil {
98
+ log.Debug("fuse conn error: %s", err)
99
+ }
100
+
101
+ // try mount.ForceUnmountManyTimes
102
+ if err := ForceUnmountManyTimes(m, 10); err != nil {
103
+ return err
104
+ }
105
+
106
+ log.Infof("Seemingly unmounted %s", m.MountPoint())
107
+ return nil
108
+}
109
+
110
+func (m *mount) CtxGroup() ctxgroup.ContextGroup {
111
+ return m.cg
112
+}
113
+
114
+func (m *mount) MountPoint() string {
115
+ return m.mpoint
116
+}
117
+
118
+func (m *mount) Unmount() error {
119
+ // call ContextCloser Close(), which calls unmount() exactly once.
120
+ return m.cg.Close()
121
+}
fuse/mount/mount.go
-111
@@ -7,8 +7,6 @@ import (
7
"runtime"
8
"time"
9
10
- fuse "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
11
- fs "github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
10
ctxgroup "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
11
12
u "github.com/jbenet/go-ipfs/util"
@@ -31,115 +29,6 @@ type Mount interface {
29
CtxGroup() ctxgroup.ContextGroup
30
}
31
34
-// mount implements go-ipfs/fuse/mount
35
-type mount struct {
36
- mpoint string
37
- filesys fs.FS
38
- fuseConn *fuse.Conn
39
- // closeErr error
40
-
41
- cg ctxgroup.ContextGroup
42
-}
43
-
44
-// Mount mounts a fuse fs.FS at a given location, and returns a Mount instance.
45
-// parent is a ContextGroup to bind the mount's ContextGroup to.
46
-func NewMount(p ctxgroup.ContextGroup, fsys fs.FS, mountpoint string) (Mount, error) {
47
- conn, err := fuse.Mount(mountpoint)
48
- if err != nil {
49
- return nil, err
50
- }
51
-
52
- m := &mount{
53
- mpoint: mountpoint,
54
- fuseConn: conn,
55
- filesys: fsys,
56
- cg: ctxgroup.WithParent(p), // link it to parent.
57
- }
58
- m.cg.SetTeardown(m.unmount)
59
-
60
- // launch the mounting process.
61
- if err := m.mount(); err != nil {
62
- m.Unmount() // just in case.
63
- return nil, err
64
- }
65
-
66
- return m, nil
67
-}
68
-
69
-func (m *mount) mount() error {
70
- log.Infof("Mounting %s", m.MountPoint())
71
-
72
- errs := make(chan error, 1)
73
- go func() {
74
- err := fs.Serve(m.fuseConn, m.filesys)
75
- log.Debugf("Mounting %s -- fs.Serve returned (%s)", err)
76
- errs <- err
77
- close(errs)
78
- }()
79
-
80
- // wait for the mount process to be done, or timed out.
81
- select {
82
- case <-time.After(MountTimeout):
83
- return fmt.Errorf("Mounting %s timed out.", m.MountPoint())
84
- case err := <-errs:
85
- return err
86
- case <-m.fuseConn.Ready:
87
- }
88
-
89
- // check if the mount process has an error to report
90
- if err := m.fuseConn.MountError; err != nil {
91
- return err
92
- }
93
-
94
- log.Infof("Mounted %s", m.MountPoint())
95
- return nil
96
-}
97
-
98
-// umount is called exactly once to unmount this service.
99
-// note that closing the connection will not always unmount
100
-// properly. If that happens, we bring out the big guns
101
-// (mount.ForceUnmountManyTimes, exec unmount).
102
-func (m *mount) unmount() error {
103
- log.Infof("Unmounting %s", m.MountPoint())
104
-
105
- // try unmounting with fuse lib
106
- err := fuse.Unmount(m.MountPoint())
107
- if err == nil {
108
- return nil
109
- }
110
- log.Debug("fuse unmount err: %s", err)
111
-
112
- // try closing the fuseConn
113
- err = m.fuseConn.Close()
114
- if err == nil {
115
- return nil
116
- }
117
- if err != nil {
118
- log.Debug("fuse conn error: %s", err)
119
- }
120
-
121
- // try mount.ForceUnmountManyTimes
122
- if err := ForceUnmountManyTimes(m, 10); err != nil {
123
- return err
124
- }
125
-
126
- log.Infof("Seemingly unmounted %s", m.MountPoint())
127
- return nil
128
-}
129
-
130
-func (m *mount) CtxGroup() ctxgroup.ContextGroup {
131
- return m.cg
132
-}
133
-
134
-func (m *mount) MountPoint() string {
135
- return m.mpoint
136
-}
137
-
138
-func (m *mount) Unmount() error {
139
- // call ContextCloser Close(), which calls unmount() exactly once.
140
- return m.cg.Close()
141
-}
142
-
32
// ForceUnmount attempts to forcibly unmount a given mount.
33
// It does so by calling diskutil or fusermount directly.
34
func ForceUnmount(m Mount) error {
fuse/readonly/ipfs_test.go
+2
@@ -1,3 +1,5 @@
1
+// +build !nofuse
2
+
3
package readonly
4
5
import (
fuse/readonly/mount_unix.go
+1
-1
@@ -1,4 +1,4 @@
1
-// +build linux darwin freebsd
1
+// +build (linux darwin freebsd) and !nofuse
2
3
package readonly
4
fuse/readonly/readonly_unix.go
+1
-1
@@ -1,4 +1,4 @@
1
-// +build linux darwin freebsd
1
+// +build (linux darwin freebsd) and !nofuse
2
3
// package fuse/readonly implements a fuse filesystem to access files
4
// stored inside of ipfs.