/
mirrorfs-cli.go
70 lines (57 loc) · 1.21 KB
/
mirrorfs-cli.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
package main
import (
// "io"
"os"
"fmt"
"log"
"flag"
"bazil.org/fuse"
"bazil.org/fuse/fs"
// "golang.org/x/net/context"
"./fs"
)
// debug flag enables logging of debug messages to stderr.
var debug = flag.Bool("debug", false, "enable debug log messages to stderr")
var mirror = flag.String("mirror", "", "path to mirror contents (required)")
var mount = flag.String("mount", "", "path to mount volume (required)")
func usage() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
func debugLog(msg interface{}) {
fmt.Printf("%s", msg)
}
func main() {
flag.Usage = usage
flag.Parse()
if *mount == "" || *mirror == "" {
usage()
os.Exit(2)
}
c, err := fuse.Mount(
*mount,
fuse.FSName("mirrorfs"),
fuse.Subtype("mirrorfs"),
fuse.VolumeName("Mirror FS"),
// fuse.LocalVolume(),
fuse.AllowOther(),
)
if err != nil {
log.Fatal(err)
}
defer c.Close()
cfg := &fs.Config{}
if *debug {
cfg.Debug = debugLog
}
srv := fs.New(c, cfg)
filesys := mirrorfs.NewMirrorFS(*mirror)
if err := srv.Serve(filesys); err != nil {
log.Fatal(err)
}
// Check if the mount process has an error to report.
<-c.Ready
if err := c.MountError; err != nil {
log.Fatal(err)
}
}