Can convert QCow2 to raw file
This commit is contained in:
		@@ -35,7 +35,7 @@ pub enum DiskFileFormat {
 | 
				
			|||||||
impl DiskFileFormat {
 | 
					impl DiskFileFormat {
 | 
				
			||||||
    pub fn ext(&self) -> &'static [&'static str] {
 | 
					    pub fn ext(&self) -> &'static [&'static str] {
 | 
				
			||||||
        match self {
 | 
					        match self {
 | 
				
			||||||
            DiskFileFormat::Raw { .. } => &["", "raw"],
 | 
					            DiskFileFormat::Raw { .. } => &["raw", ""],
 | 
				
			||||||
            DiskFileFormat::QCow2 { .. } => &["qcow2"],
 | 
					            DiskFileFormat::QCow2 { .. } => &["qcow2"],
 | 
				
			||||||
            DiskFileFormat::CompressedRaw => &["raw.gz"],
 | 
					            DiskFileFormat::CompressedRaw => &["raw.gz"],
 | 
				
			||||||
            DiskFileFormat::CompressedQCow2 => &["qcow2.gz"],
 | 
					            DiskFileFormat::CompressedQCow2 => &["qcow2.gz"],
 | 
				
			||||||
@@ -153,7 +153,9 @@ impl DiskFileInfo {
 | 
				
			|||||||
    pub fn convert(&self, dest_file: &Path, dest_format: DiskFileFormat) -> anyhow::Result<()> {
 | 
					    pub fn convert(&self, dest_file: &Path, dest_format: DiskFileFormat) -> anyhow::Result<()> {
 | 
				
			||||||
        // Create a temporary directory to perform the operation
 | 
					        // Create a temporary directory to perform the operation
 | 
				
			||||||
        let temp_dir = tempfile::tempdir_in(&AppConfig::get().temp_dir)?;
 | 
					        let temp_dir = tempfile::tempdir_in(&AppConfig::get().temp_dir)?;
 | 
				
			||||||
        let temp_file = temp_dir.path().join("temp_file");
 | 
					        let temp_file = temp_dir
 | 
				
			||||||
 | 
					            .path()
 | 
				
			||||||
 | 
					            .join(format!("temp_file.{}", dest_format.ext()[0]));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Prepare the conversion
 | 
					        // Prepare the conversion
 | 
				
			||||||
        let mut cmd = match (self.format, dest_format) {
 | 
					        let mut cmd = match (self.format, dest_format) {
 | 
				
			||||||
@@ -178,6 +180,13 @@ impl DiskFileInfo {
 | 
				
			|||||||
                cmd
 | 
					                cmd
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Convert QCow2 to Raw file
 | 
				
			||||||
 | 
					            (DiskFileFormat::QCow2 { .. }, DiskFileFormat::Raw { .. }) => {
 | 
				
			||||||
 | 
					                let mut cmd = Command::new(constants::QEMU_IMAGE_PROGRAM);
 | 
				
			||||||
 | 
					                cmd.arg("convert").arg(&self.file_path).arg(&temp_file);
 | 
				
			||||||
 | 
					                cmd
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Dumb copy of file
 | 
					            // Dumb copy of file
 | 
				
			||||||
            (a, b) if a == b => {
 | 
					            (a, b) if a == b => {
 | 
				
			||||||
                let mut cmd = Command::new(constants::COPY_PROGRAM);
 | 
					                let mut cmd = Command::new(constants::COPY_PROGRAM);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user