-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.go
68 lines (56 loc) · 1.21 KB
/
file.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 (
"syscall"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"bazil.org/fuse/fuseutil"
"golang.org/x/net/context"
"taterbase.me/git-mount/git"
)
var (
_ Node = (*File)(nil)
_ fs.NodeOpener = (*File)(nil)
_ fs.Handle = (*File)(nil)
_ fs.HandleReader = (*File)(nil)
)
type File struct {
treeish string
name string
path string
length uint64
}
func (f *File) IsDir() bool {
return false
}
func (f *File) Name() string {
return f.name
}
func (f *File) Path() string {
return f.path
}
func (f *File) Attr(ctx context.Context, a *fuse.Attr) error {
a.Mode = 0444
a.Size = f.length
return nil
}
func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
if !req.Flags.IsReadOnly() {
return nil, fuse.Errno(syscall.EACCES)
}
resp.Flags |= fuse.OpenKeepCache
return f, nil
}
func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
content, err := git.ShowContents(f.treeish, f.Path())
if err != nil {
return err
}
fuseutil.HandleRead(req, resp, []byte(content))
return nil
}
type GitFS struct {
root fs.Node
}
func (gfs *GitFS) Root() (fs.Node, error) {
return gfs.root, nil
}