-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
166 lines (129 loc) · 3.83 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"triggerfs/filesystem"
"triggerfs/parser"
"flag"
"time"
"log"
"os"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
)
const VERSION string = "0.1"
func main() {
// configfile
var configfile string
flag.StringVar(&configfile,"c", "config.conf", "config file")
flag.StringVar(&configfile,"config", "config.conf", "config file")
// title
var title string
flag.StringVar(&title,"title", "", "set title of fs")
// triggerFS options
sizecache := flag.Bool("sizecache", false, "enable file size caching")
nosizecache := flag.Bool("nosizecache", false, "disable file size caching")
prebuildcache := flag.Bool("prebuildcache", false, "create sizecache on startup")
noprebuildcache := flag.Bool("noprebuildcache", false, "don't create sizecache on startup")
updatetree := flag.Bool("updatetree", false, "add files matching patters to fs tree after they've been accessed once")
noupdatetree := flag.Bool("noupdatetree", false, "don't add files matching patters to fs tree after they've been accessed once")
version := flag.Bool("version", false, "print version and exit")
loglevel := flag.Int("loglvl", 0, "set loglevel 0-3")
//fuse options
gid := flag.Int("gid", os.Geteuid(), "set group id")
uid := flag.Int("uid", os.Getgid(), "set user id")
debug := flag.Bool("debug", false, "print fuse debugging messages")
ttl := flag.Float64("ttl", 1.0, "attribute/entry cache TTL")
flag.Parse()
log.SetOutput(os.Stdout)
if *version {
log.Printf("TriggerFS v%s\n", VERSION)
return
}
if len(flag.Args()) < 1 {
log.Println("Usage:\n triggerfs [<arg>] MOUNTPOINT\n")
log.Println("Arguments:")
flag.PrintDefaults()
os.Exit(2)
}
//logger := stdlog.GetFromFlags()
mountpoint := flag.Arg(0)
log.Printf("Starting TriggerFS v%s\n", VERSION)
log.Printf("Reading config: %s\n", configfile)
config := parser.Parseconfig(configfile)
// commandline args overwrite configfile options
if title != "" {
config.Title = title
}
if *loglevel > 0 {
config.LogLevel = int(*loglevel)
}
if *sizecache {
config.Caching = true
}
if *nosizecache {
config.Caching = false
}
if *prebuildcache {
config.PrebuildCache = true
}
if *noprebuildcache {
config.PrebuildCache = false
}
if *updatetree {
config.UpdateTree = true
}
if *noupdatetree {
config.UpdateTree = false
}
// set defaults
if config.Title == "" {
config.Title = "triggerfs"
}
// make fs and attach config
log.Println("Generating filesystem")
fs := filesystem.NewTriggerFS()
fs.BaseConf["triggerFS"] = config
fs.LogLevel = *loglevel
for path, cfg := range config.Dir {
attr := parser.ConfigToAttr(cfg, true)
fs.AddDir(path, attr)
}
for path, cfg := range config.File {
attr := parser.ConfigToAttr(cfg, false)
fs.AddFile(path, cfg.Exec, attr)
}
for path, cfg := range config.Pattern {
attr := parser.ConfigToAttr(cfg, false)
fs.AddPattern(path, cfg.Exec, attr)
}
//spew.Dump(config)
nfs := pathfs.NewPathNodeFs(fs, nil)
log.Println(nfs.String())
log.Printf("Mounting on %s\n", mountpoint)
// set mount options
opts := &nodefs.Options{
AttrTimeout: time.Duration(*ttl * float64(time.Second)),
EntryTimeout: time.Duration(*ttl * float64(time.Second)),
Debug: *debug,
LookupKnownChildren: false,
Owner: &fuse.Owner{
Uid: uint32(*uid),
Gid: uint32(*gid),
},
}
connector := nodefs.NewFileSystemConnector(nfs.Root(), opts)
// set fuse options
mountOpts := &fuse.MountOptions{
AllowOther: true,
DisableXAttrs: true,
Debug: *debug,
FsName: "triggerFS",
Name: config.Title,
}
server, err := fuse.NewServer(connector.RawFS(), mountpoint, mountOpts)
if err != nil {
log.Fatalf("ERROR Mount failed: %v\n", err)
}
log.Println("Filesystem ready.")
server.Serve()
}