MCPcopy Create free account
hub / github.com/kataras/iris / FindNames

Function FindNames

context/fs.go:137–182  ·  view source on GitHub ↗

FindNames accepts a "http.FileSystem" and a root name and returns the list containing its file names.

(fileSystem http.FileSystem, name string)

Source from the content-addressed store, hash-verified

135// FindNames accepts a "http.FileSystem" and a root name and returns
136// the list containing its file names.
137func FindNames(fileSystem http.FileSystem, name string) ([]string, error) {
138 if strings.Contains(name, "..") {
139 return nil, fmt.Errorf("invalid root name")
140 }
141
142 f, err := fileSystem.Open(name) // it's the root dir.
143 if err != nil {
144 return nil, err
145 }
146 defer f.Close()
147
148 fi, err := f.Stat()
149 if err != nil {
150 return nil, err
151 }
152
153 if !fi.IsDir() {
154 return []string{name}, nil
155 }
156
157 fileinfos, err := f.Readdir(-1)
158 if err != nil {
159 return nil, err
160 }
161
162 files := make([]string, 0)
163
164 for _, info := range fileinfos {
165 // Note:
166 // go-bindata has absolute names with os.Separator,
167 // http.Dir the basename.
168 baseFilename := toBaseName(info.Name())
169 fullname := path.Join(name, baseFilename)
170 if fullname == name { // prevent looping through itself.
171 continue
172 }
173 rfiles, err := FindNames(fileSystem, fullname)
174 if err != nil {
175 return nil, err
176 }
177
178 files = append(files, rfiles...)
179 }
180
181 return files, nil
182}
183
184// Instead of path.Base(filepath.ToSlash(s))
185// let's do something like that, it is faster

Callers 2

FileServerFunction · 0.92
cacheFunction · 0.92

Calls 9

ContainsMethod · 0.80
ErrorfMethod · 0.80
toBaseNameFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65
OpenMethod · 0.45
StatMethod · 0.45
IsDirMethod · 0.45
ReaddirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…