5
5
use std:: path:: { Path , PathBuf } ;
6
6
7
7
use disks:: BlockDevice ;
8
- use partitioning:: { blkpg, loopback, sparsefile, writer:: DiskWriter } ;
8
+ use partitioning:: { blkpg, loopback, sparsefile, writer:: DiskWriter , Formatter } ;
9
9
use provisioning:: { Parser , Provisioner , StrategyDefinition } ;
10
10
11
11
/// Loads provisioning strategies from a configuration file
@@ -58,10 +58,38 @@ fn apply_partitioning(whence: &Path) -> Result<(), Box<dyn std::error::Error>> {
58
58
disk_writer. write ( ) ?;
59
59
}
60
60
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
+ }
63
89
}
64
90
91
+ eprintln ! ( "Format operations: {:?}" , formatters) ;
92
+
65
93
for ( role, device) in plan. role_mounts . iter ( ) {
66
94
eprintln ! ( "To mount: {:?} as {:?} (`{}`)" , device, role, role. as_path( ) ) ;
67
95
}
@@ -84,9 +112,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
84
112
eprintln ! ( "Error applying partitioning: {}" , e) ;
85
113
}
86
114
87
- // Sync partition table changes
88
- blkpg:: sync_gpt_partitions ( whence) ?;
89
-
90
115
// Clean up loopback device
91
116
l. detach ( ) ?;
92
117
0 commit comments