Skip to content

Commit

Permalink
install-to-filesystem: Verify target is a dir+mountpoint
Browse files Browse the repository at this point in the history
Similarly to previous patch for `install to-disk`, verify
that the target is a directory *and* that it's a mountpoint (we
can't sanely support installing to a subdirectory of a filesystem).

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Dec 15, 2023
1 parent ffe46d8 commit 7997f57
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,13 +1123,22 @@ fn clean_boot_directories(rootfs: &Dir) -> Result<()> {

/// Implementation of the `bootc install to-filsystem` CLI command.
pub(crate) async fn install_to_filesystem(opts: InstallToFilesystemOpts) -> Result<()> {
// Gather global state, destructuring the provided options
let state = prepare_install(opts.config_opts, opts.target_opts).await?;
let fsopts = opts.filesystem_opts;

let root_path = &fsopts.root_path;

let st = root_path.symlink_metadata()?;
if !st.is_dir() {
anyhow::bail!("Not a directory: {root_path}");
}
let rootfs_fd = Dir::open_ambient_dir(root_path, cap_std::ambient_authority())
.with_context(|| format!("Opening target root directory {root_path}"))?;
if let Some(false) = ostree_ext::mountutil::is_mountpoint(&rootfs_fd, ".")? {
anyhow::bail!("Not a root mountpoint: {root_path}");
}

// Gather global state, destructuring the provided options
let state = prepare_install(opts.config_opts, opts.target_opts).await?;

match fsopts.replace {
Some(ReplaceMode::Wipe) => {
let rootfs_fd = rootfs_fd.try_clone()?;
Expand Down

0 comments on commit 7997f57

Please sign in to comment.