Skip to content

Commit 41bb83c

Browse files
authored
reuploading TUF repo marks it unpruned (#9212)
Fixes #9138.
1 parent e25179a commit 41bb83c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

nexus/db-queries/src/db/datastore/update.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ async fn insert_impl(
546546
.await
547547
.optional()?;
548548

549-
if let Some(existing_repo) = existing_repo {
549+
if let Some(mut existing_repo) = existing_repo {
550550
// It doesn't matter whether the UUID of the repo matches or not,
551551
// since it's uniquely generated. But do check the hash.
552552
if existing_repo.sha256 != desc.repo.sha256 {
@@ -557,6 +557,19 @@ async fn insert_impl(
557557
}));
558558
}
559559

560+
// This repo matches a previous record, so reset `time_created` to
561+
// now and ensure `time_pruned` is set to NULL.
562+
existing_repo.time_created = chrono::Utc::now();
563+
existing_repo.time_pruned = None;
564+
diesel::update(dsl::tuf_repo)
565+
.filter(dsl::id.eq(existing_repo.id))
566+
.set((
567+
dsl::time_created.eq(existing_repo.time_created),
568+
dsl::time_pruned.eq(existing_repo.time_pruned),
569+
))
570+
.execute_async(&conn)
571+
.await?;
572+
560573
// Just return the existing repo along with all of its artifacts.
561574
let artifacts =
562575
artifacts_for_repo(existing_repo.id.into(), &conn).await?;

nexus/tests/integration_tests/updates.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,34 @@ async fn test_repo_prune(cptestctx: &ControlPlaneTestContext) {
831831
assert!(repos.iter().any(|r| r.id() == repo2id));
832832
assert!(repos.iter().any(|r| r.id() == repo3id));
833833
assert!(repos.iter().any(|r| r.id() == repo4id));
834+
835+
// Re-insert repo 1.
836+
let repo1id_again = insert_test_tuf_repo(&opctx, datastore, 1).await;
837+
// The ID should be the same.
838+
assert_eq!(repo1id, repo1id_again);
839+
// All four repos should be visible again.
840+
let repos = datastore
841+
.tuf_list_repos_unpruned_batched(&opctx)
842+
.await
843+
.expect("listing repos");
844+
assert_eq!(repos.len(), 4);
845+
assert!(repos.iter().any(|r| r.id() == repo1id));
846+
assert!(repos.iter().any(|r| r.id() == repo2id));
847+
assert!(repos.iter().any(|r| r.id() == repo3id));
848+
assert!(repos.iter().any(|r| r.id() == repo4id));
849+
850+
// Activate the task again and wait for it to complete. The second repo
851+
// should now be pruned, since it is the least-recently uploaded.
852+
activate_background_task(client, "tuf_repo_pruner").await;
853+
let repos = datastore
854+
.tuf_list_repos_unpruned_batched(&opctx)
855+
.await
856+
.expect("listing repos");
857+
assert_eq!(repos.len(), 3);
858+
assert!(repos.iter().any(|r| r.id() == repo1id));
859+
assert!(!repos.iter().any(|r| r.id() == repo2id));
860+
assert!(repos.iter().any(|r| r.id() == repo3id));
861+
assert!(repos.iter().any(|r| r.id() == repo4id));
834862
}
835863

836864
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

0 commit comments

Comments
 (0)