mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-01 08:32:55 +00:00
Merge pull request #249 from NobodyXu/optimmiz
Optimze updating `CratesToml`
This commit is contained in:
commit
900186e57d
5 changed files with 35 additions and 9 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -129,6 +129,7 @@ dependencies = [
|
|||
"bzip2",
|
||||
"cargo_toml",
|
||||
"clap",
|
||||
"compact_str",
|
||||
"crates_io_api",
|
||||
"dirs",
|
||||
"embed-resource",
|
||||
|
@ -173,6 +174,15 @@ dependencies = [
|
|||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "castaway"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.73"
|
||||
|
@ -257,6 +267,18 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5857fc4f27cd0fa2cd7c4a4fa780c0da3d898ae27e66bf6a719343e219e9a559"
|
||||
dependencies = [
|
||||
"castaway",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
|
|
|
@ -24,6 +24,7 @@ bytes = "1.2.0"
|
|||
bzip2 = "0.4.3"
|
||||
cargo_toml = "0.11.5"
|
||||
clap = { version = "3.2.14", features = ["derive"] }
|
||||
compact_str = { version = "0.5.2", features = ["serde"] }
|
||||
crates_io_api = { version = "0.8.0", default-features = false }
|
||||
dirs = "4.0.0"
|
||||
flate2 = { version = "1.0.24", default-features = false }
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use cargo_toml::Product;
|
||||
use compact_str::CompactString;
|
||||
use log::debug;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{atomic_install, atomic_symlink_file, BinstallError, PkgFmt, PkgMeta, Template};
|
||||
|
||||
pub struct BinFile {
|
||||
pub base_name: String,
|
||||
pub base_name: CompactString,
|
||||
pub source: PathBuf,
|
||||
pub dest: PathBuf,
|
||||
pub link: PathBuf,
|
||||
|
@ -15,7 +16,7 @@ pub struct BinFile {
|
|||
|
||||
impl BinFile {
|
||||
pub fn from_product(data: &Data, product: &Product) -> Result<Self, BinstallError> {
|
||||
let base_name = product.name.clone().unwrap();
|
||||
let base_name = CompactString::from(product.name.clone().unwrap());
|
||||
|
||||
let binary_ext = if data.target.contains("windows") {
|
||||
".exe"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::collections::BTreeSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use compact_str::CompactString;
|
||||
|
||||
use crate::{metafiles, DesiredTargets, PkgOverride};
|
||||
|
||||
mod resolve;
|
||||
|
@ -20,7 +21,7 @@ pub struct Options {
|
|||
|
||||
/// MetaData required to update MetaFiles.
|
||||
pub struct MetaData {
|
||||
pub bins: BTreeSet<String>,
|
||||
pub bins: Vec<CompactString>,
|
||||
pub cvs: metafiles::CrateVersionSource,
|
||||
pub version_req: String,
|
||||
pub target: String,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
collections::BTreeMap,
|
||||
fs::File,
|
||||
io::{self, Seek},
|
||||
iter::IntoIterator,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use compact_str::CompactString;
|
||||
use miette::Diagnostic;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
@ -15,7 +16,7 @@ use crate::{cargo_home, create_if_not_exist, FileLock};
|
|||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct CratesToml {
|
||||
v1: BTreeMap<String, BTreeSet<String>>,
|
||||
v1: BTreeMap<String, Vec<CompactString>>,
|
||||
}
|
||||
|
||||
impl CratesToml {
|
||||
|
@ -38,7 +39,7 @@ impl CratesToml {
|
|||
Self::load_from_reader(file)
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, cvs: &CrateVersionSource, bins: BTreeSet<String>) {
|
||||
pub fn insert(&mut self, cvs: &CrateVersionSource, bins: Vec<CompactString>) {
|
||||
self.v1.insert(cvs.to_string(), bins);
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ impl CratesToml {
|
|||
iter: Iter,
|
||||
) -> Result<(), CratesTomlParseError>
|
||||
where
|
||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, BTreeSet<String>)>,
|
||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<CompactString>)>,
|
||||
{
|
||||
let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?;
|
||||
let mut c1 = Self::load_from_reader(&mut *file)?;
|
||||
|
@ -87,7 +88,7 @@ impl CratesToml {
|
|||
|
||||
pub fn append<'a, Iter>(iter: Iter) -> Result<(), CratesTomlParseError>
|
||||
where
|
||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, BTreeSet<String>)>,
|
||||
Iter: IntoIterator<Item = (&'a CrateVersionSource, Vec<CompactString>)>,
|
||||
{
|
||||
Self::append_to_path(Self::default_path()?, iter)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue