Removed temp debug lines.
[ntk/apt.git] / apt-pkg / packagemanager.cc
index 35cc245..f49df83 100644 (file)
@@ -81,9 +81,6 @@ bool pkgPackageManager::GetArchives(pkgAcquire *Owner,pkgSourceList *Sources,
       if (List->IsNow(Pkg) == false)
         continue;
 
-      if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == true)
-        continue;
-
       new pkgAcqArchive(Owner,Sources,Recs,Cache[Pkg].InstVerIter(Cache),
                        FileNames[Pkg->ID]);
    }
@@ -281,9 +278,7 @@ bool pkgPackageManager::ConfigureAll()
    {
       PkgIterator Pkg(Cache,*I);
 
-      if (ConfigurePkgs == true &&
-         pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false &&
-         Configure(Pkg) == false)
+      if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false)
         return false;
       
       List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
@@ -318,20 +313,114 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg)
    {
       PkgIterator Pkg(Cache,*I);
       
-      if (ConfigurePkgs == true &&
-         pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false &&
-         Configure(Pkg) == false)
+      if (ConfigurePkgs == true && VerifyConfigure(Pkg,OList) == false)
         return false;
       
       List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
    }
 
+   if (Cache[Pkg].InstVerIter(Cache)->MultiArch == pkgCache::Version::Same)
+      for (PkgIterator P = Pkg.Group().PackageList();
+          P.end() == false; P = Pkg.Group().NextPkg(P))
+      {
+        if (Pkg == P || List->IsFlag(P,pkgOrderList::Configured) == true ||
+            Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
+             (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
+           continue;
+        SmartConfigure(P);
+      }
+
    // Sanity Check
    if (List->IsFlag(Pkg,pkgOrderList::Configured) == false)
-      return _error->Error(_("Could not perform immediate configuration on '%s'."
+      return _error->Error(_("Could not perform immediate configuration on '%s'. "
                        "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),1);
 
    return true;
+}
+
+// PM::VerifyConfigure - Check configuration of dependancies     /*{{{*/
+// ---------------------------------------------------------------------
+/* This routine checks that all a packages dependancies have been 
+   configured, before it is going to be configured. If this gives a warning 
+   on a virtual package, it means that the package thats providing it is not
+   configured*/
+bool pkgPackageManager::VerifyConfigure(PkgIterator Pkg, pkgOrderList &OList)
+{
+   // If this is true at the end, then the package should not be configured
+   bool error=true;
+   // This holds the the OR status of the previous dependancy  
+   bool previousOr=false;
+
+   // First iterate through the dependancies of Pkg
+   for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false; D++)
+   {
+      
+      /* If the dependancy is of type Depends or PreDepends, we need to check it, but only if it is going to be 
+         configured at some point */
+      if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) {
+         
+         /* If the previous package and this package are OR dependancies, and the previous package satisfied the dependancy
+            then skip this dependancy as it is not relevent, this will repeat for the next package if the situation is the 
+            same */
+         if (previousOr && !error) { // As error has not been reset, this refers to the previous dependancy 
+            previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
+            continue;
+         }
+        
+         // Reset error
+         error = true;
+
+         // Check thorugh all possible versions of this dependancy (D)
+         SPtrArray<Version *> VList = D.AllTargets();
+        for (Version **I = VList; *I != 0; I++)
+        {
+           VerIterator DepVer(Cache,*I);
+           PkgIterator DepPkg = DepVer.ParentPkg();
+           VerIterator DepInstallVer(Cache,Cache[DepPkg].InstallVer);
+           
+           if (DepPkg.CurrentVer() == DepVer && !List->IsFlag(DepPkg,pkgOrderList::UnPacked)) {
+              error=false;
+              break;
+           }
+           
+           if (Cache[DepPkg].InstallVer == DepVer && 
+              (List->IsFlag(DepPkg,pkgOrderList::Configured) || OList.IsFlag(DepPkg,pkgOrderList::InList))) {
+              error=false;
+              break;
+           }
+        }
+
+         /* Only worry here if this package is a OR with the next, as even though this package does not satisfy the OR
+            the next one might */
+         if (error && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) {
+             _error->Error("Package %s should not be configured because package %s is not configured",Pkg.Name(),D.TargetPkg().Name());
+             return false; 
+         /* If the previous package is a OR but not this package, but there is still an error then fail as it will not
+            be satisfied */    
+         } else if (error && previousOr && !((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)) {
+             _error->Error("Package %s should not be configured because package %s (or any alternatives) are not configured",Pkg.Name(),D.TargetPkg().Name());
+             return false; 
+         }
+         
+         previousOr = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
+      } else {
+         previousOr=false;
+      }
+   }
+   return true;
+}
+
+// PM::VerifyAndConfigure - Check configuration of dependancies     /*{{{*/
+// ---------------------------------------------------------------------
+/* This routine verifies if a package can be configured and if so 
+   configures it  */
+bool pkgPackageManager::VerifyAndConfigure(PkgIterator Pkg, pkgOrderList &OList)
+{
+   if (VerifyConfigure(Pkg, OList))
+      return Configure(Pkg);
+   else
+      return false;
+   
 }
                                                                        /*}}}*/
 // PM::DepAdd - Add all dependents to the oder list                    /*{{{*/
@@ -345,6 +434,9 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth)
       return true;
    if (List->IsFlag(Pkg,pkgOrderList::UnPacked) == false)
       return false;
+
+   if (Debug) 
+      std::clog << OutputInDepth(Depth) << "DepAdd: " << Pkg.Name() << std::endl;
       
    // Put the package on the list
    OList.push_back(Pkg);
@@ -398,6 +490,8 @@ bool pkgPackageManager::DepAdd(pkgOrderList &OList,PkgIterator Pkg,int Depth)
       
       if (Bad == true)
       {
+        if (Debug) 
+           std::clog << OutputInDepth(Depth) << "DepAdd FAILS on: " << Pkg.Name() << std::endl;
         OList.Flag(Pkg,0,pkgOrderList::Added);
         OList.pop_back();
         Depth--;
@@ -468,10 +562,7 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
 
    List->Flag(Pkg,pkgOrderList::Configured,pkgOrderList::States);
 
-   if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false)
-      return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
-   else
-      return SmartRemove(Pkg.Group().FindPkg("all"));
+   return Remove(Pkg,(Cache[Pkg].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge);
    return true;
 }
                                                                        /*}}}*/
@@ -479,22 +570,29 @@ bool pkgPackageManager::SmartRemove(PkgIterator Pkg)
 // ---------------------------------------------------------------------
 /* This performs the task of handling pre-depends. */
 bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
+{
+   return SmartUnPack(Pkg, true);
+}
+bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate)
 {
    // Check if it is already unpacked
    if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure &&
        Cache[Pkg].Keep() == true)
    {
       List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
-      if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
+      if (Immediate == true &&
+         List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
         if (SmartConfigure(Pkg) == false)
-           return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'."
+           return _error->Error(_("Could not perform immediate configuration on already unpacked '%s'. "
                        "Please see man 5 apt.conf under APT::Immediate-Configure for details."),Pkg.Name());
       return true;
    }
 
+   VerIterator const instVer = Cache[Pkg].InstVerIter(Cache);
+
    /* See if this packages install version has any predependencies
       that are not met by 'now' packages. */
-   for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); 
+   for (DepIterator D = instVer.DependsList();
        D.end() == false; )
    {
       // Compute a single dependency element (glob or)
@@ -580,26 +678,34 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg)
 
    // Check for reverse conflicts.
    if (CheckRConflicts(Pkg,Pkg.RevDependsList(),
-                  Cache[Pkg].InstVerIter(Cache).VerStr()) == false)
+                  instVer.VerStr()) == false)
       return false;
    
-   for (PrvIterator P = Cache[Pkg].InstVerIter(Cache).ProvidesList(); 
+   for (PrvIterator P = instVer.ProvidesList();
        P.end() == false; P++)
       CheckRConflicts(Pkg,P.ParentPkg().RevDependsList(),P.ProvideVersion());
 
-   if (pkgCache::VerIterator(Cache, Cache[Pkg].CandidateVer).Pseudo() == false)
-   {
-      if(Install(Pkg,FileNames[Pkg->ID]) == false)
-         return false;
-   } else if (SmartUnPack(Pkg.Group().FindPkg("all")) == false)
+   List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
+
+   if (instVer->MultiArch == pkgCache::Version::Same)
+      for (PkgIterator P = Pkg.Group().PackageList();
+          P.end() == false; P = Pkg.Group().NextPkg(P))
+      {
+        if (Pkg == P || List->IsFlag(P,pkgOrderList::UnPacked) == true ||
+            Cache[P].InstallVer == 0 || (P.CurrentVer() == Cache[P].InstallVer &&
+             (Cache[Pkg].iFlags & pkgDepCache::ReInstall) != pkgDepCache::ReInstall))
+           continue;
+        SmartUnPack(P, false);
+      }
+
+   if(Install(Pkg,FileNames[Pkg->ID]) == false)
       return false;
 
-   List->Flag(Pkg,pkgOrderList::UnPacked,pkgOrderList::States);
-   
    // Perform immedate configuration of the package.
-   if (List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
+   if (Immediate == true &&
+       List->IsFlag(Pkg,pkgOrderList::Immediate) == true)
       if (SmartConfigure(Pkg) == false)
-        return _error->Error(_("Could not perform immediate configuration on '%s'."
+        return _error->Error(_("Could not perform immediate configuration on '%s'. "
                        "Please see man 5 apt.conf under APT::Immediate-Configure for details. (%d)"),Pkg.Name(),2);
    
    return true;