Skip to content

Commit dca6e84

Browse files
authored
controllers/krate/delete: prevent any crates with rdeps from deletion (#10591)
Temporary hack while we discuss #10538 further.
1 parent f9d6ebb commit dca6e84

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

app/templates/crate/delete.hbs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@
2020

2121
<div local-class="requirements">
2222
<h3>Requirements:</h3>
23-
<p>A crate can only be deleted if either:</p>
23+
<p>
24+
A crate can only be deleted if it is not depended upon by any other crate on crates.io. (This is a temporary
25+
restriction due to
26+
<a
27+
href='https://github.com/rust-lang/crates.io/issues/10538'
28+
target='_blank'
29+
rel='noopener noreferrer'
30+
>#10538</a>.)
31+
</p>
32+
<p>Additionally, a crate can only be deleted if either:</p>
2433
<ol local-class='first'>
2534
<li>the crate has been published for less than 72 hours</li>
2635
</ol>
@@ -29,8 +38,7 @@
2938
<li>
3039
<ol>
3140
<li>the crate only has a single owner, <em>and</em></li>
32-
<li>the crate has been downloaded less than 500 times for each month it has been published, <em>and</em></li>
33-
<li>the crate is not depended upon by any other crate on crates.io.</li>
41+
<li>the crate has been downloaded less than 500 times for each month it has been published.</li>
3442
</ol>
3543
</li>
3644
</ol>

src/controllers/krate/delete.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ pub async fn delete_crate(
9494
let msg = format!("only crates with less than {DOWNLOADS_PER_MONTH_LIMIT} downloads per month can be deleted after 72 hours");
9595
return Err(custom(StatusCode::UNPROCESSABLE_ENTITY, msg));
9696
}
97+
}
9798

98-
if has_rev_dep(&mut conn, krate.id).await? {
99-
let msg = "only crates without reverse dependencies can be deleted after 72 hours";
100-
return Err(custom(StatusCode::UNPROCESSABLE_ENTITY, msg));
101-
}
99+
// Temporary hack to mitigate https://github.com/rust-lang/crates.io/issues/10538: all crates
100+
// with reverse dependencies are currently blocked from being deleted to avoid unexpected
101+
// historical index changes.
102+
if has_rev_dep(&mut conn, krate.id).await? {
103+
let msg = "only crates without reverse dependencies can be deleted";
104+
return Err(custom(StatusCode::UNPROCESSABLE_ENTITY, msg));
102105
}
103106

104107
let crate_name = krate.name.clone();
@@ -491,11 +494,9 @@ mod tests {
491494

492495
#[tokio::test(flavor = "multi_thread")]
493496
async fn test_rev_deps() -> anyhow::Result<()> {
494-
let (app, anon, user) = TestApp::full().with_user().await;
495-
let mut conn = app.db_conn().await;
497+
let (_app, anon, user) = TestApp::full().with_user().await;
496498

497499
publish_crate(&user, "foo").await;
498-
adjust_creation_date(&mut conn, "foo", 73).await?;
499500

500501
// Publish another crate
501502
let pb = PublishBuilder::new("bar", "1.0.0").dependency(DependencyBuilder::new("foo"));
@@ -504,7 +505,7 @@ mod tests {
504505

505506
let response = delete_crate(&user, "foo").await;
506507
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
507-
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"only crates without reverse dependencies can be deleted after 72 hours"}]}"#);
508+
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"only crates without reverse dependencies can be deleted"}]}"#);
508509

509510
assert_crate_exists(&anon, "foo", true).await;
510511

0 commit comments

Comments
 (0)