-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (75 loc) · 1.4 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"fmt"
"log"
"os"
"os/user"
"bazil.org/fuse"
"bazil.org/fuse/fs"
)
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s MOUNTPOINT\n", os.Args[0])
flag.PrintDefaults()
}
func dbg(msg interface{}) {
log.Println(msg)
}
func exists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
return false
}
func main() {
flag.Usage = Usage
flag.Parse()
if flag.NArg() != 1 {
Usage()
os.Exit(2)
}
you, err := user.Current()
if err != nil {
log.Fatal(err)
}
if !exists(you.HomeDir + "/fstorage") {
err := os.Mkdir(you.HomeDir + "/fstorage", 0700)
if err != nil {
log.Fatal(err)
}
}
if !exists(you.HomeDir + "/fstorage/files") {
err := os.Mkdir(you.HomeDir + "/fstorage/files", 0700)
if err != nil {
log.Fatal(err)
}
}
myfs, err := newfs(you.HomeDir + "/fstorage")
if err != nil {
log.Fatal(err)
}
defer myfs.CloseBolt()
myfs.DatabaseIDPrompt()
err = myfs.SpawnAdminConsole()
if err != nil {
log.Fatal(err)
}
mountpoint := flag.Arg(0)
c, err := fuse.Mount(mountpoint)
if err != nil {
log.Fatal(err)
}
log.Println("fs ready, dbid", myfs.dbid, "(admin console: nc localhost 2000)")
server := fs.Server{
FS: myfs,
// Debug: dbg,
}
server.Serve(c)
<-c.Ready
if err := c.MountError; err != nil {
log.Fatal(err)
}
log.Println("fs shut down nicely")
}