mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
commit
d2ab613652
2 changed files with 40 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
use std::{
|
||||
ffi::OsString,
|
||||
fs,
|
||||
mem::take,
|
||||
path::{Path, PathBuf},
|
||||
process::{ExitCode, Termination},
|
||||
|
@ -295,6 +296,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
|||
error!("No viable install path found of specified, try `--install-path`");
|
||||
miette!("No install path found or specified")
|
||||
})?;
|
||||
fs::create_dir_all(&install_path).map_err(BinstallError::Io)?;
|
||||
debug!("Using install path: {}", install_path.display());
|
||||
|
||||
// Create a temporary directory for downloads etc.
|
||||
|
@ -393,6 +395,10 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
|||
|
||||
block_in_place(|| {
|
||||
if !custom_install_path {
|
||||
// If using standardised install path,
|
||||
// then create_dir_all(&install_path) would also
|
||||
// create .cargo.
|
||||
|
||||
debug!("Writing .crates.toml");
|
||||
metafiles::v1::CratesToml::append(metadata_vec.iter())?;
|
||||
|
||||
|
|
|
@ -74,7 +74,11 @@ impl CratesToml {
|
|||
Iter: IntoIterator<Item = &'a MetaData>,
|
||||
{
|
||||
let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?;
|
||||
let mut c1 = Self::load_from_reader(&mut *file)?;
|
||||
let mut c1 = if file.metadata()?.len() != 0 {
|
||||
Self::load_from_reader(&mut *file)?
|
||||
} else {
|
||||
Self::default()
|
||||
};
|
||||
|
||||
for metadata in iter {
|
||||
c1.insert(&CrateVersionSource::from(metadata), metadata.bins.clone());
|
||||
|
@ -108,3 +112,32 @@ pub enum CratesTomlParseError {
|
|||
#[error(transparent)]
|
||||
CvsParse(#[from] super::CvsParseError),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{super::binstall_v1, *};
|
||||
use crate::target::TARGET;
|
||||
|
||||
use semver::Version;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let tempdir = TempDir::new().unwrap();
|
||||
let path = tempdir.path().join("crates-v1.toml");
|
||||
|
||||
CratesToml::append_to_path(
|
||||
&path,
|
||||
&[MetaData {
|
||||
name: "cargo-binstall".into(),
|
||||
version_req: "*".into(),
|
||||
current_version: Version::new(0, 11, 1),
|
||||
source: binstall_v1::Source::cratesio_registry(),
|
||||
target: TARGET.into(),
|
||||
bins: vec!["cargo-binstall".into()],
|
||||
other: Default::default(),
|
||||
}],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue