Skip crates that are already installed.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-05 00:06:36 +10:00
parent 04fee49c22
commit ac085533cc
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -333,6 +333,25 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
fs::create_dir_all(&install_path).map_err(BinstallError::Io)?; fs::create_dir_all(&install_path).map_err(BinstallError::Io)?;
debug!("Using install path: {}", install_path.display()); debug!("Using install path: {}", install_path.display());
// Load metadata
let metadata = if !custom_install_path {
debug!("Reading binstall/crates-v1.json");
Some(metafiles::binstall_v1::Records::load()?)
} else {
None
};
// Filter out installed crate_names
let crate_names = crate_names.filter(|crate_name| {
if opts.force {
true
} else if let Some(records) = &metadata {
!records.contains(&crate_name.name)
} else {
true
}
});
// Create a temporary directory for downloads etc. // Create a temporary directory for downloads etc.
// //
// Put all binaries to a temporary directory under `dst` first, catching // Put all binaries to a temporary directory under `dst` first, catching
@ -429,7 +448,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
} }
block_in_place(|| { block_in_place(|| {
if !custom_install_path { if let Some(mut records) = metadata {
// If using standardised install path, // If using standardised install path,
// then create_dir_all(&install_path) would also // then create_dir_all(&install_path) would also
// create .cargo. // create .cargo.
@ -438,7 +457,10 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
metafiles::v1::CratesToml::append(metadata_vec.iter())?; metafiles::v1::CratesToml::append(metadata_vec.iter())?;
debug!("Writing binstall/crates-v1.json"); debug!("Writing binstall/crates-v1.json");
metafiles::binstall_v1::append(metadata_vec)?; for metadata in metadata_vec {
records.replace(metadata);
}
records.overwrite()?;
} }
if opts.no_cleanup { if opts.no_cleanup {