]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/update.cc
follow the googletest merge in build-depends
[apt.git] / apt-pkg / update.cc
index 5d5b1962670383f248447b55e53f3c229f832d8d..f7075c446fa6b048686155327ab167fbcdfd4d81 100644 (file)
@@ -11,7 +11,6 @@
 #include <apt-pkg/update.h>
 
 #include <string>
-#include <vector>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -27,8 +26,8 @@ bool ListUpdate(pkgAcquireStatus &Stat,
                pkgSourceList &List, 
                int PulseInterval)
 {
-   pkgAcquire Fetcher;
-   if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false)
+   pkgAcquire Fetcher(&Stat);
+   if (Fetcher.GetLock(_config->FindDir("Dir::State::Lists")) == false)
       return false;
 
    // Populate it with the source selection
@@ -57,35 +56,47 @@ 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)
-        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);
-      _error->Warning(_("Failed to fetch %s  %s\n"), descUri.c_str(),
-             (*I)->ErrorText.c_str());
-
-      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
-      {
-        TransientNetworkFailure = true;
-        continue;
-      }
-
-      Failed = true;
+      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(),
+                       (*I)->ErrorText.c_str());
+      else
+        _error->Error(_("Failed to fetch %s  %s"), descUri.c_str(),
+              (*I)->ErrorText.c_str());
    }
-   
+
    // 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
@@ -98,22 +109,25 @@ bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
         // something went wrong with the clean
         return false;
    }
-   
-   if (TransientNetworkFailure == true)
-      _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
-   else if (Failed == true)
-      return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
 
+   bool Res = 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)
    {
-      if(!TransientNetworkFailure && !Failed)
+      if(AllFailed == false)
         RunScripts("APT::Update::Post-Invoke-Success");
 
       // Run the other scripts
       RunScripts("APT::Update::Post-Invoke");
    }
-   return true;
+   return Res;
 }
                                                                        /*}}}*/