Fix FileLock for .crates.toml not dropped (#697)

* Fix `FileLock` for `.crates.toml` not dropped

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Rm unneccessary ret type annotation for the closure

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Add regression test

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-01-12 16:45:36 +11:00 committed by GitHub
parent 87854d8cc4
commit 1be25f81b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 30 deletions

View file

@ -7,7 +7,7 @@ use binstalk::{
helpers::{jobserver_client::LazyJobserverClient, remote::Client, tasks::AutoAbortJoinHandle}, helpers::{jobserver_client::LazyJobserverClient, remote::Client, tasks::AutoAbortJoinHandle},
ops::{ ops::{
self, self,
resolve::{CrateName, Resolution, VersionReqExt}, resolve::{CrateName, Resolution, ResolutionFetch, VersionReqExt},
Resolver, Resolver,
}, },
}; };
@ -146,35 +146,14 @@ pub async fn install_crates(args: Args, jobserver_client: LazyJobserverClient) -
confirm().await?; confirm().await?;
} }
if !resolution_fetchs.is_empty() { do_install_fetches(
if dry_run { resolution_fetchs,
info!("Dry-run: Not proceeding to install fetched binaries"); manifests,
} else { &binstall_opts,
let f = || -> Result<()> { dry_run,
let metadata_vec = resolution_fetchs temp_dir,
.into_iter() no_cleanup,
.map(|fetch| fetch.install(&binstall_opts)) )?;
.collect::<Result<Vec<_>, BinstallError>>()?;
if let Some(manifests) = manifests {
manifests.update(metadata_vec)?;
}
if no_cleanup {
// Consume temp_dir without removing it from fs.
temp_dir.into_path();
} else {
temp_dir.close().unwrap_or_else(|err| {
warn!("Failed to clean up some resources: {err}");
});
}
Ok(())
};
block_in_place(f)?;
}
}
let tasks: Vec<_> = resolution_sources let tasks: Vec<_> = resolution_sources
.into_iter() .into_iter()
@ -276,3 +255,45 @@ fn filter_out_installed_crates(
} }
})) }))
} }
#[allow(clippy::vec_box)]
fn do_install_fetches(
resolution_fetchs: Vec<Box<ResolutionFetch>>,
// Take manifests by value to drop the `FileLock`.
manifests: Option<Manifests>,
binstall_opts: &ops::Options,
dry_run: bool,
temp_dir: tempfile::TempDir,
no_cleanup: bool,
) -> Result<()> {
if resolution_fetchs.is_empty() {
return Ok(());
}
if dry_run {
info!("Dry-run: Not proceeding to install fetched binaries");
return Ok(());
}
block_in_place(|| {
let metadata_vec = resolution_fetchs
.into_iter()
.map(|fetch| fetch.install(binstall_opts))
.collect::<Result<Vec<_>, BinstallError>>()?;
if let Some(manifests) = manifests {
manifests.update(metadata_vec)?;
}
if no_cleanup {
// Consume temp_dir without removing it from fs.
temp_dir.into_path();
} else {
temp_dir.close().unwrap_or_else(|err| {
warn!("Failed to clean up some resources: {err}");
});
}
Ok(())
})
}

View file

@ -24,3 +24,6 @@ if [ "$exit_code" != 94 ]; then
echo "Expected exit code 94, but actual exit code $exit_code" echo "Expected exit code 94, but actual exit code $exit_code"
exit 1 exit 1
fi fi
## Test compile-only strategy
"./$1" binstall --no-confirm --strategies compile cargo-quickinstall