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