@@ -712,6 +712,27 @@ async fn initialize_ostree_root(
712712 Ok ( ( Storage :: new ( sysroot, & temp_run) ?, has_ostree, imgstore) )
713713}
714714
715+ fn check_disk_space (
716+ repo_fd : impl AsFd ,
717+ image_meta : & PreparedImportMeta ,
718+ imgref : & ImageReference ,
719+ ) -> Result < ( ) > {
720+ let stat = rustix:: fs:: fstatvfs ( repo_fd) ?;
721+ let bytes_avail: u64 = stat. f_bsize * stat. f_bavail ;
722+ tracing:: trace!( "bytes_avail: {bytes_avail}" ) ;
723+
724+ if image_meta. bytes_to_fetch > bytes_avail {
725+ anyhow:: bail!(
726+ "Insufficient free space for {image} (available: {bytes_avail} required: {bytes_to_fetch})" ,
727+ bytes_avail = ostree_ext:: glib:: format_size( bytes_avail) ,
728+ bytes_to_fetch = ostree_ext:: glib:: format_size( image_meta. bytes_to_fetch) ,
729+ image = imgref. image,
730+ ) ;
731+ }
732+
733+ Ok ( ( ) )
734+ }
735+
715736#[ context( "Creating ostree deployment" ) ]
716737async fn install_container (
717738 state : & State ,
@@ -760,6 +781,7 @@ async fn install_container(
760781 match prepare_for_pull ( repo, & spec_imgref, Some ( & state. target_imgref ) ) . await ? {
761782 PreparedPullResult :: AlreadyPresent ( existing) => existing,
762783 PreparedPullResult :: Ready ( image_meta) => {
784+ check_disk_space ( root_setup. physical_root . as_fd ( ) , & image_meta, & spec_imgref) ?;
763785 pull_from_prepared (
764786 repo,
765787 & spec_imgref,
0 commit comments