-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir.go
61 lines (48 loc) · 1.12 KB
/
dir.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
package main
import (
"net/url"
"os"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
type Dir struct {
Filename string
Location string
}
var _ fs.Node = (*Dir)(nil)
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = 1
a.Mode = os.ModeDir | 0755
return nil
}
var _ fs.NodeStringLookuper = (*Dir)(nil)
func (d *Dir) Lookup(ctx context.Context, name string) (fs.Node, error) {
filename := d.Filename + "/" + name
location := d.Location + "/" + url.PathEscape(name)
if content, exists := Tree[location]; exists {
switch content.DType {
case fuse.DT_File:
return &File{
Filename: filename,
Location: location,
Size: uint64(content.Size),
}, nil
case fuse.DT_Dir:
return &Dir{
Filename: filename,
Location: location,
}, nil
default:
break
}
}
return nil, fuse.ENOENT
}
var _ fs.HandleReadDirAller = (*Dir)(nil)
func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
if content, exists := Tree[d.Location]; !exists || len(content.Children) == 0 {
RequestRoute(d.Location)
}
return Tree[d.Location].Children, nil
}