-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
74 lines (67 loc) · 1.72 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
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
"time"
"github.com/hanwen/gitfs/fs"
"github.com/hanwen/gitfs/manifest"
"github.com/hanwen/go-fuse/fuse/nodefs"
)
func main() {
debug := flag.Bool("debug", false, "print FUSE debug data")
lazy := flag.Bool("lazy", true, "only read contents for reads")
disk := flag.Bool("disk", false, "don't use intermediate files")
gitRepo := flag.String("git_repo", "", "if set, mount a single repository.")
repo := flag.String("repo", "", "if set, mount a single manifest from repo repository.")
flag.Parse()
if len(flag.Args()) < 1 {
log.Fatalf("usage: %s MOUNT", os.Args[0])
}
tempDir, err := ioutil.TempDir("", "gitfs")
if err != nil {
log.Fatalf("TempDir: %v", err)
}
mntDir := flag.Args()[0]
opts := fs.GitFSOptions{
Lazy: *lazy,
Disk: *disk,
TempDir: tempDir,
}
var root nodefs.Node
if *repo != "" {
xml := filepath.Join(*repo, "manifest.xml")
m, err := manifest.ParseFile(xml)
if err != nil {
log.Fatalf("ParseFile(%q): %v", *repo, err)
}
root, err = fs.NewManifestFS(m, filepath.Join(*repo, "projects"), &opts)
if err != nil {
log.Fatalf("NewManifestFS: %v", err)
}
} else if *gitRepo != "" {
var err error
root, err = fs.NewGitFSRoot(*gitRepo, &opts)
if err != nil {
log.Fatalf("NewGitFSRoot: %v", err)
}
} else {
root = fs.NewMultiGitFSRoot(&opts)
}
server, _, err := nodefs.MountRoot(mntDir, root, &nodefs.Options{
EntryTimeout: time.Hour,
NegativeTimeout: time.Hour,
AttrTimeout: time.Hour,
PortableInodes: true,
})
if err != nil {
log.Fatalf("MountFileSystem: %v", err)
}
if *debug {
server.SetDebug(true)
}
log.Printf("Started git multi fs FUSE on %s", mntDir)
server.Serve()
}