Skip to content

context: print metadata cache age after loading repos#2666

Open
DeveshB-1 wants to merge 1 commit intorpm-software-management:mainfrom
DeveshB-1:feat/metadata-cache-age-display
Open

context: print metadata cache age after loading repos#2666
DeveshB-1 wants to merge 1 commit intorpm-software-management:mainfrom
DeveshB-1:feat/metadata-cache-age-display

Conversation

@DeveshB-1
Copy link
Copy Markdown

Closes #1491

DNF4 displayed Last metadata expiration check: H:MM:SS ago on <date>. after loading repository metadata. DNF5 dropped this output, making it hard to know whether you are working with stale repo data.

What this does

After load_repos() completes, iterate over enabled non-system repos and compute:

  • oldest cache age (get_age()) — how stale is the most stale repo
  • newest repomd timestamp (get_timestamp()) — when was the newest primary metadata written

Print the message only when at least one repo has a valid cached timestamp. Matches dnf4 behaviour exactly.

Example output

Last metadata expiration check: 0:32:14 ago on Sun 30 Mar 2026 10:15:00 AM IST.
Repositories loaded.

Design decision (multiple repos)

Follows dnf4: show oldest age + newest timestamp. This answers "how stale is the most stale repo you are using".

@DeveshB-1 DeveshB-1 requested a review from a team as a code owner March 29, 2026 18:23
@DeveshB-1 DeveshB-1 requested review from fhbash and removed request for a team March 29, 2026 18:23
@packit-as-a-service
Copy link
Copy Markdown

Failed to load packit config file:

Please correct data and retry.

For more info, please check out the documentation or contact the Packit team. You can also use our CLI command config validate or our pre-commit hooks for validation of the configuration.

@DeveshB-1
Copy link
Copy Markdown
Author

The dnf5 tests failing in testing-farm are caused by the new "Last metadata expiration check:" line not being handled by the <REPOSYNC> macro in the test framework.

I've opened rpm-software-management/ci-dnf-stack#1855 to fix strip_reposync_dnf5() in ci-dnf-stack. Once that PR is merged, the testing-farm tests should pass.

The dnf5 code change itself (using libdnf5::utils::sformat() instead of fmt::format()) is correct and needed for fmt v11 compatibility.

@DeveshB-1
Copy link
Copy Markdown
Author

@fnbash do look into this

@mfocko
Copy link
Copy Markdown
Contributor

mfocko commented Mar 30, 2026

https://github.com/rpm-software-management/dnf5/blob/main/CONTRIBUTING.md#ai-assisted-contributions-policy

I can tell by the commits:

  • second one doesn't touch any include guard, yet it claims so…
  • last two — both of them together change nothing, and at the same time don't test anything…

@DeveshB-1 DeveshB-1 force-pushed the feat/metadata-cache-age-display branch from a18cefb to cb93a96 Compare March 30, 2026 05:55
@DeveshB-1
Copy link
Copy Markdown
Author

I cleaned up the branch and force-pushed it so the PR now reflects only the real change in dnf5/context.cpp. I removed the
.packit.yaml detour commits, the revert/no-op noise, and the misleading intermediate commit split.

I also updated the remaining commit message so it describes the code accurately. Per the project policy, I will also label the commit
for AI assistance.

Any ci-dnf-stack / Packit-side work, if still needed, will be handled separately in the appropriate repository.

Thanks again for the review.

DNF4 displayed "Last metadata expiration check: H:MM:SS ago on <date>."
after loading repository metadata. DNF5 dropped this output, making it
hard for users to know whether they are working with stale repo data.

Restore the behaviour by iterating over enabled non-system repos after
load_repos() completes. Show the oldest cache age (most stale repo)
paired with the newest repomd primary timestamp, matching dnf4 logic.

Use libdnf5::utils::sformat for the translated output string.

The message is suppressed when no repos have valid timestamps (e.g.
all repos were just refreshed from the network and have age 0, or no
cache exists yet).

Closes: rpm-software-management#1491

Signed-off-by: Devesh B <98201065+DeveshB-1@users.noreply.github.com>
Assisted-by: ChatGPT
@DeveshB-1 DeveshB-1 force-pushed the feat/metadata-cache-age-display branch from cb93a96 to 17b6968 Compare March 30, 2026 05:59
@m-blaha
Copy link
Copy Markdown
Member

m-blaha commented Mar 31, 2026

Also this change breaks a lot of scenarios in ci-dnf-stack repo.

Copy link
Copy Markdown
Member

@m-blaha m-blaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fix the pre commit hook errors please.

}
if (load_available) {
// Print metadata cache age, mirroring dnf4's "Last metadata expiration check" output.
// Show oldest age (most stale repo) with the newest repomd timestamp.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong (also in the commit message) - age shows the freshest cache age (minimal age), not the oldest. The newest timestamp is correct.

}
}

if (min_age != std::numeric_limits<int64_t>::max() && max_ts > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dnf4 prints the cache age only when cached metadata were used (i.e. age > 0), not when metadata have been just refreshed - e.g. for dnf4 repoquery xxx --refresh. What do you think? Does such differentiation make sense?

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.

Add info about repository metadata cache age to dnf5 output

3 participants