-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathempty.go
55 lines (45 loc) · 1.35 KB
/
empty.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
package vfs
import (
"errors"
"os"
"time"
)
type empty struct{}
// Open implements Opener. Since empty is an empty directory, all attempts to
// open a file will return errors.
func (empty) Open(name string) (ReadSeekCloser, error) {
if name == "/" {
return nil, errors.New("open: / is a directory")
}
return nil, os.ErrNotExist
}
// Stat returns os.FileInfo for an empty directory if the path is
// is root "/" or error. os.FileInfo is implemented by emptyVFS
func (e empty) Stat(path string) (os.FileInfo, error) {
if path == "/" {
return e, nil
}
return nil, os.ErrNotExist
}
func (e *empty) Lstat(path string) (os.FileInfo, error) {
return e.Stat(path)
}
// ReadDir returns an empty os.FileInfo slice for "/", else error.
func (empty) Readdir(path string) ([]os.FileInfo, error) {
if path == "/" {
return []os.FileInfo{}, nil
}
return nil, os.ErrNotExist
}
func (empty) String() string {
return "empty(/)"
}
// These functions below implement os.FileInfo for the single
// empty emulated directory.
func (empty) Name() string { return "/" }
func (empty) Size() int64 { return 0 }
func (empty) Mode() os.FileMode { return os.ModeDir | os.ModePerm }
func (empty) ModTime() time.Time { return time.Time{} }
func (empty) IsDir() bool { return true }
func (empty) Sys() interface{} { return nil }
var _ FileSystem = (*empty)(nil)