MCPcopy Create free account
hub / github.com/bootc-dev/bootc / read_tmpfiles_from_dir

Function read_tmpfiles_from_dir

crates/tmpfiles/src/lib.rs:457–493  ·  view source on GitHub ↗

Read all tmpfiles.d entries from a single directory

(
    rootfs: &Dir,
    dir_path: &str,
    generation: &mut BootcTmpfilesGeneration,
)

Source from the content-addressed store, hash-verified

455
456/// Read all tmpfiles.d entries from a single directory
457fn 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)

Callers 1

read_tmpfilesFunction · 0.85

Calls 4

tmpfiles_entry_get_pathFunction · 0.85
incrementMethod · 0.80
openMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected