Load usernames from a passwd-format file at `path` within `root`, returning an empty set if the file doesn't exist.
(root: &Dir, path: &str)
| 28 | /// Load usernames from a passwd-format file at `path` within `root`, returning |
| 29 | /// an empty set if the file doesn't exist. |
| 30 | fn load_usernames(root: &Dir, path: &str) -> Result<HashSet<String>> { |
| 31 | use bootc_sysusers::nameservice::passwd::parse_passwd_content; |
| 32 | let mut names = HashSet::new(); |
| 33 | if let Some(f) = root |
| 34 | .open_optional(path) |
| 35 | .with_context(|| format!("Opening {path}"))? |
| 36 | { |
| 37 | let entries = parse_passwd_content(std::io::BufReader::new(f)) |
| 38 | .with_context(|| format!("Parsing {path}"))?; |
| 39 | names.extend(entries.into_iter().map(|e| e.name)); |
| 40 | } |
| 41 | Ok(names) |
| 42 | } |
| 43 | |
| 44 | /// Load group names from a group-format file at `path` within `root`, returning |
| 45 | /// an empty set if the file doesn't exist. |
no test coverage detected