Skip to content

Commit 848be3f

Browse files
authored
Merge pull request #905 from cgwalters/minor-install-root-path
install: Some cleanups around root_path
2 parents fde4cca + 784b31c commit 848be3f

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

lib/src/install.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,40 +1636,42 @@ pub(crate) async fn install_to_filesystem(
16361636
opts: InstallToFilesystemOpts,
16371637
targeting_host_root: bool,
16381638
) -> Result<()> {
1639-
let fsopts = opts.filesystem_opts;
1640-
let root_path = &fsopts.root_path;
1641-
1642-
let st = root_path
1643-
.symlink_metadata()
1644-
.with_context(|| format!("Querying target filesystem {root_path}"))?;
1645-
if !st.is_dir() {
1646-
anyhow::bail!("Not a directory: {root_path}");
1639+
let mut fsopts = opts.filesystem_opts;
1640+
1641+
// Check that the target is a directory
1642+
{
1643+
let root_path = &fsopts.root_path;
1644+
let st = root_path
1645+
.symlink_metadata()
1646+
.with_context(|| format!("Querying target filesystem {root_path}"))?;
1647+
if !st.is_dir() {
1648+
anyhow::bail!("Not a directory: {root_path}");
1649+
}
16471650
}
16481651

1652+
// If we're installing to an ostree root, then find the physical root from
1653+
// the deployment root.
16491654
let possible_physical_root = fsopts.root_path.join("sysroot");
16501655
let possible_ostree_dir = possible_physical_root.join("ostree");
1651-
let root_path = if possible_ostree_dir.exists() {
1656+
if possible_ostree_dir.exists() {
16521657
tracing::debug!(
1653-
"ostree detected in {possible_ostree_dir}, assuming / is a deployment root and using {possible_physical_root} instead of {root_path} as target root"
1658+
"ostree detected in {possible_ostree_dir}, assuming target is a deployment root and using {possible_physical_root}"
16541659
);
1655-
&possible_physical_root
1656-
} else {
1657-
root_path
1660+
fsopts.root_path = possible_physical_root;
16581661
};
16591662

1660-
let rootfs_fd = Dir::open_ambient_dir(root_path, cap_std::ambient_authority())
1661-
.with_context(|| format!("Opening target root directory {root_path}"))?;
1663+
// Get a file descriptor for the root path
1664+
let rootfs_fd = {
1665+
let root_path = &fsopts.root_path;
1666+
let rootfs_fd = Dir::open_ambient_dir(&fsopts.root_path, cap_std::ambient_authority())
1667+
.with_context(|| format!("Opening target root directory {root_path}"))?;
16621668

1663-
tracing::debug!("Root filesystem: {root_path}");
1669+
tracing::debug!("Root filesystem: {root_path}");
16641670

1665-
if let Some(false) = ostree_ext::mountutil::is_mountpoint(&rootfs_fd, ".")? {
1666-
anyhow::bail!("Not a mountpoint: {root_path}");
1667-
}
1668-
1669-
let fsopts = {
1670-
let mut fsopts = fsopts.clone();
1671-
fsopts.root_path = root_path.clone();
1672-
fsopts
1671+
if let Some(false) = ostree_ext::mountutil::is_mountpoint(&rootfs_fd, ".")? {
1672+
anyhow::bail!("Not a mountpoint: {root_path}");
1673+
}
1674+
rootfs_fd
16731675
};
16741676

16751677
// Gather global state, destructuring the provided options.

0 commit comments

Comments
 (0)