Skip to content

Commit 9d1f7c3

Browse files
committed
admin/delete_version: Move user confirmation outside of spawn_blocking() callback
1 parent bc300e4 commit 9d1f7c3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/admin/delete_version.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
4545
.context("Failed to look up crate id from the database")
4646
}?;
4747

48-
let opts = spawn_blocking::<_, _, anyhow::Error>(move || {
49-
use diesel::RunQueryDsl;
50-
51-
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
52-
48+
{
5349
let crate_name = &opts.crate_name;
5450

5551
println!("Deleting the following versions of the `{crate_name}` crate:");
@@ -59,9 +55,20 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
5955
}
6056
println!();
6157

62-
if !opts.yes && !dialoguer::confirm("Do you want to permanently delete these versions?")? {
63-
return Ok(opts);
58+
if !opts.yes
59+
&& !dialoguer::async_confirm("Do you want to permanently delete these versions?")
60+
.await?
61+
{
62+
return Ok(());
6463
}
64+
}
65+
66+
let opts = spawn_blocking::<_, _, anyhow::Error>(move || {
67+
use diesel::RunQueryDsl;
68+
69+
let conn: &mut AsyncConnectionWrapper<_> = &mut conn.into();
70+
71+
let crate_name = &opts.crate_name;
6572

6673
conn.transaction(|conn| {
6774
info!(%crate_name, %crate_id, versions = ?opts.versions, "Deleting versions from the database");

0 commit comments

Comments
 (0)