55use std:: path:: { Path , PathBuf } ;
66
77use disks:: BlockDevice ;
8- use partitioning:: { blkpg, loopback, sparsefile, writer:: DiskWriter } ;
8+ use partitioning:: { blkpg, loopback, sparsefile, writer:: DiskWriter , Formatter } ;
99use provisioning:: { Parser , Provisioner , StrategyDefinition } ;
1010
1111/// Loads provisioning strategies from a configuration file
@@ -58,10 +58,38 @@ fn apply_partitioning(whence: &Path) -> Result<(), Box<dyn std::error::Error>> {
5858 disk_writer. write ( ) ?;
5959 }
6060
61- for ( device, fs) in plan. filesystems . iter ( ) {
62- eprintln ! ( "To format: {:?} with {:?}" , device, fs) ;
61+ // Sync partition table changes
62+ blkpg:: sync_gpt_partitions ( whence) ?;
63+
64+ let mut formatters = plan
65+ . filesystems
66+ . iter ( )
67+ . map ( |( device, fs) | {
68+ let formatter = Formatter :: new ( fs. clone ( ) ) . force ( ) ;
69+ formatter. format ( device)
70+ } )
71+ . collect :: < Vec < _ > > ( ) ;
72+
73+ for operation in formatters. iter_mut ( ) {
74+ match operation. output ( ) {
75+ Ok ( output) => {
76+ let stdout = std:: str:: from_utf8 ( & output. stdout ) . expect ( "Invalid UTF-8" ) ;
77+ if output. status . success ( ) {
78+ eprintln ! ( "Format success: {}" , stdout) ;
79+ } else {
80+ let stderr = std:: str:: from_utf8 ( & output. stderr ) . expect ( "Invalid UTF-8" ) ;
81+ eprintln ! ( "Format error: {}" , stderr) ;
82+ }
83+ eprintln ! ( "Format output: {}" , stdout) ;
84+ }
85+ Err ( e) => {
86+ eprintln ! ( "Format error: {}" , e) ;
87+ }
88+ }
6389 }
6490
91+ eprintln ! ( "Format operations: {:?}" , formatters) ;
92+
6593 for ( role, device) in plan. role_mounts . iter ( ) {
6694 eprintln ! ( "To mount: {:?} as {:?} (`{}`)" , device, role, role. as_path( ) ) ;
6795 }
@@ -84,9 +112,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
84112 eprintln ! ( "Error applying partitioning: {}" , e) ;
85113 }
86114
87- // Sync partition table changes
88- blkpg:: sync_gpt_partitions ( whence) ?;
89-
90115 // Clean up loopback device
91116 l. detach ( ) ?;
92117
0 commit comments