Read all tmpfiles.d entries from a single directory
(
rootfs: &Dir,
dir_path: &str,
generation: &mut BootcTmpfilesGeneration,
)
| 455 | |
| 456 | /// Read all tmpfiles.d entries from a single directory |
| 457 | fn read_tmpfiles_from_dir( |
| 458 | rootfs: &Dir, |
| 459 | dir_path: &str, |
| 460 | generation: &mut BootcTmpfilesGeneration, |
| 461 | ) -> Result<BTreeMap<PathBuf, String>> { |
| 462 | let Some(tmpfiles_dir) = rootfs.open_dir_optional(dir_path)? else { |
| 463 | return Ok(Default::default()); |
| 464 | }; |
| 465 | let mut result = BTreeMap::new(); |
| 466 | for entry in tmpfiles_dir.entries()? { |
| 467 | let entry = entry?; |
| 468 | let name = entry.file_name(); |
| 469 | let (Some(stem), Some(extension)) = |
| 470 | (Path::new(&name).file_stem(), Path::new(&name).extension()) |
| 471 | else { |
| 472 | continue; |
| 473 | }; |
| 474 | if extension != "conf" { |
| 475 | continue; |
| 476 | } |
| 477 | if let Ok(s) = stem.as_str() { |
| 478 | if s.starts_with(BOOTC_GENERATED_PREFIX) { |
| 479 | generation.increment(); |
| 480 | } |
| 481 | } |
| 482 | let r = BufReader::new(entry.open()?); |
| 483 | for line in r.lines() { |
| 484 | let line = line?; |
| 485 | if line.is_empty() || line.starts_with("#") { |
| 486 | continue; |
| 487 | } |
| 488 | let path = tmpfiles_entry_get_path(&line)?; |
| 489 | result.insert(path.to_owned(), line); |
| 490 | } |
| 491 | } |
| 492 | Ok(result) |
| 493 | } |
| 494 | |
| 495 | /// Read all tmpfiles.d entries in the target directory, and return a mapping |
| 496 | /// from (file path) => (single tmpfiles.d entry line) |
no test coverage detected