lanzatool: improve esp_relative_path_string error msg

This commit is contained in:
nikstur 2022-12-30 01:39:54 +01:00
parent f4e4ad9c3b
commit 781651b9e0
1 changed files with 5 additions and 5 deletions

View File

@ -32,7 +32,7 @@ pub fn lanzaboote_image(
let kernel_path_file = write_to_tmp(
target_dir,
"kernel-esp-path",
esp_relative_path_string(esp, kernel_path),
esp_relative_path_string(esp, kernel_path)?,
)?;
let kernel_hash_file = write_to_tmp(
target_dir,
@ -43,7 +43,7 @@ pub fn lanzaboote_image(
let initrd_path_file = write_to_tmp(
target_dir,
"initrd-esp-path",
esp_relative_path_string(esp, initrd_path),
esp_relative_path_string(esp, initrd_path)?,
)?;
let initrd_hash_file = write_to_tmp(
target_dir,
@ -167,17 +167,17 @@ fn write_to_tmp(
Ok(path)
}
fn esp_relative_path_string(esp: &Path, path: &Path) -> String {
fn esp_relative_path_string(esp: &Path, path: &Path) -> Result<String> {
let relative_path = path
.strip_prefix(esp)
.expect("Failed to make path relative to esp")
.with_context(|| format!("Failed to strip prefix: {:?} from path: {:?}", esp, path))?
.to_owned();
let relative_path_string = relative_path
.into_os_string()
.into_string()
.expect("Failed to convert path '{}' to a relative string path")
.replace('/', "\\");
format!("\\{}", &relative_path_string)
Ok(format!("\\{}", &relative_path_string))
}
fn stub_offset(binary: &Path) -> Result<u64> {