-
Notifications
You must be signed in to change notification settings - Fork 292
/
dirfs.go
56 lines (47 loc) · 1 KB
/
dirfs.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
package module
import (
"io/fs"
"os"
)
// SourceLoc represents the location of some CUE source code.
type SourceLoc struct {
// FS is the filesystem containing the source.
FS fs.FS
// Dir is the directory within the above filesystem.
Dir string
}
// OSRootFS can be implemented by an [fs.FS]
// implementation to return its root directory as
// an OS file path.
type OSRootFS interface {
fs.FS
// OSRoot returns the root directory of the FS
// as an OS file path. If it wasn't possible to do that,
// it returns the empty string.
OSRoot() string
}
// OSDirFS is like [os.DirFS] but the returned value implements
// [OSRootFS] by returning p.
func OSDirFS(p string) fs.FS {
return dirFSImpl{
augmentedFS: os.DirFS(p).(augmentedFS),
osRoot: p,
}
}
var _ interface {
augmentedFS
OSRootFS
} = dirFSImpl{}
type augmentedFS interface {
fs.FS
fs.StatFS
fs.ReadDirFS
fs.ReadFileFS
}
type dirFSImpl struct {
osRoot string
augmentedFS
}
func (fsys dirFSImpl) OSRoot() string {
return fsys.osRoot
}