Lists all directories under "path" and outputs the results as children of "parent".
(dirpath string, parent string, recursive bool, output map[string]struct{})
| 302 | |
| 303 | // Lists all directories under "path" and outputs the results as children of "parent". |
| 304 | func 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 | |
| 333 | func MakeCgroupPaths(mountPoints map[string]string, name string) map[string]string { |
| 334 | cgroupPaths := make(map[string]string, len(mountPoints)) |
searching dependent graphs…