Skip to content

controllers/krate/delete: prevent any crates with rdeps from deletion #10591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/templates/crate/delete.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@

<div local-class="requirements">
<h3>Requirements:</h3>
<p>A crate can only be deleted if either:</p>
<p>
A crate can only be deleted if it is not depended upon by any other crate on crates.io. (This is a temporary
restriction due to
<a
href='https://github.com/rust-lang/crates.io/issues/10538'
target='_blank'
rel='noopener noreferrer'
>#10538</a>.)
</p>
<p>Additionally, a crate can only be deleted if either:</p>
<ol local-class='first'>
<li>the crate has been published for less than 72 hours</li>
</ol>
Expand All @@ -29,8 +38,7 @@
<li>
<ol>
<li>the crate only has a single owner, <em>and</em></li>
<li>the crate has been downloaded less than 500 times for each month it has been published, <em>and</em></li>
<li>the crate is not depended upon by any other crate on crates.io.</li>
<li>the crate has been downloaded less than 500 times for each month it has been published.</li>
</ol>
</li>
</ol>
Expand Down
17 changes: 9 additions & 8 deletions src/controllers/krate/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ pub async fn delete_crate(
let msg = format!("only crates with less than {DOWNLOADS_PER_MONTH_LIMIT} downloads per month can be deleted after 72 hours");
return Err(custom(StatusCode::UNPROCESSABLE_ENTITY, msg));
}
}

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

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

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

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

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

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

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

Expand Down
Loading