From ffe46d85dda83d3c2effc069ae147c9eb74a418b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 15 Dec 2023 10:21:41 -0500 Subject: [PATCH] install-to-disk: Verify target is a block device I saw someone get confused and think `bootc install` could work on a filesystem. Signed-off-by: Colin Walters --- lib/src/install.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/src/install.rs b/lib/src/install.rs index 3fb80eb92..f2a2b9797 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -26,6 +26,7 @@ use cap_std_ext::prelude::CapStdExtDirExt; use chrono::prelude::*; use clap::ValueEnum; use ostree_ext::oci_spec; +use rustix::fs::FileTypeExt; use rustix::fs::MetadataExt; use fn_error_context::context; @@ -1024,6 +1025,13 @@ fn installation_complete() { /// Implementation of the `bootc install to-disk` CLI command. pub(crate) async fn install_to_disk(opts: InstallToDiskOpts) -> Result<()> { let block_opts = opts.block_opts; + let target_blockdev_meta = block_opts + .device + .metadata() + .with_context(|| format!("Querying {}", &block_opts.device))?; + if !target_blockdev_meta.file_type().is_block_device() { + anyhow::bail!("Not a block device: {}", block_opts.device); + } let state = prepare_install(opts.config_opts, opts.target_opts).await?; // This is all blocking stuff