File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -207,6 +207,16 @@ impl FileTree {
207207 Ok ( Self { children } )
208208 }
209209
210+ /// Total size in bytes of all files in the tree (for space checks).
211+ #[ cfg( any(
212+ target_arch = "x86_64" ,
213+ target_arch = "aarch64" ,
214+ target_arch = "riscv64"
215+ ) ) ]
216+ pub ( crate ) fn total_size ( & self ) -> u64 {
217+ self . children . values ( ) . map ( |m| m. size ) . sum ( )
218+ }
219+
210220 /// Determine the changes *from* self to the updated tree
211221 #[ cfg( any(
212222 target_arch = "x86_64" ,
Original file line number Diff line number Diff line change 11use std:: collections:: HashSet ;
2+ use std:: os:: unix:: io:: AsRawFd ;
23use std:: path:: Path ;
34use std:: process:: Command ;
45
56use anyhow:: { bail, Context , Result } ;
67use openat_ext:: OpenatDirExt ;
8+ use rustix:: fd:: BorrowedFd ;
79
810/// Parse an environment variable as UTF-8
911#[ allow( dead_code) ]
@@ -51,9 +53,18 @@ pub(crate) fn filenames(dir: &openat::Dir) -> Result<HashSet<String>> {
5153 Ok ( ret)
5254}
5355
56+ /// Return the available space in bytes on the filesystem containing the given directory.
57+ /// Uses f_bavail * f_frsize from fstatvfs to avoid partial updates when the partition is full.
58+ pub ( crate ) fn available_space_bytes ( dir : & openat:: Dir ) -> Result < u64 > {
59+ let fd = unsafe { BorrowedFd :: borrow_raw ( dir. as_raw_fd ( ) ) } ;
60+ let st = rustix:: fs:: fstatvfs ( fd) ?;
61+ Ok ( ( st. f_bavail as u64 ) * ( st. f_frsize as u64 ) )
62+ }
63+
5464pub ( crate ) fn ensure_writable_mount < P : AsRef < Path > > ( p : P ) -> Result < ( ) > {
5565 let p = p. as_ref ( ) ;
56- let stat = rustix:: fs:: statvfs ( p) ?;
66+ let stat =
67+ rustix:: fs:: statvfs ( p) . map_err ( |e| std:: io:: Error :: from_raw_os_error ( e. raw_os_error ( ) ) ) ?;
5768 if !stat. f_flag . contains ( rustix:: fs:: StatVfsMountFlags :: RDONLY ) {
5869 return Ok ( ( ) ) ;
5970 }
You can’t perform that action at this time.
0 commit comments