Skip to content

Commit

Permalink
Merge pull request #689 from cgwalters/bump-cap-std-ext
Browse files Browse the repository at this point in the history
boundimage: Use new RootDir API
  • Loading branch information
ckyrouac authored Jul 16, 2024
2 parents 2ef07ec + adf6b90 commit 63f593d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 4 additions & 17 deletions lib/src/boundimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ use fn_error_context::context;
use ostree_ext::ostree::Deployment;
use ostree_ext::sysroot::SysrootLock;
use rustix::fd::BorrowedFd;
use rustix::fs::{OFlags, ResolveFlags};
use std::fs::File;
use std::io::Read;
use std::os::unix::io::AsFd;

const BOUND_IMAGE_DIR: &str = "usr/lib/bootc-experimental/bound-images.d";

Expand All @@ -37,6 +33,9 @@ fn parse_spec_dir(root: &Dir, spec_dir: &str) -> Result<Vec<BoundImage>> {
let Some(bound_images_dir) = root.open_dir_optional(spec_dir)? else {
return Ok(Default::default());
};
// And open a view of the dir that uses RESOLVE_IN_ROOT so we
// handle absolute symlinks.
let absroot = &root.open_dir_rooted_ext(".")?;

let mut bound_images = Vec::new();

Expand All @@ -59,19 +58,7 @@ fn parse_spec_dir(root: &Dir, spec_dir: &str) -> Result<Vec<BoundImage>> {

//parse the file contents
let path = Utf8Path::new(spec_dir).join(file_name);
let mut file: File = rustix::fs::openat2(
root.as_fd(),
path.as_std_path(),
OFlags::CLOEXEC | OFlags::RDONLY,
rustix::fs::Mode::empty(),
ResolveFlags::IN_ROOT,
)
.context("Unable to openat")?
.into();

let mut file_contents = String::new();
file.read_to_string(&mut file_contents)
.context("Unable to read file contents")?;
let file_contents = absroot.read_to_string(&path)?;

let file_ini = tini::Ini::from_string(&file_contents).context("Parse to ini")?;
let file_extension = Utf8Path::new(file_name).extension();
Expand Down

0 comments on commit 63f593d

Please sign in to comment.