Skip to content

reposync: Continue syncing remaining repositories after a failure - #3100

Open
LUX-ETVERITAS wants to merge 1 commit into
rpm-software-management:mainfrom
LUX-ETVERITAS:fix/reposync-continue-on-repo-error
Open

LUX-ETVERITAS wants to merge 1 commit into
rpm-software-management:mainfrom
LUX-ETVERITAS:fix/reposync-continue-on-repo-error

Conversation

@LUX-ETVERITAS

Copy link
Copy Markdown
Contributor

A missing RPM or a failed OpenPGP check could stop a mirror job before it reached the remaining repositories. Report each repository's sync error, continue the job, and return exit code 1 after the last repository if any sync failed.

An incomplete package download skips pruning for that repository. Cleanup failures now also contribute to the final exit status, and package signature checks still run after a cleanup error.

Verification

Built the reposync plugin and ran three new Behave scenarios against both the original and patched plugin. All three failed on the original and passed with the patch (29 steps). They cover package download failures across multiple repositories alongside a healthy repository, OpenPGP failures in two repositories, and a cleanup error that previously returned success.

Fixes #2775

Handle sync errors at the repository boundary so a missing package or
failed OpenPGP check does not prevent other repositories from syncing.
Report the repository and underlying error and return failure after the
last repository. Skip pruning after an incomplete download.

Count cleanup errors toward the final status and still check package
signatures. Treat a missing destination as already clean when no RPMs
match the selected architectures.

Fixes rpm-software-management#2775
Assisted-by: Codex
@LUX-ETVERITAS
LUX-ETVERITAS requested a review from a team as a code owner December 4, 2026 05:40
@LUX-ETVERITAS
LUX-ETVERITAS requested review from dcantrell and removed request for a team December 4, 2026 05:40
@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

reposync: continue syncing remaining repositories after a failure

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes


AI Description

• Catches per-repository sync errors so reposync reports each one and moves on to the next
 repository.
• Exits with code 1 after the last repository if any sync failed; cleanup errors now count toward
 that status.
• Skips pruning after an incomplete download and still runs OpenPGP checks after a cleanup error.
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.
  • The changed download, metadata, cleanup, signature-check, and per-repository orchestration steps all produce one bounded outcome: a local copy for each selected repository.
  • The propagation path is local filesystem state for that copy, not separate capabilities per helper or technical hop.
Sources

dnf5-plugins/reposync_plugin/reposync.cpp[412-425]

void ReposyncCommand::sync_repo(libdnf5::repo::Repo & repo) {
    const auto pkg_list = get_packages_list(repo);
    if (download_metadata_option->get_value()) {
        download_metadata(repo);
    }
    download_packages(pkg_list);
    const bool cleanup_failed = delete_option->get_value() && !delete_old_local_packages(repo, pkg_list);
    if (gpgcheck_option->get_value() && !pgp_check_packages(pkg_list)) {
        throw libdnf5::cli::CommandExitError(1, M_("OpenPGP signature check failed"));
    }
    if (cleanup_failed) {
        throw libdnf5::cli::CommandExitError(1, M_("Failed to remove old packages"));
    }
}
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Coordinated invariants

  • Before, the run loop invoked one repository and propagated its runtime failure immediately.
  • After, each repository has an exception boundary and the loop records a shared failed state before returning a final error.
  • The new correctness condition is that later repositories must remain independently attempted while every repository failure, including cleanup failure, still forces the final nonzero result; partial local filesystem effects must not be mistaken for successful synchronization.
  • The cleanup helper also changes from reporting errors only to returning success state consumed by sync_repo.
Sources

dnf5-plugins/reposync_plugin/reposync.cpp[412-425]

void ReposyncCommand::sync_repo(libdnf5::repo::Repo & repo) {
    const auto pkg_list = get_packages_list(repo);
    if (download_metadata_option->get_value()) {
        download_metadata(repo);
    }
    download_packages(pkg_list);
    const bool cleanup_failed = delete_option->get_value() && !delete_old_local_packages(repo, pkg_list);
    if (gpgcheck_option->get_value() && !pgp_check_packages(pkg_list)) {
        throw libdnf5::cli::CommandExitError(1, M_("OpenPGP signature check failed"));
    }
    if (cleanup_failed) {
        throw libdnf5::cli::CommandExitError(1, M_("Failed to remove old packages"));
    }
}

dnf5-plugins/reposync_plugin/reposync.cpp[360-369]

        delete_iterator.increment(ec);
    }
    if (ec) {
        std::cerr << libdnf5::utils::sformat(
                         _("Failed to iterate directory '{0}': {1}"), repo_path.string(), ec.message())
                  << std::endl;
        return false;
    }
    return success;
}
Potential damage 🟡 Medium 🩹 Recoverable

  • If a selected repository cannot complete, its local copy may be incomplete or stale while other repositories can still synchronize.
  • Reverting stops future aggregate continuation but does not restore already downloaded or deleted files; rerunning reposync is needed, and any deleted packages require separate restoration.
  • No external side effect or irreversible data transition is shown.
  • Rerunning the affected repository can redownload missing packages and repeat cleanup; restoration of packages already deleted by --delete may require a source repository, cache, or backup.
Sources

dnf5-plugins/reposync_plugin/reposync.cpp[412-425]

void ReposyncCommand::sync_repo(libdnf5::repo::Repo & repo) {
    const auto pkg_list = get_packages_list(repo);
    if (download_metadata_option->get_value()) {
        download_metadata(repo);
    }
    download_packages(pkg_list);
    const bool cleanup_failed = delete_option->get_value() && !delete_old_local_packages(repo, pkg_list);
    if (gpgcheck_option->get_value() && !pgp_check_packages(pkg_list)) {
        throw libdnf5::cli::CommandExitError(1, M_("OpenPGP signature check failed"));
    }
    if (cleanup_failed) {
        throw libdnf5::cli::CommandExitError(1, M_("Failed to remove old packages"));
    }
}

dnf5-plugins/reposync_plugin/reposync.cpp[360-369]

        delete_iterator.increment(ec);
    }
    if (ec) {
        std::cerr << libdnf5::utils::sformat(
                         _("Failed to iterate directory '{0}': {1}"), repo_path.string(), ec.message())
                  << std::endl;
        return false;
    }
    return success;
}
Assessed commit c075ea7
Diagram

graph TD
    run["run() repo loop"] --> sync["sync_repo()"] --> download["download_packages()"] --> cleanup[("delete_old_local_packages()")] --> pgp["pgp_check_packages()"] --> status["Report error, exit 1 at end"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Collect errors and continue inside each helper without exceptions
  • ➕ Avoids exception-based control flow for expected per-repo failures
  • ➕ Could report several errors per repository instead of stopping at the first
  • ➖ Requires threading status returns through download_packages and pgp_check_packages
  • ➖ Larger diff touching more call sites

Recommendation: The PR's approach is reasonable: a single try/catch at the repository boundary is the smallest change that fixes the stop-on-first-error behavior. The libdnf5::Error hierarchy derives from std::runtime_error, so CommandExitError from the PGP check is caught by the same handler. The alternative of returning status codes everywhere is cleaner but would touch more code for no user-visible gain.

Files changed (4) +100 / -25

Bug fix (2) +54 / -25
reposync.cppIsolate per-repo failures and aggregate exit status +52/-24

Isolate per-repo failures and aggregate exit status

• Extracts sync_repo() so download, cleanup, and PGP check run per repository inside a try block in run(). delete_old_local_packages() now returns bool, treats a missing destination as clean, and reports iteration and inspection errors. A failed cleanup is deferred until after the PGP check, and SilentCommandExitError(1) is thrown after the loop if any repository failed.

dnf5-plugins/reposync_plugin/reposync.cpp

reposync.hppUpdate declarations for cleanup return type and sync_repo +2/-1

Update declarations for cleanup return type and sync_repo

• Changes delete_old_local_packages() to return bool and declares the new sync_repo() helper.

dnf5-plugins/reposync_plugin/reposync.hpp

Tests (1) +44 / -0
reposync.featureAdd Behave scenarios for multi-repo failure handling +44/-0

Add Behave scenarios for multi-repo failure handling

• Adds three scenarios: package download failures across repositories with a healthy one, OpenPGP failures in two repositories, and a cleanup error on a non-directory destination that must return exit code 1.

integration-tests/dnf-behave-tests/dnf/plugins-core/reposync.feature

Documentation (1) +2 / -0
reposync.8.rstDocument continue-on-error and exit code 1 behavior +2/-0

Document continue-on-error and exit code 1 behavior

• Adds a paragraph stating that reposync reports repository errors, continues with remaining repositories, and exits with code 1 if any failed.

doc/dnf5_plugins/reposync.8.rst

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Great, no issues found!

Qodo reviewed your code and found no material issues that require review
Tip of the day
💡 Did you know, you can import rules and skills only from the repositories your team follows

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗


Powered by Qodo

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.

reposync: continue syncing remaining repos after per-repo errors

1 participant