From c7123bea6a8dc2c9e327ce41ddfc25e29f1bb145 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 8 Jan 2021 17:52:53 +0100 Subject: Implement update --error-on=any People have been asking for a feature to error out on transient network errors for a while, this gives them one while keeping the door open for other modes we need, such as --error-on=no-success which we need to determine when to retry the daily update job. Closes: #594813 (and a whole bunch of duplicates...) --- apt-pkg/update.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/update.cc b/apt-pkg/update.cc index 1b25bafd6..1bf818ad7 100644 --- a/apt-pkg/update.cc +++ b/apt-pkg/update.cc @@ -46,6 +46,20 @@ bool ListUpdate(pkgAcquireStatus &Stat, bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, bool const RunUpdateScripts, bool const ListCleanup) { + enum class ErrorMode + { + Persistent, + Any + }; + std::string errorModeS = _config->Find("APT::Update::Error-Mode", "persistent"); + ErrorMode errorMode = ErrorMode::Persistent; + if (errorModeS == "persistent") + errorMode = ErrorMode::Persistent; + else if (errorModeS == "any") + errorMode = ErrorMode::Any; + else + return _error->Error("Unknown update error mode %s", errorModeS.c_str()); + // Run scripts if (RunUpdateScripts == true) RunScripts("APT::Update::Pre-Invoke"); @@ -69,7 +83,10 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, AllFailed = false; continue; case pkgAcquire::Item::StatTransientNetworkError: - TransientNetworkFailure = true; + if (errorMode == ErrorMode::Any) + Failed = true; + else + TransientNetworkFailure = true; break; case pkgAcquire::Item::StatIdle: case pkgAcquire::Item::StatFetching: @@ -91,7 +108,7 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, uri.Path = DeQuoteString(uri.Path); std::string const descUri = std::string(uri); // Show an error for non-transient failures, otherwise only warn - if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) + if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError && errorMode != ErrorMode::Any) _error->Warning(_("Failed to fetch %s %s"), descUri.c_str(), (*I)->ErrorText.c_str()); else -- cgit v1.2.3