Core disk space check: verify that `bytes_to_fetch` fits within available space, leaving at least `min_free` bytes reserved.
(
fd: impl AsFd,
bytes_to_fetch: u64,
min_free: u64,
imgref: &ImageReference,
)
| 428 | /// Core disk space check: verify that `bytes_to_fetch` fits within available space, |
| 429 | /// leaving at least `min_free` bytes reserved. |
| 430 | fn check_disk_space_inner( |
| 431 | fd: impl AsFd, |
| 432 | bytes_to_fetch: u64, |
| 433 | min_free: u64, |
| 434 | imgref: &ImageReference, |
| 435 | ) -> Result<()> { |
| 436 | let stat = rustix::fs::fstatvfs(fd)?; |
| 437 | let bytes_avail = stat.f_bsize.checked_mul(stat.f_bavail).unwrap_or(u64::MAX); |
| 438 | let usable = bytes_avail.saturating_sub(min_free); |
| 439 | tracing::trace!("bytes_avail: {bytes_avail} min_free: {min_free} usable: {usable}"); |
| 440 | |
| 441 | if bytes_to_fetch > usable { |
| 442 | anyhow::bail!( |
| 443 | "Insufficient free space for {image} (available: {available} required: {required})", |
| 444 | available = ostree_ext::glib::format_size(usable), |
| 445 | required = ostree_ext::glib::format_size(bytes_to_fetch), |
| 446 | image = imgref.image, |
| 447 | ); |
| 448 | } |
| 449 | Ok(()) |
| 450 | } |
| 451 | |
| 452 | /// Verify there is sufficient disk space to pull an image into the ostree repo. |
| 453 | /// Respects the repository's configured min-free-space threshold. |
no outgoing calls