Skip to content

Base: always create parent dirs for system repo lock - #3105

Open
evan-goode wants to merge 1 commit into
rpm-software-management:mainfrom
evan-goode:evan-goode/create-lock-dirs
Open

evan-goode wants to merge 1 commit into
rpm-software-management:mainfrom
evan-goode:evan-goode/create-lock-dirs

Conversation

@evan-goode

Copy link
Copy Markdown
Member

The lock directory may have been removed in between calls to lock_system_repo/unlock_system_repo. This change is primarily motivated by a seemingly spontaneous failure I noticed in RpmTransactionTest::test_source_date_epoch_sorting, which calls std::filesystem::remove_all(installroot) multiple times without resetting the Base. In the real world, this parent directory should not just vanish under normal circumstances, so we could resolve this failure by recreating the lock dir in the test instead. But doing it in lock_system_repo is a bit more defensive.

The lock directory may have been removed in between calls to
lock_system_repo/unlock_system_repo. This change is primarily motivated
by a seemingly spontaneous failure I noticed in
RpmTransactionTest::test_source_date_epoch_sorting, which calls
std::filesystem::remove_all(installroot) multiple times without
resetting the Base. In the real world, this parent directory should not
just vanish under normal circumstances, so we could resolve this failure
by recreating it in the test instead. But doing it in lock_system_repo
is a bit more defensive.
@evan-goode
evan-goode requested a review from a team as a code owner December 4, 2026 22:39
@evan-goode
evan-goode requested review from fhbash and removed request for a team December 4, 2026 22:39
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Base: always create parent dirs for system repo lock

🐞 Bug fix 🕐 Less than 10 minutes


AI Description

• Recreates the lock file's parent directory on every lock_system_repo call.
• Fixes failures when the lock directory is removed between lock and unlock calls.
• Moves the installroot lock call out of the one-time branch; it is idempotent.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • Repository loading and transaction execution both use the same Base-owned system-repository lock to coordinate reads and writes; they are related outcomes within one bounded system-repository integration, not independent technical layers.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, installroot locking and path preparation occurred only when system_repo_lock was absent.
  • After, those operations occur on every call while Locker construction remains conditional.
  • The new correctness condition is that repeated calls and failed-then-retried lock acquisition must preserve one stable lock object and path while reapplying configuration protection; this interacts with the present/absent and held/unheld lock states.
  • The changed logic does not introduce a new algorithm or concurrency protocol.
Potential damage 🔴 High 🩹 Integrity

  • If the changed setup allowed a lock to be created for the wrong path or failed to preserve synchronization during retries, concurrent RPM database access could corrupt system-repository state.
  • No concrete fault is established by the inspected source.
  • Reverting prevents further affected lock behavior, but already corrupted persistent RPM database state may require validation or repair; external package effects may require compensation.
Assessed commit 9dc5030
Diagram

graph TD
A["Base::lock_system_repo"] --> B["create_directories(parent)"] --> C["Create Locker if unset"] --> D[("Lock file")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Recreate the lock directory in the test only
  • ➕ Smallest blast radius, touches only the exposing test
  • ➕ No change to the production locking path
  • ➖ Production stays exposed if the directory is removed externally
  • ➖ Does not address the root cause for other callers
2. Create the directory once in the Locker constructor or at Base init
  • ➕ No extra mkdir call on repeat lock acquisitions
  • ➕ Centralizes directory setup
  • ➖ Still fails if the directory is removed after init, which is the scenario being fixed
  • ➖ Requires lifecycle changes to Base construction

Recommendation: The PR's approach is sound. An mkdir -p on each acquisition is cheap and covers external removal between calls. Fixing only the test leaves production exposed. Caveat: an already-open Locker is not protected; only re-acquisition after removal is covered. Moving installroot_option.lock() outside the one-time branch is safe because Option::lock returns early when already locked.

Files changed (1) +8 / -8

Bug fix (1) +8 / -8
base.cppAlways create lock file parent directory before locking +8/-8

Always create lock file parent directory before locking

• Moves the installroot option lock, persistdir lookup, and lock path computation out of the one-time branch. create_directories now runs on every call, and only Locker construction stays guarded by the optional check. This lets the lock recover when its directory was removed between lock/unlock cycles.

libdnf5/base/base.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant