/
storage-defs.go
94 lines (71 loc) 路 2.55 KB
/
storage-defs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package storage
import (
"io/fs"
"os"
)
type filepathAPI interface {
// Intended only for those filepath methods that actually affect the
// filesystem. Eg: there is no point in replicating methods like
// filepath.Join here they are just path helpers that do not read/write
// to the filesystem.
// Currently, there is no requirement for using any filepath methods
// with the golang generator, hence nothing is defined here. We may
// want to replicate this filesystem model in other contexts, so this
// will serve as a reminder in the intended use of this interface.
}
// ExistsInFS contains methods that check the existence of file system items.
type ExistsInFS interface {
// FileExists does file exist at the path specified
FileExists(path string) bool
// DirectoryExists does directory exist at the path specified
DirectoryExists(path string) bool
}
type ReadFromFS interface {
// Lstat, see https://pkg.go.dev/os#Lstat
Lstat(path string) (fs.FileInfo, error)
// Lstat, see https://pkg.go.dev/os#Stat
Stat(path string) (fs.FileInfo, error)
// ReadFile, see https://pkg.go.dev/os#ReadFile
ReadFile(name string) ([]byte, error)
// ReadDir, see https://pkg.go.dev/os#ReadDir
ReadDir(name string) ([]os.DirEntry, error)
}
// WriteToFS contains methods that perform mutative operations on the file system.
type WriteToFS interface {
// Chmod, see https://pkg.go.dev/os#Chmod
Chmod(name string, mode os.FileMode) error
// Chown, https://pkg.go.dev/os#Chown
Chown(name string, uid, gid int) error
// Create, see https://pkg.go.dev/os#Create
Create(name string) (*os.File, error)
// Link, see https://pkg.go.dev/os#Link
Link(oldname, newname string) error
// Mkdir, see https://pkg.go.dev/os#Mkdir
Mkdir(name string, perm fs.FileMode) error
// MkdirAll, see https://pkg.go.dev/os#MkdirAll
MkdirAll(path string, perm os.FileMode) error
// Remove, see https://pkg.go.dev/os#Remove
Remove(name string) error
// RemoveAll, see https://pkg.go.dev/os#RemoveAll
RemoveAll(path string) error
// Rename, see https://pkg.go.dev/os#Rename
Rename(oldpath, newpath string) error
// WriteFile, see https://pkg.go.dev/os#WriteFile
WriteFile(name string, data []byte, perm os.FileMode) error
}
// ReadOnlyVirtualFS provides read-only access to the file system.
type ReadOnlyVirtualFS interface {
filepathAPI
ExistsInFS
ReadFromFS
}
// VirtualFS is a facade over the native file system, which include read
// and write access.
type VirtualFS interface {
filepathAPI
ExistsInFS
ReadFromFS
WriteToFS
Backend() VirtualBackend
}
type VirtualBackend string