Skip to content

Commit 186c8b7

Browse files
committed
qa
Signed-off-by: Jan Zachmann <[email protected]>
1 parent 3d59ccf commit 186c8b7

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/lib.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
anyhow::ensure!(
6969
image_file.try_exists().is_ok_and(|exists| exists),
7070
"run_image_command: image doesn't exist {}",
71-
image_file.to_str().unwrap()
71+
image_file.to_str().context("cannot get image file path")?
7272
);
7373

7474
let mut dest_image_file = image_file.clone();
@@ -77,12 +77,16 @@ where
7777
let tmp_dir = PathBuf::from(format!("/tmp/{}", Uuid::new_v4()));
7878
fs::create_dir_all(tmp_dir.clone()).context(format!(
7979
"run_image_command: couldn't create destination path {}",
80-
tmp_dir.to_str().unwrap()
80+
tmp_dir.to_str().context("cannot tmp dir name")?
8181
))?;
8282

8383
let _guard = TempDirGuard(tmp_dir.clone());
8484

85-
let mut tmp_image_file = tmp_dir.join(image_file.file_name().unwrap());
85+
let mut tmp_image_file = tmp_dir.join(
86+
image_file
87+
.file_name()
88+
.context("cannot get image file name")?,
89+
);
8690

8791
// if applicable decompress image to *.wic
8892
if let Some(source_compression) = Compression::from_file(&image_file)? {
@@ -102,10 +106,22 @@ where
102106

103107
// create and copy back bmap file if one was created
104108
if generate_bmap {
105-
let mut target_bmap = image_file.parent().unwrap().to_path_buf();
106-
let tmp_bmap = PathBuf::from(format!("{}.bmap", tmp_image_file.to_str().unwrap()));
107-
file::functions::generate_bmap_file(tmp_image_file.to_str().unwrap())?;
108-
target_bmap.push(tmp_bmap.file_name().unwrap());
109+
let mut target_bmap = image_file
110+
.parent()
111+
.context("cannot get image path parent")?
112+
.to_path_buf();
113+
let tmp_bmap = PathBuf::from(format!(
114+
"{}.bmap",
115+
tmp_image_file
116+
.to_str()
117+
.context("cannot get image file path")?
118+
));
119+
file::functions::generate_bmap_file(
120+
tmp_image_file
121+
.to_str()
122+
.context("cannot get image file path")?,
123+
)?;
124+
target_bmap.push(tmp_bmap.file_name().context("cannot get bmap file name")?);
109125
std::fs::copy(&tmp_bmap, &target_bmap).context(format!(
110126
"error: std::fs::copy({:?}, {:?})",
111127
tmp_bmap, target_bmap
@@ -115,7 +131,11 @@ where
115131
// if applicable compress image
116132
if let Some(c) = target_compression {
117133
tmp_image_file = compression::compress(&tmp_image_file, &c)?;
118-
dest_image_file.set_file_name(tmp_image_file.file_name().unwrap());
134+
dest_image_file.set_file_name(
135+
tmp_image_file
136+
.file_name()
137+
.context("cannot get image file name")?,
138+
);
119139
std::fs::copy(&tmp_image_file, &dest_image_file).context(format!(
120140
"error: std::fs::copy({:?}, {:?})",
121141
tmp_image_file, dest_image_file

0 commit comments

Comments
 (0)