@@ -1636,40 +1636,42 @@ pub(crate) async fn install_to_filesystem(
1636
1636
opts : InstallToFilesystemOpts ,
1637
1637
targeting_host_root : bool ,
1638
1638
) -> 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
+ }
1647
1650
}
1648
1651
1652
+ // If we're installing to an ostree root, then find the physical root from
1653
+ // the deployment root.
1649
1654
let possible_physical_root = fsopts. root_path . join ( "sysroot" ) ;
1650
1655
let possible_ostree_dir = possible_physical_root. join ( "ostree" ) ;
1651
- let root_path = if possible_ostree_dir. exists ( ) {
1656
+ if possible_ostree_dir. exists ( ) {
1652
1657
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}"
1654
1659
) ;
1655
- & possible_physical_root
1656
- } else {
1657
- root_path
1660
+ fsopts. root_path = possible_physical_root;
1658
1661
} ;
1659
1662
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}" ) ) ?;
1662
1668
1663
- tracing:: debug!( "Root filesystem: {root_path}" ) ;
1669
+ tracing:: debug!( "Root filesystem: {root_path}" ) ;
1664
1670
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
1673
1675
} ;
1674
1676
1675
1677
// Gather global state, destructuring the provided options.
0 commit comments