mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 20:50:03 +00:00
Optimize: Launch install
immediately if confirmation is not required
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
8ca85382af
commit
90059c11cf
1 changed files with 89 additions and 72 deletions
161
src/main.rs
161
src/main.rs
|
@ -256,57 +256,6 @@ async fn entry() -> Result<()> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut resolutions = Vec::with_capacity(tasks.len());
|
|
||||||
for task in tasks {
|
|
||||||
resolutions.push(await_task(task).await??);
|
|
||||||
}
|
|
||||||
|
|
||||||
for resolution in &resolutions {
|
|
||||||
match resolution {
|
|
||||||
Resolution::Fetch {
|
|
||||||
fetcher, bin_files, ..
|
|
||||||
} => {
|
|
||||||
let fetcher_target = fetcher.target();
|
|
||||||
// Prompt user for confirmation
|
|
||||||
debug!(
|
|
||||||
"Found a binary install source: {} ({fetcher_target})",
|
|
||||||
fetcher.source_name()
|
|
||||||
);
|
|
||||||
|
|
||||||
if fetcher.is_third_party() {
|
|
||||||
warn!(
|
|
||||||
"The package will be downloaded from third-party source {}",
|
|
||||||
fetcher.source_name()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
info!(
|
|
||||||
"The package will be downloaded from {}",
|
|
||||||
fetcher.source_name()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("This will install the following binaries:");
|
|
||||||
for file in bin_files {
|
|
||||||
info!(" - {}", file.preview_bin());
|
|
||||||
}
|
|
||||||
|
|
||||||
if !opts.no_symlinks {
|
|
||||||
info!("And create (or update) the following symlinks:");
|
|
||||||
for file in bin_files {
|
|
||||||
info!(" - {}", file.preview_link());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Resolution::InstallFromSource { .. } => {
|
|
||||||
warn!("The package will be installed from source (with cargo)",)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !opts.dry_run {
|
|
||||||
uithread.confirm().await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let desired_targets = desired_targets.get().await;
|
let desired_targets = desired_targets.get().await;
|
||||||
let target = Arc::from(
|
let target = Arc::from(
|
||||||
desired_targets
|
desired_targets
|
||||||
|
@ -317,10 +266,82 @@ async fn entry() -> Result<()> {
|
||||||
|
|
||||||
let temp_dir_path = Arc::from(temp_dir.path());
|
let temp_dir_path = Arc::from(temp_dir.path());
|
||||||
|
|
||||||
let tasks: Vec<_> = resolutions
|
let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm {
|
||||||
.into_iter()
|
let mut resolutions = Vec::with_capacity(tasks.len());
|
||||||
.map(|resolution| install(resolution, &opts, &temp_dir_path, &target))
|
for task in tasks {
|
||||||
.collect();
|
resolutions.push(await_task(task).await??);
|
||||||
|
}
|
||||||
|
|
||||||
|
for resolution in &resolutions {
|
||||||
|
match resolution {
|
||||||
|
Resolution::Fetch {
|
||||||
|
fetcher, bin_files, ..
|
||||||
|
} => {
|
||||||
|
let fetcher_target = fetcher.target();
|
||||||
|
// Prompt user for confirmation
|
||||||
|
debug!(
|
||||||
|
"Found a binary install source: {} ({fetcher_target})",
|
||||||
|
fetcher.source_name()
|
||||||
|
);
|
||||||
|
|
||||||
|
if fetcher.is_third_party() {
|
||||||
|
warn!(
|
||||||
|
"The package will be downloaded from third-party source {}",
|
||||||
|
fetcher.source_name()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"The package will be downloaded from {}",
|
||||||
|
fetcher.source_name()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("This will install the following binaries:");
|
||||||
|
for file in bin_files {
|
||||||
|
info!(" - {}", file.preview_bin());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !opts.no_symlinks {
|
||||||
|
info!("And create (or update) the following symlinks:");
|
||||||
|
for file in bin_files {
|
||||||
|
info!(" - {}", file.preview_link());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Resolution::InstallFromSource { .. } => {
|
||||||
|
warn!("The package will be installed from source (with cargo)",)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uithread.confirm().await?;
|
||||||
|
|
||||||
|
resolutions
|
||||||
|
.into_iter()
|
||||||
|
.map(|resolution| {
|
||||||
|
tokio::spawn(install(
|
||||||
|
resolution,
|
||||||
|
Arc::clone(&opts),
|
||||||
|
Arc::clone(&temp_dir_path),
|
||||||
|
Arc::clone(&target),
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
tasks
|
||||||
|
.into_iter()
|
||||||
|
.map(|task| {
|
||||||
|
let opts = Arc::clone(&opts);
|
||||||
|
let temp_dir_path = Arc::clone(&temp_dir_path);
|
||||||
|
let target = Arc::clone(&target);
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let resolution = await_task(task).await??;
|
||||||
|
install(resolution, opts, temp_dir_path, target).await
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
for task in tasks {
|
for task in tasks {
|
||||||
await_task(task).await??;
|
await_task(task).await??;
|
||||||
|
@ -501,12 +522,12 @@ fn collect_bin_files(
|
||||||
Ok(bin_files)
|
Ok(bin_files)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install(
|
async fn install(
|
||||||
resolution: Resolution,
|
resolution: Resolution,
|
||||||
opts: &Arc<Options>,
|
opts: Arc<Options>,
|
||||||
temp_dir: &Arc<Path>,
|
temp_dir: Arc<Path>,
|
||||||
target: &Arc<str>,
|
target: Arc<str>,
|
||||||
) -> tokio::task::JoinHandle<Result<()>> {
|
) -> Result<()> {
|
||||||
match resolution {
|
match resolution {
|
||||||
Resolution::Fetch {
|
Resolution::Fetch {
|
||||||
fetcher,
|
fetcher,
|
||||||
|
@ -515,25 +536,21 @@ fn install(
|
||||||
version,
|
version,
|
||||||
bin_path,
|
bin_path,
|
||||||
bin_files,
|
bin_files,
|
||||||
} => tokio::spawn(install_from_package(
|
} => {
|
||||||
fetcher,
|
install_from_package(
|
||||||
opts.clone(),
|
fetcher, opts, package, crate_name, temp_dir, version, bin_path, bin_files,
|
||||||
package,
|
)
|
||||||
crate_name,
|
.await
|
||||||
Arc::clone(temp_dir),
|
}
|
||||||
version,
|
|
||||||
bin_path,
|
|
||||||
bin_files,
|
|
||||||
)),
|
|
||||||
Resolution::InstallFromSource { package } => {
|
Resolution::InstallFromSource { package } => {
|
||||||
if !opts.dry_run {
|
if !opts.dry_run {
|
||||||
tokio::spawn(install_from_source(package, Arc::clone(target)))
|
install_from_source(package, target).await
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"Dry-run: running `cargo install {} --version {} --target {target}`",
|
"Dry-run: running `cargo install {} --version {} --target {target}`",
|
||||||
package.name, package.version
|
package.name, package.version
|
||||||
);
|
);
|
||||||
tokio::spawn(async { Ok(()) })
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue