add APT::Status-deb822-Fd
[ntk/apt.git] / apt-private / private-install.cc
index b03f131..1d2acee 100644 (file)
@@ -24,6 +24,8 @@
 #include <apt-pkg/pkgrecords.h>
 #include <apt-pkg/indexfile.h>
 
+#include <apt-private/private-progress.h>
+
 #include <set>
 #include <locale.h>
 #include <langinfo.h>
@@ -42,6 +44,7 @@
 #include <sstream>
 
 #include "private-install.h"
+#include "private-download.h"
 #include "private-cachefile.h"
 #include "private-output.h"
 #include "private-cacheset.h"
 #include <apti18n.h>
                                                                        /*}}}*/
 
-// CheckAuth - check if each download comes form a trusted source      /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool CheckAuth(pkgAcquire& Fetcher)
-{
-   std::string UntrustedList;
-   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I < Fetcher.ItemsEnd(); ++I)
-   {
-      if (!(*I)->IsTrusted())
-      {
-          UntrustedList += std::string((*I)->ShortDesc()) + " ";
-      }
-   }
-
-   if (UntrustedList == "")
-   {
-      return true;
-   }
-        
-   ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
-
-   if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
-   {
-      c2out << _("Authentication warning overridden.\n");
-      return true;
-   }
-
-   if (_config->FindI("quiet",0) < 2
-       && _config->FindB("APT::Get::Assume-Yes",false) == false)
-   {
-      c2out << _("Install these packages without verification?") << std::flush;
-      if (!YnPrompt(false))
-         return _error->Error(_("Some packages could not be authenticated"));
-
-      return true;
-   }
-   else if (_config->FindB("APT::Get::Force-Yes",false) == true)
-   {
-      return true;
-   }
-
-   return _error->Error(_("There are problems and -y was used without --force-yes"));
-}
-                                                                       /*}}}*/
-
-
 // InstallPackages - Actually download and install the packages                /*{{{*/
 // ---------------------------------------------------------------------
 /* This displays the informative messages describing what is going to 
@@ -148,8 +105,14 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    if (_config->FindB("APT::Get::Simulate") == true)
    {
       pkgSimulate PM(Cache);
+
       int status_fd = _config->FindI("APT::Status-Fd",-1);
-      pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd);
+      APT::Progress::PackageManager *progress = NULL;
+      if (status_fd > 0)
+         progress = new APT::Progress::PackageManagerProgressFd(status_fd);
+      pkgPackageManager::OrderResult Res = PM.DoInstall(progress);
+      delete progress;
+
       if (Res == pkgPackageManager::Failed)
         return false;
       if (Res != pkgPackageManager::Completed)
@@ -301,12 +264,12 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    {
       pkgAcquire::UriIterator I = Fetcher.UriBegin();
       for (; I != Fetcher.UriEnd(); ++I)
-        c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' << 
+        std::cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
               I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
       return true;
    }
 
-   if (!CheckAuth(Fetcher))
+   if (!CheckAuth(Fetcher, true))
       return false;
 
    /* Unlock the dpkg lock if we are not going to be doing an install
@@ -338,29 +301,10 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
            I = Fetcher.ItemsBegin();
         }       
       }
-      
-      if (Fetcher.Run() == pkgAcquire::Failed)
-        return false;
-      
-      // Print out errors
-      bool Failed = false;
-      for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
-      {
-        if ((*I)->Status == pkgAcquire::Item::StatDone &&
-            (*I)->Complete == true)
-           continue;
-        
-        if ((*I)->Status == pkgAcquire::Item::StatIdle)
-        {
-           Transient = true;
-           // Failed = true;
-           continue;
-        }
 
-        fprintf(stderr,_("Failed to fetch %s  %s\n"),(*I)->DescURI().c_str(),
-                (*I)->ErrorText.c_str());
-        Failed = true;
-      }
+      bool Failed = false;
+      if (AcquireRun(Fetcher, 0, &Failed, &Transient) == false)
+        return false;
 
       /* If we are in no download mode and missing files and there were
          'failures' then the user must specify -m. Furthermore, there 
@@ -396,8 +340,28 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
       }
 
       _system->UnLock();
-      int status_fd = _config->FindI("APT::Status-Fd",-1);
-      pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd);
+      
+      // FIXME: make this a factory
+      // select the right progress
+      int status_fd = _config->FindI("APT::Status-Fd", -1);
+      int status_deb822_fd = _config->FindI("APT::Status-deb822-Fd", -1);
+
+      APT::Progress::PackageManager *progress = NULL;
+      if (status_deb822_fd > 0)
+         progress = new APT::Progress::PackageManagerProgressDeb822Fd(
+            status_deb822_fd);
+      else if (status_fd > 0)
+         progress = new APT::Progress::PackageManagerProgressFd(status_fd);
+      else if(_config->FindB("Dpkg::Progress-Fancy", false) == true)
+         progress = new APT::Progress::PackageManagerFancy();
+      else if (_config->FindB("Dpkg::Progress", 
+                _config->FindB("DpkgPM::Progress", false)) == true)
+         progress = new APT::Progress::PackageManagerText();
+      else
+         progress = new APT::Progress::PackageManager();
+      pkgPackageManager::OrderResult Res = PM->DoInstall(progress);
+      delete progress;
+
       if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
         return false;
       if (Res == pkgPackageManager::Completed)
@@ -429,8 +393,6 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask, bool Safety)
    return true;
 }
                                                                        /*}}}*/
-
-
 // DoAutomaticRemove - Remove all automatic unused packages            /*{{{*/
 // ---------------------------------------------------------------------
 /* Remove unused automatic packages */
@@ -504,15 +466,15 @@ bool DoAutomaticRemove(CacheFile &Cache)
       do {
         Changed = false;
         for (APT::PackageSet::const_iterator Pkg = tooMuch.begin();
-             Pkg != tooMuch.end() && Changed == false; ++Pkg)
+             Pkg != tooMuch.end(); ++Pkg)
         {
            APT::PackageSet too;
            too.insert(*Pkg);
            for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
                 Prv.end() == false; ++Prv)
               too.insert(Prv.ParentPkg());
-           for (APT::PackageSet::const_iterator P = too.begin();
-                P != too.end() && Changed == false; ++P) {
+           for (APT::PackageSet::const_iterator P = too.begin(); P != too.end(); ++P)
+           {
               for (pkgCache::DepIterator R = P.RevDependsList();
                    R.end() == false; ++R)
               {
@@ -531,7 +493,11 @@ bool DoAutomaticRemove(CacheFile &Cache)
                 Changed = true;
                 break;
               }
+              if (Changed == true)
+                 break;
            }
+           if (Changed == true)
+              break;
         }
       } while (Changed == true);
    }
@@ -576,7 +542,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
    return true;
 }
                                                                        /*}}}*/
-
+// DoCacheManipulationFromCommandLine                                  /*{{{*/
 static const unsigned short MOD_REMOVE = 1;
 static const unsigned short MOD_INSTALL = 2;
 
@@ -585,7 +551,6 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache)
    std::map<unsigned short, APT::VersionSet> verset;
    return DoCacheManipulationFromCommandLine(CmdL, Cache, verset);
 }
-
 bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
                                         std::map<unsigned short, APT::VersionSet> &verset)
 {
@@ -719,8 +684,7 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
 
    return true;
 }
-
-
+                                                                       /*}}}*/
 // DoInstall - Install packages from the command line                  /*{{{*/
 // ---------------------------------------------------------------------
 /* Install named packages */