-
Notifications
You must be signed in to change notification settings - Fork 0
/
fourfuse.go
68 lines (56 loc) · 1.11 KB
/
fourfuse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"bazil.org/fuse"
"bazil.org/fuse/fs"
_ "bazil.org/fuse/fs/fstestutil"
fourfuse "github.com/dedeibel/fourfuse/lib"
)
func usage() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s MOUNTPOINT\n", os.Args[0])
}
func main() {
fourfuse.InitializeLogger()
fourfuse.UseSystemLocale()
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 {
usage()
os.Exit(2)
}
mountpoint := flag.Arg(0)
c, err := fuse.Mount(
mountpoint,
fuse.AsyncRead(),
fuse.FSName("4get"),
fuse.Subtype("4get"))
if err != nil {
log.Fatal(err)
}
defer c.Close()
registerCleanupHandler(mountpoint)
err = fs.Serve(c, fourfuse.NewFs(fourfuse.LoadBoards()))
if err != nil {
log.Fatal(err)
}
}
func cleanupFusemount(path string) {
if err := fuse.Unmount(path); err != nil {
log.Fatal(err)
}
}
func registerCleanupHandler(path string) {
sigtermChannel := make(chan os.Signal, 1)
signal.Notify(sigtermChannel, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigtermChannel
cleanupFusemount(path)
os.Exit(0)
}()
}