/// Build the arguments to pass to the fvm tool.
Build the arguments to pass to the fvm tool.
Build the arguments to pass to the fvm tool .
fn build_args(&self) -> Result<Vec<String>> {
        let mut args: Vec<String> = Vec::new();
        args.push(self.output.path_to_string()?);
        // Append key and value to the `args` if the value is present.
        fn maybe_append_value(
            args: &mut Vec<String>,
            key: impl AsRef<str>,
            value: Option<impl std::string::ToString>,
        ) {
            if let Some(value) = value {
                args.push(format!("--{}", key.as_ref()));
                args.push(value.to_string());
            }
        }
        // Append the type-specific args.
        match &self.fvm_type {
            FvmType::Default => {
                args.push("create".to_string());
            }
            FvmType::Sparse { empty_minfs } => {
                args.push("sparse".to_string());
                maybe_append_value(&mut args, "compress", Some("lz4"));
                maybe_append_value(&mut args, "max-disk-size", self.max_disk_size);
                if *empty_minfs {
                    args.push("--with-empty-minfs".to_string());
                }
            }
            FvmType::Emmc { compression, length } => {
                args.push("create".to_string());
                args.push("--resize-image-file-to-fit".to_string());
                maybe_append_value(&mut args, "length", Some(length));
                let compression = match compression.as_str() {
                    "none" => None,
                    c => Some(c),
                };
                maybe_append_value(&mut args, "compress", compression);
            }
        }
        // Append the common args.
        maybe_append_value(&mut args, "slice", Some(self.slice_size.to_string()));
        maybe_append_value(&mut args, "reserve-slices", Some(self.reserved_slices.to_string()));
        // Append the filesystem args.
        for fs in &self.filesystems {
            // The 'account' partition is a special case in that the standard image for the
            // filesystem type is not appropriate. Handle this by setting a special flag
            // instead of passing through the supplied path and attributes.
            //
            // TODO(fxbug.dev/85165): Generate an empty image instead of a standard minfs image
            // for this case and the similar case of the 'data' partition in encrypted
            // environments. This empty image could be passed through directly and the special flags
            // could be removed from FVM.
            if &fs.attributes.name == "account" {
                args.push("--with-empty-account-partition".to_string());
            } else {
                maybe_append_value(
                    &mut args,
                    &fs.attributes.name,
                    Some(&fs.path.path_to_string()?),
                );
                maybe_append_value(&mut args, "minimum-inodes", fs.attributes.minimum_inodes);
                maybe_append_value(
                    &mut args,
                    "minimum-data-bytes",
                    fs.attributes.minimum_data_bytes,
                );
                maybe_append_value(&mut args, "maximum-bytes", fs.attributes.maximum_bytes);
            }
        }
        Ok(args)
    }
fn build_args ( & self ) -> Result < Vec < String > > { let mut args : Vec < String > = Vec :: new ( ) ; args . push ( self . output . path_to_string ( ) ? ) ; // Append key and value to the `args` if the value is present. fn maybe_append_value ( args : & mut Vec < String > , key : impl AsRef < str > , value : Option < impl std :: string :: ToString > , ) { if let Some ( value ) = value { args . push ( format ! ( " " key as_ref ( ) ) ) ; args . push ( value . to_string ( ) ) ; } } // Append the type-specific args. match & self . fvm_type { FvmType :: Default => { args . push ( " " . to_string ( ) ) ; } FvmType :: Sparse { empty_minfs } => { args . push ( " " . to_string ( ) ) ; maybe_append_value ( & mut args , " " , Some ( " " ) ) ; maybe_append_value ( & mut args , " " , self . max_disk_size ) ; if * empty_minfs { args . push ( " " . to_string ( ) ) ; } } FvmType :: Emmc { compression , length } => { args . push ( " " . to_string ( ) ) ; args . push ( " " . to_string ( ) ) ; maybe_append_value ( & mut args , " " , Some ( length ) ) ; let compression = match compression . as_str ( ) { " " => None , c => Some ( c ) , } ; maybe_append_value ( & mut args , " " , compression ) ; } } // Append the common args. maybe_append_value ( & mut args , " " , Some ( self . slice_size . to_string ( ) ) ) ; maybe_append_value ( & mut args , " " , Some ( self . reserved_slices . to_string ( ) ) ) ; // Append the filesystem args. for fs in & self . filesystems { // The 'account' partition is a special case in that the standard image for the // filesystem type is not appropriate. Handle this by setting a special flag // instead of passing through the supplied path and attributes. // // TODO(fxbug.dev/85165): Generate an empty image instead of a standard minfs image // for this case and the similar case of the 'data' partition in encrypted // environments. This empty image could be passed through directly and the special flags // could be removed from FVM. if & fs . attributes . name == " " { args . push ( " " . to_string ( ) ) ; } else { maybe_append_value ( & mut args , & fs . attributes . name , Some ( & fs . path . path_to_string ( ) ? ) , ) ; maybe_append_value ( & mut args , " " , fs . attributes . minimum_inodes ) ; maybe_append_value ( & mut args , " " , fs . attributes . minimum_data_bytes , ) ; maybe_append_value ( & mut args , " " , fs . attributes . maximum_bytes ) ; } } Ok ( args ) }
Build the arguments to pass to the fvm tool.
Build the arguments to pass to the fvm tool .
&self