...
1
2
3
4
5 package vfs
6
7 import (
8 "fmt"
9 "os"
10 "time"
11 )
12
13
14
15
16
17 func NewNameSpace() NameSpace {
18 ns := NameSpace{}
19 ns.Bind("/", &emptyVFS{}, "/", BindReplace)
20 return ns
21 }
22
23
24 type emptyVFS struct{}
25
26
27
28 func (e *emptyVFS) Open(path string) (ReadSeekCloser, error) {
29 if path == "/" {
30 return nil, fmt.Errorf("open: / is a directory")
31 }
32 return nil, os.ErrNotExist
33 }
34
35
36
37 func (e *emptyVFS) Stat(path string) (os.FileInfo, error) {
38 if path == "/" {
39 return e, nil
40 }
41 return nil, os.ErrNotExist
42 }
43
44 func (e *emptyVFS) Lstat(path string) (os.FileInfo, error) {
45 return e.Stat(path)
46 }
47
48
49 func (e *emptyVFS) ReadDir(path string) ([]os.FileInfo, error) {
50 if path == "/" {
51 return []os.FileInfo{}, nil
52 }
53 return nil, os.ErrNotExist
54 }
55
56 func (e *emptyVFS) String() string {
57 return "emptyVFS(/)"
58 }
59
60 func (e *emptyVFS) RootType(path string) RootType {
61 return ""
62 }
63
64
65
66
67 func (e *emptyVFS) Name() string {
68 return "/"
69 }
70
71 func (e *emptyVFS) Size() int64 {
72 return 0
73 }
74
75 func (e *emptyVFS) Mode() os.FileMode {
76 return os.ModeDir | os.ModePerm
77 }
78
79 func (e *emptyVFS) ModTime() time.Time {
80 return time.Time{}
81 }
82
83 func (e *emptyVFS) IsDir() bool {
84 return true
85 }
86
87 func (e *emptyVFS) Sys() interface{} {
88 return nil
89 }
90
View as plain text