Can convert QCow2 to raw file
This commit is contained in:
parent
3ffc64f129
commit
b9353326f5
@ -35,7 +35,7 @@ pub enum DiskFileFormat {
|
||||
impl DiskFileFormat {
|
||||
pub fn ext(&self) -> &'static [&'static str] {
|
||||
match self {
|
||||
DiskFileFormat::Raw { .. } => &["", "raw"],
|
||||
DiskFileFormat::Raw { .. } => &["raw", ""],
|
||||
DiskFileFormat::QCow2 { .. } => &["qcow2"],
|
||||
DiskFileFormat::CompressedRaw => &["raw.gz"],
|
||||
DiskFileFormat::CompressedQCow2 => &["qcow2.gz"],
|
||||
@ -153,7 +153,9 @@ impl DiskFileInfo {
|
||||
pub fn convert(&self, dest_file: &Path, dest_format: DiskFileFormat) -> anyhow::Result<()> {
|
||||
// Create a temporary directory to perform the operation
|
||||
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
|
||||
let mut cmd = match (self.format, dest_format) {
|
||||
@ -178,6 +180,13 @@ impl DiskFileInfo {
|
||||
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
|
||||
(a, b) if a == b => {
|
||||
let mut cmd = Command::new(constants::COPY_PROGRAM);
|
||||
|
Loading…
x
Reference in New Issue
Block a user