Skip to content
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

admin/delete-crate: Use configurable 24 hour availability delay #10015

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
8 changes: 7 additions & 1 deletion src/bin/crates-admin/delete_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub struct Opts {
/// An optional message explaining why the crate was deleted.
#[arg(long)]
message: Option<String>,

/// The amount of time (in hours) before making the crate available
/// for re-registration.
#[arg(long, default_value = "24")]
availability_delay: i64,
}

pub async fn run(opts: Opts) -> anyhow::Result<()> {
Expand Down Expand Up @@ -75,6 +80,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
}

let now = Utc::now();
let available_at = now + chrono::TimeDelta::hours(opts.availability_delay);

for name in &crate_names {
if let Some(crate_info) = existing_crates.iter().find(|info| info.name == *name) {
Expand All @@ -86,7 +92,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
.deleted_at(&now)
.deleted_by(deleted_by.id)
.maybe_message(opts.message.as_deref())
.available_at(&now)
.available_at(&available_at)
.build();

info!("{name}: Deleting crate from the database…");
Expand Down