ostree/prune: Calculate reachability under exclusive lock
authorJonathan Lebon <jonathan@jlebon.com>
Mon, 30 Jan 2023 18:45:50 +0000 (13:45 -0500)
committerJonathan Lebon <jonathan@jlebon.com>
Mon, 30 Jan 2023 20:08:27 +0000 (15:08 -0500)
commitfb63f7aba8887ca616274abad35db30d93f5839e
treeb8131253012de4bbbefe25c1db75b338d7e3ee27
parentaf505336c2e95820c98fc8e32bce665d5a03c795
ostree/prune: Calculate reachability under exclusive lock

When we calculate the reachability set in `ostree prune`, we do this
without any locking. This means that between the time we build the set
and when we call `ostree_repo_prune_from_reachable`, new content
might've been added. This then causes us to immediately prune that
content since it's not in the now outdated set.

Fix this by calculating the set under an exclusive lock.

I think this is what happened in
https://github.com/fedora-silverblue/issue-tracker/issues/405. While
the pruner was running, the `new-updates-sync` script[1] was importing
content into the repo. The newly imported commits were immediately
deleted by the many `ostree prune --commit-only` calls the pruner does,
breaking the refs.

[1] https://pagure.io/fedora-infra/ansible/blob/35b35127e444/f/roles/bodhi2/backend/files/new-updates-sync#_18
src/ostree/ot-builtin-prune.c
tests/test-prune.sh