merged from the debian-sid branch
[ntk/apt.git] / apt-pkg / depcache.cc
index 031fca5..2ec346f 100644 (file)
@@ -346,7 +346,7 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
    /* Check simple depends. A depends -should- never self match but 
       we allow it anyhow because dpkg does. Technically it is a packaging
       bug. Conflicts may never self match */
-   if (Dep.TargetPkg() != Dep.ParentPkg() || Dep.IsNegative() == false)
+   if (Dep.IsIgnorable(Res) == false)
    {
       PkgIterator Pkg = Dep.TargetPkg();
       // Check the base package
@@ -371,14 +371,11 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res)
    
    // Check the providing packages
    PrvIterator P = Dep.TargetPkg().ProvidesList();
-   PkgIterator Pkg = Dep.ParentPkg();
    for (; P.end() != true; ++P)
    {
-      /* Provides may never be applied against the same package (or group)
-         if it is a conflicts. See the comment above. */
-      if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
+      if (Dep.IsIgnorable(P) == true)
         continue;
-      
+
       // Check if the provides is a hit
       if (Type == NowVersion)
       {
@@ -916,11 +913,15 @@ bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
       return true;
 
    StateCache &P = PkgState[Pkg->ID];
+   // not changing the mode is obviously also fine as we might want to call
+   // e.g. MarkInstall multiple times with different arguments for the same package
+   if (P.Mode == mode)
+      return true;
 
    // if previous state was set by user only user can reset it
    if ((P.iFlags & Protected) == Protected)
    {
-      if (unlikely(DebugMarker == true) && P.Mode != mode)
+      if (unlikely(DebugMarker == true))
         std::clog << OutputInDepth(Depth) << "Ignore Mark" << PrintMode(mode)
                   << " of " << Pkg << " as its mode (" << PrintMode(P.Mode)
                   << ") is protected" << std::endl;
@@ -930,7 +931,7 @@ bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg,
    else if (mode != ModeKeep && Pkg->SelectedState == pkgCache::State::Hold &&
            _config->FindB("APT::Ignore-Hold",false) == false)
    {
-      if (unlikely(DebugMarker == true) && P.Mode != mode)
+      if (unlikely(DebugMarker == true))
         std::clog << OutputInDepth(Depth) << "Hold prevents Mark" << PrintMode(mode)
                   << " of " << Pkg << std::endl;
       return false;
@@ -966,6 +967,13 @@ struct CompareProviders {
         else if ((B->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
            return true;
       }
+      if ((A->Flags & pkgCache::Flag::Important) != (B->Flags & pkgCache::Flag::Important))
+      {
+        if ((A->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+           return false;
+        else if ((B->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+           return true;
+      }
       // higher priority seems like a good idea
       if (AV->Priority != BV->Priority)
         return AV->Priority < BV->Priority;
@@ -1148,9 +1156,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
       }
 
       /* This bit is for processing the possibilty of an install/upgrade
-         fixing the problem */
-      if (Start->Type != Dep::DpkgBreaks &&
-         (DepState[Start->ID] & DepCVer) == DepCVer)
+         fixing the problem for "positive" dependencies */
+      if (Start.IsNegative() == false && (DepState[Start->ID] & DepCVer) == DepCVer)
       {
         APT::VersionList verlist;
         pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
@@ -1161,7 +1168,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
            pkgCache::VerIterator V = Prv.OwnerVer();
            pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
            if (Cand.end() == true || V != Cand ||
-               VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == false)
+               VS().CheckDep(Prv.ProvideVersion(), Start->CompareOp, Start.TargetVer()) == false)
               continue;
            verlist.insert(Cand);
         }
@@ -1175,32 +1182,25 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
               std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
                         << " as " << Start.DepType() << " of " << Pkg.Name()
                         << std::endl;
-           // now check if we should consider it a automatic dependency or not
-           if(Pkg.Section() && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg.Section()))
-           {
+           MarkInstall(InstPkg, true, Depth + 1, false, ForceImportantDeps);
+           // now check if we should consider it a automatic dependency or not
+           if(InstPkg->CurrentVer == 0 && Pkg->Section != 0 && ConfigValueInSubTree("APT::Never-MarkAuto-Sections", Pkg.Section()))
+           {
               if(DebugAutoInstall == true)
                  std::clog << OutputInDepth(Depth) << "Setting NOT as auto-installed (direct "
                             << Start.DepType() << " of pkg in APT::Never-MarkAuto-Sections)" << std::endl;
-              MarkInstall(InstPkg,true,Depth + 1, true);
-           }
-           else 
-           {
-              // mark automatic dependency
-              MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
-              // Set the autoflag, after MarkInstall because MarkInstall unsets it
-              if (InstPkg->CurrentVer == 0)
-                 PkgState[InstPkg->ID].Flags |= Flag::Auto;
-           }
+              MarkAuto(InstPkg, false);
+           }
         }
         continue;
       }
-
-      /* For conflicts we just de-install the package and mark as auto,
-         Conflicts may not have or groups.  For dpkg's Breaks we try to
-         upgrade the package. */
-      if (Start.IsNegative() == true)
+      /* Negative dependencies have no or-group
+        If the dependency isn't versioned, we try if an upgrade might solve the problem.
+        Otherwise we remove the offender if needed */
+      else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
       {
         SPtrArray<Version *> List = Start.AllTargets();
+        pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
         for (Version **I = List; *I != 0; I++)
         {
            VerIterator Ver(*this,*I);
@@ -1211,15 +1211,17 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
            if (PkgState[Pkg->ID].InstallVer == 0)
               continue;
 
-           if (PkgState[Pkg->ID].CandidateVer != *I &&
-               Start->Type == Dep::DpkgBreaks &&
+           if ((Start->Version != 0 || TrgPkg != Pkg) &&
+               PkgState[Pkg->ID].CandidateVer != PkgState[Pkg->ID].InstallVer &&
+               PkgState[Pkg->ID].CandidateVer != *I &&
                MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps) == true)
               continue;
-           else if (MarkDelete(Pkg,false,Depth + 1, false) == false)
+           else if ((Start->Type == pkgCache::Dep::Conflicts || Start->Type == pkgCache::Dep::DpkgBreaks) &&
+                    MarkDelete(Pkg,false,Depth + 1, false) == false)
               break;
         }
         continue;
-      }      
+      }
    }
 
    return Dep.end() == true;
@@ -1243,19 +1245,36 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
    if (unlikely(Pkg.end() == true))
       return;
 
+   APT::PackageList pkglist;
+   if (Pkg->CurrentVer != 0 &&
+       (Pkg.CurrentVer()-> MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+   {
+      pkgCache::GrpIterator Grp = Pkg.Group();
+      for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P))
+      {
+        if (P->CurrentVer != 0)
+           pkglist.insert(P);
+      }
+   }
+   else
+      pkglist.insert(Pkg);
+
    ActionGroup group(*this);
 
-   RemoveSizes(Pkg);
-   RemoveStates(Pkg);
-   
-   StateCache &P = PkgState[Pkg->ID];
-   if (To == true)
-      P.iFlags |= ReInstall;
-   else
-      P.iFlags &= ~ReInstall;
-   
-   AddStates(Pkg);
-   AddSizes(Pkg);
+   for (APT::PackageList::const_iterator Pkg = pkglist.begin(); Pkg != pkglist.end(); ++Pkg)
+   {
+      RemoveSizes(Pkg);
+      RemoveStates(Pkg);
+
+      StateCache &P = PkgState[Pkg->ID];
+      if (To == true)
+        P.iFlags |= ReInstall;
+      else
+        P.iFlags &= ~ReInstall;
+
+      AddStates(Pkg);
+      AddSizes(Pkg);
+   }
 }
                                                                        /*}}}*/
 // DepCache::SetCandidateVersion - Change the candidate version                /*{{{*/
@@ -1627,6 +1646,7 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc)
    {
       if(!(PkgState[p->ID].Flags & Flag::Auto) ||
          (p->Flags & Flag::Essential) ||
+         (p->Flags & Flag::Important) ||
          userFunc.InRootSet(p) ||
          // be nice even then a required package violates the policy (#583517)
          // and do the full mark process also for required packages