Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Support chroot images
Browse files Browse the repository at this point in the history
  • Loading branch information
r-darwish committed Jun 17, 2019
1 parent eddecf8 commit 92f5bdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,14 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
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 boot_partition = storage_device.get_partition(BOOT_PARTITION_INDEX)?;
Expand Down
8 changes: 4 additions & 4 deletions src/storage/loop_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl LoopDevice {
))?
}

Ok(LoopDevice {
path: PathBuf::from(String::from_utf8(output.stdout).unwrap().trim()),
losetup,
})
let path = PathBuf::from(String::from_utf8(output.stdout).unwrap().trim());
info!("Mounted {} to {}", file.display(), path.display());

Ok(LoopDevice { path, losetup })
}

pub fn path(&self) -> &Path {
Expand Down

0 comments on commit 92f5bdf

Please sign in to comment.