]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/depcache.cc
* cmdline/apt-get.cc:
[apt.git] / apt-pkg / depcache.cc
index ffa4fe71c0dd119c3a6c43f3258d8c6bef1b2128..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)