Skip to content

Commit

Permalink
bwrap: Pass mutability flag, not unified core
Browse files Browse the repository at this point in the history
We have two `bool` values here and that's a code smell.  I was
going to add another option and we definitely don't want three
bools.

We already have an enum here related to what's going on,
so change things to use it.
  • Loading branch information
cgwalters committed Mar 8, 2024
1 parent cc79924 commit de80514
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
11 changes: 3 additions & 8 deletions rust/src/bwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,14 @@ pub(crate) fn bubblewrap_run_sync(
rootfs_dfd: i32,
args: &Vec<String>,
capture_stdout: bool,
unified_core: bool,
mutability: BubblewrapMutability,
) -> CxxResult<Vec<u8>> {
let rootfs_dfd = unsafe { &crate::ffiutil::ffi_dirfd(rootfs_dfd)? };
let tempetc = crate::core::prepare_tempetc_guard(rootfs_dfd.as_raw_fd())?;
let mutability = if unified_core {
BubblewrapMutability::RoFiles
} else {
BubblewrapMutability::MutateFreely
};
let mut bwrap = Bubblewrap::new_with_mutability(rootfs_dfd, mutability)?;

if unified_core {
bwrap.bind_read("var", "/var");
if mutability != BubblewrapMutability::MutateFreely {
bwrap.bind_read("var", "/var")
} else {
bwrap.bind_readwrite("var", "/var")
}
Expand Down
10 changes: 7 additions & 3 deletions rust/src/composepost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,12 @@ fn compose_postprocess_scripts(
)?;
println!("Executing `postprocess` inline script '{}'", i);
let child_argv = vec![binpath.to_string()];
let _ =
bwrap::bubblewrap_run_sync(rootfs_dfd.as_raw_fd(), &child_argv, false, unified_core)?;
let _ = bwrap::bubblewrap_run_sync(
rootfs_dfd.as_raw_fd(),
&child_argv,
false,
BubblewrapMutability::for_unified_core(unified_core),
)?;
rootfs_dfd.remove_file(target_binpath)?;
}

Expand All @@ -531,7 +535,7 @@ fn compose_postprocess_scripts(
rootfs_dfd.as_raw_fd(),
child_argv,
false,
unified_core,
BubblewrapMutability::for_unified_core(unified_core),
)
.context("Executing postprocessing script")?;

Expand Down
7 changes: 6 additions & 1 deletion rust/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ pub(crate) fn run_depmod(rootfs_dfd: i32, kver: &str, unified_core: bool) -> Cxx
.into_iter()
.map(|s| s.to_string())
.collect();
let _ = crate::bwrap::bubblewrap_run_sync(rootfs_dfd, &args, false, unified_core)?;
let _ = crate::bwrap::bubblewrap_run_sync(
rootfs_dfd,
&args,
false,
crate::ffi::BubblewrapMutability::for_unified_core(unified_core),
)?;
Ok(())
}

Expand Down
13 changes: 12 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod cxxrsutil;
mod ffiutil;
pub(crate) mod ffiwrappers;
pub(crate) use cxxrsutil::*;
use ffi::BubblewrapMutability;

/// APIs defined here are automatically bridged between Rust and C++ using https://cxx.rs/
///
Expand Down Expand Up @@ -123,7 +124,7 @@ pub mod ffi {
rootfs_dfd: i32,
args: &Vec<String>,
capture_stdout: bool,
unified_core: bool,
mutability: BubblewrapMutability,
) -> Result<Vec<u8>>;

fn bubblewrap_new(rootfs_fd: i32) -> Result<Box<Bubblewrap>>;
Expand Down Expand Up @@ -927,6 +928,16 @@ pub mod ffi {
}
}

impl BubblewrapMutability {
pub(crate) fn for_unified_core(unified_core: bool) -> Self {
if unified_core {
Self::RoFiles
} else {
Self::MutateFreely
}
}
}

pub mod builtins;
pub(crate) use crate::builtins::apply_live::*;
pub(crate) use crate::builtins::compose::commit::*;
Expand Down

0 comments on commit de80514

Please sign in to comment.