Skip to content

Commit 8e024c1

Browse files
committed
fix: convert_random_data test
1 parent eccb7ff commit 8e024c1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

goldboot-image/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl TryFrom<String> for ImageArch {
9898
/// file. Clusters are variable in size and ideally smaller than their
9999
/// associated blocks (due to compression). If a block does not have an
100100
/// associated cluster, that block is zero.
101+
#[derive(Debug)]
101102
pub struct ImageHandle {
102103
/// The primary file header
103104
pub primary_header: PrimaryHeader,
@@ -482,7 +483,7 @@ impl ImageHandle {
482483
Aes256Gcm::new(Key::<Aes256Gcm>::from_slice(&protected_header.cluster_key));
483484

484485
let dest = dest.as_ref();
485-
info!(dest = ?dest, "Writing image");
486+
info!(image = ?self, dest = ?dest, "Writing goldboot image");
486487

487488
let mut dest = std::fs::OpenOptions::new()
488489
.create(true)
@@ -626,8 +627,12 @@ impl ImageBuilder {
626627
pub fn convert(self, source: &Qcow3, size: u64) -> Result<ImageHandle> {
627628
info!(name = self.name, "Exporting storage to goldboot image");
628629

629-
// The requested goldboot image must be at least as large as the qcow
630-
assert!(source.header.size <= size);
630+
assert!(
631+
source.header.size >= size,
632+
"source.header.size = {}, size = {}",
633+
source.header.size,
634+
size
635+
);
631636

632637
let mut dest_file = File::create(&self.dest)?;
633638
let mut source_file = File::open(&source.path)?;
@@ -652,7 +657,7 @@ impl ImageBuilder {
652657
let mut primary_header = PrimaryHeader {
653658
version: 1,
654659
arch: ImageArch::Amd64, // TODO
655-
size: source.header.size,
660+
size,
656661
directory_nonce: rng.gen::<[u8; 12]>(),
657662
directory_offset: 0,
658663
directory_size: 0,

goldboot-image/src/qcow/levels.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl L2Entry {
7979
}
8080
}
8181

82-
/// Read the contents of a given L2 Entry from `reader` into `buf`.
82+
/// Read the contents of a given L2 Entry from `reader`.
8383
pub fn read_contents(
8484
&self,
8585
reader: &mut (impl Read + Seek),
@@ -90,10 +90,11 @@ impl L2Entry {
9090
match &self.cluster_descriptor {
9191
ClusterDescriptor::Standard(cluster) => {
9292
if cluster.all_zeroes || cluster.host_cluster_offset == 0 {
93+
// TODO size properly
9394
buf.fill(0);
9495
} else {
9596
reader.seek(SeekFrom::Start(cluster.host_cluster_offset))?;
96-
let r = reader.take(cluster_size).read_to_end(&mut buf)?;
97+
reader.take(cluster_size).read_to_end(&mut buf)?;
9798
}
9899
}
99100
ClusterDescriptor::Compressed(cluster) => match comp_type {

0 commit comments

Comments
 (0)