mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +00:00
Refactor: Extract CratesToml::append{_to_path}
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
ef72f851f7
commit
31d9716d28
2 changed files with 21 additions and 6 deletions
|
@ -109,12 +109,8 @@ async fn install_from_package(
|
||||||
|
|
||||||
let bins: BTreeSet<String> = bin_files.into_iter().map(|bin| bin.base_name).collect();
|
let bins: BTreeSet<String> = bin_files.into_iter().map(|bin| bin.base_name).collect();
|
||||||
|
|
||||||
{
|
|
||||||
debug!("Writing .crates.toml");
|
debug!("Writing .crates.toml");
|
||||||
let mut c1 = metafiles::v1::CratesToml::load().unwrap_or_default();
|
metafiles::v1::CratesToml::append(cvs.clone(), bins.clone())?;
|
||||||
c1.insert(cvs.clone(), bins.clone());
|
|
||||||
c1.write()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
debug!("Writing .crates2.json");
|
debug!("Writing .crates2.json");
|
||||||
|
|
|
@ -42,6 +42,25 @@ impl CratesToml {
|
||||||
fs::write(path, &toml::to_vec(&self)?)?;
|
fs::write(path, &toml::to_vec(&self)?)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn append_to_path(
|
||||||
|
path: impl AsRef<Path>,
|
||||||
|
cvs: CrateVersionSource,
|
||||||
|
bins: BTreeSet<String>,
|
||||||
|
) -> Result<(), CratesTomlParseError> {
|
||||||
|
let mut c1 = Self::load_from_path(path.as_ref()).unwrap_or_default();
|
||||||
|
c1.insert(cvs, bins);
|
||||||
|
c1.write_to_path(path.as_ref())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn append(
|
||||||
|
cvs: CrateVersionSource,
|
||||||
|
bins: BTreeSet<String>,
|
||||||
|
) -> Result<(), CratesTomlParseError> {
|
||||||
|
Self::append_to_path(Self::default_path()?, cvs, bins)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for CratesToml {
|
impl FromStr for CratesToml {
|
||||||
|
|
Loading…
Add table
Reference in a new issue