Fix error logging

ok_or will unconditionally creates a LoggedResult, which prints
an error even it successes. Use ok_or_else which lazily creates
a LoggedResult only if it fails.
This commit is contained in:
LoveSy
2023-07-07 01:01:11 +08:00
committed by John Wu
parent 75ba62d588
commit af2207433d
2 changed files with 10 additions and 5 deletions
+4 -2
View File
@@ -157,9 +157,11 @@ fn do_extract_boot_from_payload(
for ext in operation.dst_extents.iter() {
let out_seek = ext
.start_block
.ok_or(bad_payload!("start block not found"))?
.ok_or_else(|| bad_payload!("start block not found"))?
* block_size;
let num_blocks = ext.num_blocks.ok_or(bad_payload!("num blocks not found"))?;
let num_blocks = ext
.num_blocks
.ok_or_else(|| bad_payload!("num blocks not found"))?;
out_file.seek(SeekFrom::Start(out_seek))?;
out_file.write_zeros(num_blocks as usize)?;
}