MCPcopy Create free account
hub / github.com/awslabs/amazon-eks-ami / ReadDir

Method ReadDir

nodeadm/internal/system/filesystem.go:80–112  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

78}
79
80func (f FakeFileSystem) ReadDir(name string) ([]fs.DirEntry, error) {
81 name = strings.TrimSuffix(name, "/")
82 if content, ok := f.Files[name]; ok && content != EmptyDirectoryMarker {
83 return nil, &os.PathError{Op: "readdir", Path: name, Err: os.ErrInvalid}
84 }
85
86 var entries []fs.DirEntry
87 seen := make(map[string]bool)
88 prefix := name + "/"
89
90 for path := range f.Files {
91 if !strings.HasPrefix(path, prefix) {
92 continue
93 }
94 rest := strings.TrimPrefix(path, prefix)
95 parts := strings.SplitN(rest, "/", 2)
96 entryName := parts[0]
97 if seen[entryName] {
98 continue
99 }
100 seen[entryName] = true
101
102 entryPath := name + "/" + entryName
103 entries = append(entries, &fakeEntry{name: entryName, isDir: f.isDir(entryPath)})
104 }
105
106 if len(entries) == 0 {
107 if _, ok := f.Files[name]; !ok {
108 return nil, os.ErrNotExist
109 }
110 }
111 return entries, nil
112}
113
114func (f FakeFileSystem) isDir(name string) bool {
115 if content, ok := f.Files[name]; ok && content == EmptyDirectoryMarker {

Callers

nothing calls this directly

Calls 1

isDirMethod · 0.95

Tested by

no test coverage detected