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 +++++++++++++++++++-- apt-private/private-cmndline.cc | 1 + doc/apt-get.8.xml | 4 ++++ doc/examples/configure-index | 1 + .../integration/test-apt-update-failure-propagation | 6 ++++++ 5 files changed, 31 insertions(+), 2 deletions(-) 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 diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index 2049842db..2884dccba 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -206,6 +206,7 @@ static bool addArgumentsAPTGet(std::vector &Args, char const addArg(0, "allow-releaseinfo-change-codename", "Acquire::AllowReleaseInfoChange::Codename", 0); addArg(0, "allow-releaseinfo-change-suite", "Acquire::AllowReleaseInfoChange::Suite", 0); addArg(0, "allow-releaseinfo-change-defaultpin", "Acquire::AllowReleaseInfoChange::DefaultPin", 0); + addArg('e', "error-on", "APT::Update::Error-Mode", CommandLine::HasArg); } else if (CmdMatches("source")) { diff --git a/doc/apt-get.8.xml b/doc/apt-get.8.xml index 38a8c253a..0bdece955 100644 --- a/doc/apt-get.8.xml +++ b/doc/apt-get.8.xml @@ -646,6 +646,10 @@ + + Fail the update command if any error occured, even a transient one. + + &apt-commonoptions; diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 5ddf4132c..ecd54b6ba 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -166,6 +166,7 @@ APT { Pre-Invoke {"touch /var/lib/apt/pre-update-stamp"; }; Post-Invoke {"touch /var/lib/apt/post-update-stamp"; }; + Error-Mode ""; }; /* define a new supported compressor on the fly diff --git a/test/integration/test-apt-update-failure-propagation b/test/integration/test-apt-update-failure-propagation index 44f2e7048..8c7fd3b7e 100755 --- a/test/integration/test-apt-update-failure-propagation +++ b/test/integration/test-apt-update-failure-propagation @@ -88,3 +88,9 @@ testwarning aptget update -o Dir::Bin::Methods::https="${OLDMETHODS}/https" testsuccess grep '^W: Failed to fetch https://localhost:666/dists/stable/InRelease ' rootdir/tmp/testwarning.output testequal 'W: Some index files failed to download. They have been ignored, or old ones used instead.' tail -n 1 rootdir/tmp/testwarning.output posttest + +pretest 'error-mode=any' 'doom port' +testfailure aptget update -o Dir::Bin::Methods::https="${OLDMETHODS}/https" -eany +testsuccess grep '^E: Failed to fetch https://localhost:666/dists/stable/InRelease ' rootdir/tmp/testfailure.output +testequal 'E: Some index files failed to download. They have been ignored, or old ones used instead.' tail -n 1 rootdir/tmp/testfailure.output +posttest -- cgit v1.2.3