]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/depcache.cc
merge MultiArch-ABI. We don't support MultiArch yet (as most other tools),
[apt.git] / apt-pkg / depcache.cc
index 45c614c6fe69e431797663a4a787b7642be56ab6..75f69ee116a13b3c88ae7e0ce77ff9642830b2a8 100644 (file)
@@ -257,7 +257,22 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)     /*{{{*/
         pkgCache::PkgIterator pkg = Cache->FindPkg(pkgname, pkgarch);
         if(pkg.end() || pkg.VersionList().end()) 
            continue;
-        bool const newAuto = (PkgState[pkg->ID].Flags & Flag::Auto);
+        StateCache const &P = PkgState[pkg->ID];
+        bool newAuto = (P.Flags & Flag::Auto);
+        // skip not installed or now-removed ones if requested
+        if (InstalledOnly && (
+            (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
+            (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
+        {
+           // The section is obsolete if it contains no other tag
+           unsigned int const count = section.Count();
+           if (count < 2 ||
+               (count == 2 && section.Exists("Auto-Installed")) ||
+               (count == 3 && section.Exists("Auto-Installed") && section.Exists("Architecture")))
+              continue;
+           else
+              newAuto = false;
+        }
         if(_config->FindB("Debug::pkgAutoRemove",false))
            std::clog << "Update existing AutoInstall info: " 
                      << pkg.FullName() << std::endl;
@@ -277,14 +292,17 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)    /*{{{*/
    // then write the ones we have not seen yet
    std::ostringstream ostr;
    for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); pkg++) {
-      if(PkgState[pkg->ID].Flags & Flag::Auto) {
+      StateCache const &P = PkgState[pkg->ID];
+      if(P.Flags & Flag::Auto) {
         if (pkgs_seen.find(pkg.FullName()) != pkgs_seen.end()) {
            if(debug_autoremove)
               std::clog << "Skipping already written " << pkg.FullName() << std::endl;
            continue;
         }
         // skip not installed ones if requested
-        if(InstalledOnly && pkg->CurrentVer == 0)
+        if (InstalledOnly && (
+            (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
+            (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
            continue;
         const char* const pkgarch = pkg.Arch();
         if (strcmp(pkgarch, "all") == 0)
@@ -630,11 +648,43 @@ bool pkgDepCache::RemovePseudoInstalledPkg(PkgIterator &Pkg, std::set<unsigned l
    if (V->MultiArch != Version::All)
       return false;
 
-   unsigned char const DepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
-   if ((DepState & DepInstMin) == DepInstMin)
+   // Never ever kill an "all" package - they have no dependency so they can't be broken
+   if (strcmp(Pkg.Arch(),"all") == 0)
       return false;
 
-   // Dependencies for this arch all are not statisfied
+   unsigned char const CurDepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
+   if ((CurDepState & DepInstMin) == DepInstMin) {
+      // okay, the package isn't broken, but is the package also required?
+      // If it has no real dependencies, no installed rdepends and doesn't
+      // provide something of value, we will kill it as not required.
+      // These pseudopackages have otherwise interesting effects if they get
+      // a new dependency in a newer version…
+      for (pkgCache::DepIterator D = V.DependsList();
+          D.end() != true; ++D)
+        if (D.IsCritical() == true && D.ParentPkg()->Group != Pkg->Group)
+           return false;
+      for (DepIterator D = Pkg.RevDependsList(); D.end() != true; ++D)
+      {
+        if (D.IsCritical() == false)
+           continue;
+        PkgIterator const P = D.ParentPkg();
+        if (P->Group == Pkg->Group)
+           continue;
+        if (P->CurrentVer != 0)
+           return false;
+      }
+      for (PrvIterator Prv = V.ProvidesList(); Prv.end() != true; Prv++)
+        for (DepIterator d = Prv.ParentPkg().RevDependsList();
+             d.end() != true; ++d)
+        {
+           PkgIterator const P = d.ParentPkg();
+           if (P->CurrentVer != 0 &&
+               P->Group != Pkg->Group)
+              return false;
+        }
+   }
+
+   // Dependencies for this arch all package are not statisfied
    // so we installed it only for our convenience: get right of it now.
    RemoveSizes(Pkg);
    RemoveStates(Pkg);
@@ -655,15 +705,33 @@ bool pkgDepCache::RemovePseudoInstalledPkg(PkgIterator &Pkg, std::set<unsigned l
         recheck.insert(P.Index());
    }
 
-   if (V.end() != true)
-      for (PrvIterator Prv = V.ProvidesList(); Prv.end() != true; Prv++)
-        for (DepIterator d = Prv.ParentPkg().RevDependsList();
-             d.end() != true; ++d)
-        {
-           PkgIterator const P = d.ParentPkg();
-           if (P->CurrentVer != 0)
-              recheck.insert(P.Index());
-        }
+   for (DepIterator d = V.DependsList(); d.end() != true; ++d)
+   {
+      PkgIterator const P = d.TargetPkg();
+      for (PrvIterator Prv = P.ProvidesList(); Prv.end() != true; ++Prv)
+      {
+        PkgIterator const O = Prv.OwnerPkg();
+        if (O->CurrentVer != 0)
+           recheck.insert(O.Index());
+      }
+
+      if (P->CurrentVer != 0)
+        recheck.insert(P.Index());
+   }
+
+   for (PrvIterator Prv = V.ProvidesList(); Prv.end() != true; Prv++)
+   {
+      for (DepIterator d = Prv.ParentPkg().RevDependsList();
+          d.end() != true; ++d)
+      {
+        PkgIterator const P = d.ParentPkg();
+        if (P->CurrentVer == 0)
+           continue;
+
+           recheck.insert(P.Index());
+      }
+   }
+
 
    return true;
 }
@@ -747,6 +815,68 @@ void pkgDepCache::Update(OpProgress *Prog)
         }
         recheck.erase(p);
       }
+
+      /* Okay, we have killed a great amount of pseudopackages -
+        we have killed so many that we have now arch "all" packages
+        without an installed pseudo package, but we NEED an installed
+        pseudo package, so we will search now for a pseudo package
+        we can install without breaking everything. */
+      for (GrpIterator G = Cache->GrpBegin(); G.end() != true; ++G)
+      {
+        PkgIterator P = G.FindPkg("all");
+        if (P.end() == true)
+           continue;
+        if (P->CurrentVer == 0)
+           continue;
+        bool installed = false;
+        for (P = G.FindPkg("any"); P.end() != true; P = G.NextPkg(P))
+        {
+           if (strcmp(P.Arch(), "all") == 0)
+              continue;
+           if (P->CurrentVer == 0)
+              continue;
+           installed = true;
+           break;
+        }
+        if (installed == false)
+           recheck.insert(G.Index());
+      }
+      std::vector<std::string> Archs = APT::Configuration::getArchitectures();
+      bool checkChanged = false;
+      do {
+        for(std::set<unsigned long>::const_iterator g = recheck.begin();
+            g != recheck.end(); ++g) {
+           GrpIterator G = GrpIterator(*Cache, Cache->GrpP + *g);
+           VerIterator allV = G.FindPkg("all").CurrentVer();
+           for (std::vector<std::string>::const_iterator a = Archs.begin();
+                a != Archs.end(); ++a)
+           {
+              PkgIterator P = G.FindPkg(*a);
+              if (P.end() == true) continue;
+              for (VerIterator V = P.VersionList(); V.end() != true; ++V)
+              {
+                 // FIXME: String comparison isn't a save indicator!
+                 if (strcmp(allV.VerStr(),V.VerStr()) != 0)
+                    continue;
+                 unsigned char const CurDepState = VersionState(V.DependsList(),DepInstall,DepInstMin,DepInstPolicy);
+                 if ((CurDepState & DepInstMin) != DepInstMin)
+                    break; // we found the correct version, but it is broken. Better try another arch or later again
+                 P->CurrentVer = V.Index();
+                 AddStates(P);
+                 Update(P);
+                 AddSizes(P);
+                 checkChanged = true;
+                 break;
+              }
+           }
+           recheck.erase(g);
+        }
+      } while (checkChanged == true && recheck.empty() == false);
+
+      if (_config->FindB("Debug::MultiArchKiller", false) == true)
+        for(std::set<unsigned long>::const_iterator g = recheck.begin();
+            g != recheck.end(); ++g)
+           std::cout << "No pseudo package for »" << GrpIterator(*Cache, Cache->GrpP + *g).Name() << "« installed" << std::endl;
    }
 
    if (Prog != 0)