Copy the contents of a disk image in `src_file` into `dst_file`. The type of `src_file` is automatically detected, and the output file type is determined by `dst_type`.
(
mut src_file: RawFile,
dst_file: RawFile,
dst_type: ImageType,
src_max_nesting_depth: u32,
)
| 2300 | /// The type of `src_file` is automatically detected, and the output file type is |
| 2301 | /// determined by `dst_type`. |
| 2302 | pub fn convert( |
| 2303 | mut src_file: RawFile, |
| 2304 | dst_file: RawFile, |
| 2305 | dst_type: ImageType, |
| 2306 | src_max_nesting_depth: u32, |
| 2307 | ) -> BlockResult<()> { |
| 2308 | let src_type = detect_image_type(&mut src_file)?; |
| 2309 | match src_type { |
| 2310 | ImageType::Qcow2 => { |
| 2311 | let mut src_reader = |
| 2312 | QcowFile::from_with_nesting_depth(src_file, src_max_nesting_depth, true) |
| 2313 | .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; |
| 2314 | convert_reader(&mut src_reader, dst_file, dst_type) |
| 2315 | } |
| 2316 | ImageType::Raw => { |
| 2317 | // src_file is a raw file. |
| 2318 | let mut src_reader = src_file; |
| 2319 | convert_reader(&mut src_reader, dst_file, dst_type) |
| 2320 | } |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | /// Detect the type of an image file by checking for a valid qcow2 header. |
| 2325 | pub fn detect_image_type(file: &mut RawFile) -> BlockResult<ImageType> { |
nothing calls this directly
no test coverage detected