From 57f7fb6511fcc7c55ee7a88475d15385093c048e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 16 Jun 2016 23:13:26 +0200 Subject: run update post-invokes even on (partial) failures Unsecure repositories result in error messages by default which causes the acquire run to fail hard, but non-failing repositories are still updated just like in the slightly less hard-failures which got this behaviour in 35664152e47a1d4d712fd52e0f0a2dc8ed359d32. --- apt-pkg/update.cc | 44 +++++++++++++++++++--------------- test/integration/test-apt-update-hooks | 12 +++++++--- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/apt-pkg/update.cc b/apt-pkg/update.cc index 0d901eab1..f7075c446 100644 --- a/apt-pkg/update.cc +++ b/apt-pkg/update.cc @@ -56,26 +56,38 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, else res = Fetcher.Run(); - if (res == pkgAcquire::Failed) - return false; - - bool Failed = false; + bool const errorsWereReported = (res == pkgAcquire::Failed); + bool Failed = errorsWereReported; bool TransientNetworkFailure = false; bool AllFailed = true; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I) { - if ((*I)->Status == pkgAcquire::Item::StatDone) { - AllFailed = false; - continue; + switch ((*I)->Status) + { + case pkgAcquire::Item::StatDone: + AllFailed = false; + continue; + case pkgAcquire::Item::StatTransientNetworkError: + TransientNetworkFailure = true; + break; + case pkgAcquire::Item::StatIdle: + case pkgAcquire::Item::StatFetching: + case pkgAcquire::Item::StatError: + case pkgAcquire::Item::StatAuthError: + Failed = true; + break; } (*I)->Finished(); + if (errorsWereReported) + continue; + ::URI uri((*I)->DescURI()); uri.User.clear(); uri.Password.clear(); - string descUri = string(uri); + std::string const descUri = std::string(uri); // Show an error for non-transient failures, otherwise only warn if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) _error->Warning(_("Failed to fetch %s %s"), descUri.c_str(), @@ -83,15 +95,8 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, else _error->Error(_("Failed to fetch %s %s"), descUri.c_str(), (*I)->ErrorText.c_str()); - if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) - { - TransientNetworkFailure = true; - continue; - } - - Failed = true; } - + // Clean out any old list files // Keep "APT::Get::List-Cleanup" name for compatibility, but // this is really a global option for the APT library now @@ -106,13 +111,14 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval, } bool Res = true; - - if (TransientNetworkFailure == true) + + if (errorsWereReported == true) + Res = false; + else if (TransientNetworkFailure == true) Res = _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead.")); else if (Failed == true) Res = _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead.")); - // Run the success scripts if all was fine if (RunUpdateScripts == true) { diff --git a/test/integration/test-apt-update-hooks b/test/integration/test-apt-update-hooks index 0a4ee59b4..d81ef297e 100755 --- a/test/integration/test-apt-update-hooks +++ b/test/integration/test-apt-update-hooks @@ -9,7 +9,7 @@ configarchitecture 'i386' confighashes 'SHA512' insertpackage 'unstable' 'foo' 'i386' '1.0' -insertpackage 'testing' 'foo' 'any' '1.0' +insertpackage 'testing' 'foo' 'i386' '1.0' setupaptarchive --no-update APTARCHIVE="$(readlink -f ./aptarchive)" @@ -28,16 +28,22 @@ testsuccess grep "SUCCESS" aptupdate.output msgmsg "Some sources broken => run Post-Invoke-Success and Post-Invoke" sed -i -e '/^ / d' -e '/^SHA512:/ d' "$APTARCHIVE/dists/unstable/Release" +testsuccess rm "$(aptget indextargets 'Created-By: Packages' 'Suite: testing' --format '$(FILENAME)')" signreleasefiles -testfailure aptget update +listcurrentlistsdirectory > lists.before +testfailure apt update cp rootdir/tmp/testfailure.output aptupdate.output +listcurrentlistsdirectory > lists.after +testfailure cmp lists.before lists.after testsuccess grep "RUN" aptupdate.output testsuccess grep "SUCCESS" aptupdate.output msgmsg "All sources broken => run Post-Invoke" sed -i -e '/^ / d' -e '/^SHA512:/ d' "$APTARCHIVE/dists/testing/Release" signreleasefiles -testfailure aptget update +mv lists.after lists.before +testfailure apt update cp rootdir/tmp/testfailure.output aptupdate.output +testfileequal lists.before "$(listcurrentlistsdirectory)" testsuccess grep "RUN" aptupdate.output testfailure grep "SUCCESS" aptupdate.output -- cgit v1.2.3