Support chroot images

This commit is contained in:
Roey Darwish Dror 2019-06-17 20:56:26 +03:00
parent eddecf8c6b
commit 92f5bdfeab
2 changed files with 12 additions and 5 deletions

View File

@ -330,7 +330,14 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
None None
}; };
let storage_device = storage::StorageDevice::from_path(&command.block_device)?; let mut loop_device: Option<LoopDevice>;
let storage_device = match storage::StorageDevice::from_path(&command.block_device) {
Ok(b) => b,
Err(_) => {
loop_device = Some(LoopDevice::create(&command.block_device)?);
storage::StorageDevice::from_path(loop_device.as_ref().unwrap().path())?
}
};
let mount_point = tempdir().context(ErrorKind::TmpDirError)?; let mount_point = tempdir().context(ErrorKind::TmpDirError)?;
let boot_partition = storage_device.get_partition(BOOT_PARTITION_INDEX)?; let boot_partition = storage_device.get_partition(BOOT_PARTITION_INDEX)?;

View File

@ -26,10 +26,10 @@ impl LoopDevice {
))? ))?
} }
Ok(LoopDevice { let path = PathBuf::from(String::from_utf8(output.stdout).unwrap().trim());
path: PathBuf::from(String::from_utf8(output.stdout).unwrap().trim()), info!("Mounted {} to {}", file.display(), path.display());
losetup,
}) Ok(LoopDevice { path, losetup })
} }
pub fn path(&self) -> &Path { pub fn path(&self) -> &Path {