Refactor: Extract new crate binstalk-bins (#1294)

To reduce `binstalk` codegen and enable reuse of it.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-08-16 07:48:42 +10:00 committed by GitHub
parent 76c72469eb
commit 0c5a65fb35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 114 additions and 87 deletions

View file

@ -261,7 +261,7 @@ async fn download_extract_and_verify(
.iter()
.zip(bin_files)
.filter_map(|(bin, bin_file)| {
match bin_file.check_source_exists(&extracted_files) {
match bin_file.check_source_exists(&mut |p| extracted_files.has_file(p)) {
Ok(()) => Some(Ok(bin_file)),
// This binary is optional
@ -284,7 +284,8 @@ async fn download_extract_and_verify(
}
}
})
.collect::<Result<Vec<bins::BinFile>, BinstallError>>()
.collect::<Result<Vec<bins::BinFile>, bins::Error>>()
.map_err(BinstallError::from)
}
fn collect_bin_files(
@ -314,7 +315,9 @@ fn collect_bin_files(
.bin_dir
.as_deref()
.map(Cow::Borrowed)
.unwrap_or_else(|| bins::infer_bin_dir_template(&bin_data, extracted_files));
.unwrap_or_else(|| {
bins::infer_bin_dir_template(&bin_data, &mut |p| extracted_files.get_dir(p).is_some())
});
let template = Template::parse(&bin_dir)?;
@ -323,7 +326,7 @@ fn collect_bin_files(
.binaries
.iter()
.map(|bin| bins::BinFile::new(&bin_data, bin.name.as_str(), &template, no_symlinks))
.collect::<Result<Vec<_>, BinstallError>>()?;
.collect::<Result<Vec<_>, bins::Error>>()?;
let mut source_set = BTreeSet::new();

View file

@ -51,7 +51,7 @@ impl Resolution {
impl ResolutionFetch {
pub fn install(self, opts: &Options) -> Result<CrateInfo, BinstallError> {
type InstallFp = fn(&bins::BinFile) -> Result<(), BinstallError>;
type InstallFp = fn(&bins::BinFile) -> Result<(), bins::Error>;
let (install_bin, install_link): (InstallFp, InstallFp) = match (opts.no_track, opts.force)
{