(reader: &mut R, dst_file: RawFile, dst_type: ImageType)
| 2263 | } |
| 2264 | |
| 2265 | fn convert_reader<R>(reader: &mut R, dst_file: RawFile, dst_type: ImageType) -> BlockResult<()> |
| 2266 | where |
| 2267 | R: Read + Seek + SeekHole, |
| 2268 | { |
| 2269 | let src_size = reader |
| 2270 | .seek(SeekFrom::End(0)) |
| 2271 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?; |
| 2272 | reader |
| 2273 | .rewind() |
| 2274 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?; |
| 2275 | |
| 2276 | // Ensure the destination file is empty before writing to it. |
| 2277 | dst_file |
| 2278 | .set_len(0) |
| 2279 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SettingFileSize(e)))?; |
| 2280 | |
| 2281 | match dst_type { |
| 2282 | ImageType::Qcow2 => { |
| 2283 | let mut dst_writer = QcowFile::new(dst_file, 3, src_size, true) |
| 2284 | .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; |
| 2285 | convert_reader_writer(reader, &mut dst_writer, src_size) |
| 2286 | } |
| 2287 | ImageType::Raw => { |
| 2288 | let mut dst_writer = dst_file; |
| 2289 | // Set the length of the destination file to convert it into a sparse file |
| 2290 | // of the desired size. |
| 2291 | dst_writer |
| 2292 | .set_len(src_size) |
| 2293 | .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SettingFileSize(e)))?; |
| 2294 | convert_reader_writer(reader, &mut dst_writer, src_size) |
| 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | /// Copy the contents of a disk image in `src_file` into `dst_file`. |
| 2300 | /// The type of `src_file` is automatically detected, and the output file type is |
no test coverage detected