MCPcopy
hub / github.com/google/cadvisor / ListDirectories

Function ListDirectories

lib/container/common/helpers.go:304–331  ·  view source on GitHub ↗

Lists all directories under "path" and outputs the results as children of "parent".

(dirpath string, parent string, recursive bool, output map[string]struct{})

Source from the content-addressed store, hash-verified

302
303// Lists all directories under "path" and outputs the results as children of "parent".
304func ListDirectories(dirpath string, parent string, recursive bool, output map[string]struct{}) error {
305 dirents, err := os.ReadDir(dirpath)
306 if err != nil {
307 // Ignore if this hierarchy does not exist.
308 if errors.Is(err, fs.ErrNotExist) {
309 return nil
310 }
311 return err
312 }
313 for _, dirent := range dirents {
314 // We only grab directories.
315 if !dirent.IsDir() {
316 continue
317 }
318 dirname := dirent.Name()
319
320 name := path.Join(parent, dirname)
321 output[name] = struct{}{}
322
323 // List subcontainers if asked to.
324 if recursive {
325 if err := ListDirectories(path.Join(dirpath, dirname), name, true, output); err != nil {
326 return err
327 }
328 }
329 }
330 return nil
331}
332
333func MakeCgroupPaths(mountPoints map[string]string, name string) map[string]string {
334 cgroupPaths := make(map[string]string, len(mountPoints))

Callers 2

ListContainersFunction · 0.85
BenchmarkListDirectoriesFunction · 0.85

Calls 2

NameMethod · 0.65
IsDirMethod · 0.45

Tested by 1

BenchmarkListDirectoriesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…