Browse Source

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...)

(cherry picked from commit c7123bea6a)
LP: #1693900
(cherry picked from commit f15ced2c38)
tags/debian/1.8.5
Julian Andres Klode 5 months ago
parent
commit
037856f935
5 changed files with 31 additions and 2 deletions
  1. +19
    -2
      apt-pkg/update.cc
  2. +1
    -0
      apt-private/private-cmndline.cc
  3. +4
    -0
      doc/apt-get.8.xml
  4. +1
    -0
      doc/examples/configure-index
  5. +6
    -0
      test/integration/test-apt-update-failure-propagation

+ 19
- 2
apt-pkg/update.cc View File

@@ -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:
@@ -89,7 +106,7 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
uri.Password.clear();
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


+ 1
- 0
apt-private/private-cmndline.cc View File

@@ -205,6 +205,7 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &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"))
{


+ 4
- 0
doc/apt-get.8.xml View File

@@ -620,6 +620,10 @@
</para></listitem>
</varlistentry>

<varlistentry><term><option>-e<replaceable>any</replaceable></option></term><term><option>--error-on=<replaceable>any</replaceable></option></term>
<listitem><para>Fail the update command if any error occured, even a transient one.</para></listitem>
</varlistentry>

&apt-commonoptions;
</variablelist>


+ 1
- 0
doc/examples/configure-index View File

@@ -157,6 +157,7 @@ APT
{
Pre-Invoke {"touch /var/lib/apt/pre-update-stamp"; };
Post-Invoke {"touch /var/lib/apt/post-update-stamp"; };
Error-Mode "<STRING>";
};

/* define a new supported compressor on the fly


+ 6
- 0
test/integration/test-apt-update-failure-propagation View File

@@ -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

Loading…
Cancel
Save