-
Notifications
You must be signed in to change notification settings - Fork 0
/
rootmappingdir.go
82 lines (70 loc) · 1.65 KB
/
rootmappingdir.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
package valueobject
import (
"errors"
iofs "io/fs"
"os"
)
type rootMappingDir struct {
*noOpRegularFileOps
DirOnlyOps
fs *RootMappingFs
name string
meta *FileMeta
}
func (f *rootMappingDir) Close() error {
if f.DirOnlyOps == nil {
return nil
}
return f.DirOnlyOps.Close()
}
func (f *rootMappingDir) Name() string {
return f.name
}
func (f *rootMappingDir) ReadDir(count int) ([]iofs.DirEntry, error) {
if f.DirOnlyOps != nil {
fis, err := f.DirOnlyOps.(iofs.ReadDirFile).ReadDir(count)
if err != nil {
return nil, err
}
var result []iofs.DirEntry
for _, fi := range fis {
fim := DecorateFileInfo(fi, nil, "", f.meta)
// TODO: ignore InclusionFilter
result = append(result, fim)
}
return result, nil
}
return f.fs.collectDirEntries(f.name)
}
// Sentinel error to signal that a file is a directory.
var errIsDir = errors.New("isDir")
func (f *rootMappingDir) Stat() (iofs.FileInfo, error) {
return nil, errIsDir
}
func (f *rootMappingDir) Readdir(count int) ([]os.FileInfo, error) {
dirEntry, err := f.ReadDir(count)
if err != nil {
return nil, err
}
var result []os.FileInfo
for _, d := range dirEntry {
result = append(result, d.(os.FileInfo))
}
return result, nil
}
// Note that Readdirnames preserves the order of the underlying filesystem(s),
// which is usually directory order.
func (f *rootMappingDir) Readdirnames(count int) ([]string, error) {
dirs, err := f.ReadDir(count)
if err != nil {
return nil, err
}
return dirEntriesToNames(dirs), nil
}
func dirEntriesToNames(fis []iofs.DirEntry) []string {
names := make([]string, len(fis))
for i, d := range fis {
names[i] = d.Name()
}
return names
}