Fix DistManifest parsing: Normalize path before verifying

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-10-05 23:34:47 +11:00
parent eb95a3e38f
commit 80522cc60a

View file

@ -1,8 +1,13 @@
use std::collections::BTreeMap; use std::{
collections::BTreeMap,
ffi::OsStr,
path::{Path, PathBuf},
};
use binstalk_downloader::remote::{Client, Response}; use binstalk_downloader::remote::{Client, Response};
use cargo_dist_schema::Format; use cargo_dist_schema::Format;
use compact_str::CompactString; use compact_str::CompactString;
use normalize_path::NormalizePath;
use crate::FetchError; use crate::FetchError;
@ -13,7 +18,7 @@ struct BinaryArtifact {
/// need to infer the format. /// need to infer the format.
filename: CompactString, filename: CompactString,
/// Path to the executable within the tarbal/zip. /// Path to the executable within the tarbal/zip.
path_to_exe: CompactString, path_to_exe: PathBuf,
/// Filename of the checksum file. /// Filename of the checksum file.
checksum_filename: Option<CompactString>, checksum_filename: Option<CompactString>,
@ -46,14 +51,19 @@ impl BinaryArtifact {
let path_to_exe = binary_artifact let path_to_exe = binary_artifact
.assets .assets
.iter() .iter()
.find_map(|asset| match (&asset.kind, asset.path.as_deref()) { .find_map(|asset| {
(&cargo_dist_schema::AssetKind::Executable(_), Some(path)) match (
if path.ends_with(app_name) => &asset.kind,
{ asset.path.as_deref().map(|p| Path::new(p).normalize()),
Some(path) ) {
} (&cargo_dist_schema::AssetKind::Executable(_), Some(path))
if path.file_name() == Some(OsStr::new(app_name)) =>
{
Some(path)
}
_ => None, _ => None,
}
}) })
.ok_or_else(|| { .ok_or_else(|| {
FetchError::InvalidDistManifest( FetchError::InvalidDistManifest(
@ -94,7 +104,7 @@ impl BinaryArtifact {
Ok(Some(( Ok(Some((
Self { Self {
filename: filename.into(), filename: filename.into(),
path_to_exe: path_to_exe.into(), path_to_exe,
checksum_filename, checksum_filename,
}, },
binary_artifact.target_triples.iter(), binary_artifact.target_triples.iter(),