/
empty_fs.go
77 lines (61 loc) · 1.5 KB
/
empty_fs.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
75
76
77
package sftp
import (
gosftp "github.com/pkg/sftp"
"io"
"os"
)
// EmptyFS is a [sftp.SimplifiedFS] that has no content at all.
type EmptyFS struct{}
func (e EmptyFS) List(_ string) (func([]os.FileInfo, int64) (int, error), error) {
return func(infos []os.FileInfo, i int64) (int, error) {
return 0, io.EOF
}, nil
}
func (e EmptyFS) rootFileInfo() os.FileInfo {
return topDirPath("/")
}
func (e EmptyFS) Lstat(path string) (os.FileInfo, error) {
if path == "/" {
return e.rootFileInfo(), nil
}
return nil, os.ErrInvalid
}
func (e EmptyFS) Stat(path string) (os.FileInfo, error) {
if path == "/" {
return e.rootFileInfo(), nil
}
return nil, os.ErrInvalid
}
func (e EmptyFS) ReadLink(path string) (os.FileInfo, error) {
if path == "/" {
return e.rootFileInfo(), nil
}
return nil, os.ErrInvalid
}
func (e EmptyFS) Read(_ string) (io.ReaderAt, error) {
return nil, os.ErrNotExist
}
func (e EmptyFS) Write(_ string) (io.WriterAt, error) {
return nil, os.ErrPermission
}
func (e EmptyFS) SetStat(_ string, _ gosftp.FileAttrFlags, _ *gosftp.FileStat) error {
return os.ErrPermission
}
func (e EmptyFS) Rename(_, _ string) error {
return os.ErrPermission
}
func (e EmptyFS) Rmdir(_ string) error {
return os.ErrPermission
}
func (e EmptyFS) Rm(_ string) error {
return os.ErrPermission
}
func (e EmptyFS) Mkdir(_ string) error {
return os.ErrPermission
}
func (e EmptyFS) Link(_, _ string) error {
return os.ErrPermission
}
func (e EmptyFS) Symlink(_, _ string) error {
return os.ErrPermission
}