]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/depcache.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 14 Mar 2010 20:48:14 +0000 (21:48 +0100)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sun, 14 Mar 2010 20:48:14 +0000 (21:48 +0100)
  - remove Auto-Installed information from extended_states
    together with the package itself (Closes: #572364)

apt-pkg/depcache.cc
apt-pkg/depcache.h
apt-pkg/tagfile.cc
apt-pkg/tagfile.h
debian/changelog

index 5943d858a2fb6d5373bc4a2004f50ba93cddfff1..e9fb5f76ab5dbcdb97a6add80e6ae71448ad73cb 100644 (file)
@@ -235,16 +235,30 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)    /*{{{*/
    std::set<string> pkgs_seen;
    const char *nullreorderlist[] = {0};
    while(tagfile.Step(section)) {
-        string pkgname = section.FindS("Package");
+        string const pkgname = section.FindS("Package");
         // Silently ignore unknown packages and packages with no actual
         // version.
         pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
         if(pkg.end() || pkg.VersionList().end()) 
            continue;
-        bool 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")))
+              continue;
+           else
+              newAuto = false;
+        }
         if(_config->FindB("Debug::pkgAutoRemove",false))
            std::clog << "Update existing AutoInstall info: " 
-                     << pkg.Name() << std::endl;
+                     << pkgname << std::endl;
         TFRewriteData rewrite[2];
         rewrite[0].Tag = "Auto-Installed";
         rewrite[0].Rewrite = newAuto ? "1" : "0";
@@ -258,15 +272,18 @@ 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.Name()) != pkgs_seen.end()) {
            if(debug_autoremove)
               std::clog << "Skipping already written " << pkg.Name() << std::endl;
            continue;
         }
-         // skip not installed ones if requested
-         if(InstalledOnly && pkg->CurrentVer == 0)
-            continue;
+        // skip not installed ones if requested
+        if (InstalledOnly && (
+            (pkg->CurrentVer == 0 && P.Mode != ModeInstall) ||
+            (pkg->CurrentVer != 0 && P.Mode == ModeDelete)))
+           continue;
         if(debug_autoremove)
            std::clog << "Writing new AutoInstall: " 
                      << pkg.Name() << std::endl;
index 0306861a1b4ea0399a09c008ce08e847a560ef88..fd1f202be3bc1e3166890ecafe6bdc0451f15e81 100644 (file)
@@ -447,7 +447,7 @@ class pkgDepCache : protected pkgCache::Namespace
 
    // read persistent states
    bool readStateFile(OpProgress *prog);
-   bool writeStateFile(OpProgress *prog, bool InstalledOnly=false);
+   bool writeStateFile(OpProgress *prog, bool InstalledOnly=true);
    
    // Size queries
    inline double UsrSize() {return iUsrSize;};
index 7c5d15a58b0df992ab95e659d1ba555f9c838649..0d4999ee7774a94e2bda998dac98524e95e864ba 100644 (file)
@@ -193,17 +193,8 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long Offset)
                                                                        /*}}}*/
 // TagSection::Scan - Scan for the end of the header information       /*{{{*/
 // ---------------------------------------------------------------------
-/* This looks for the first double new line in the data stream. It also
-   indexes the tags in the section. This very simple hash function for the
-   last 8 letters gives very good performance on the debian package files */
-inline static unsigned long AlphaHash(const char *Text, const char *End = 0)
-{
-   unsigned long Res = 0;
-   for (; Text != End && *Text != ':' && *Text != 0; Text++)
-      Res = ((unsigned long)(*Text) & 0xDF) ^ (Res << 1);
-   return Res & 0xFF;
-}
-
+/* This looks for the first double new line in the data stream.
+   It also indexes the tags in the section. */
 bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
 {
    const char *End = Start + MaxLength;
index 321329a2346c49cccb46f0df4bd1ea30da94f379..f63a51d07843be82fe63a95daf64ff24797e5214 100644 (file)
@@ -33,7 +33,18 @@ class pkgTagSection
    unsigned int AlphaIndexes[0x100];
    
    unsigned int TagCount;
-     
+
+   /* This very simple hash function for the last 8 letters gives
+      very good performance on the debian package files */
+   inline static unsigned long AlphaHash(const char *Text, const char *End = 0)
+   {
+      unsigned long Res = 0;
+      for (; Text != End && *Text != ':' && *Text != 0; Text++)
+        Res = ((unsigned long)(*Text) & 0xDF) ^ (Res << 1);
+      return Res & 0xFF;
+   }
+
+
    protected:
    const char *Stop;
 
@@ -54,6 +65,8 @@ class pkgTagSection
    virtual void TrimRecord(bool BeforeRecord, const char* &End);
    
    inline unsigned int Count() const {return TagCount;};
+   inline bool Exists(const char* const Tag) {return AlphaIndexes[AlphaHash(Tag)] != 0;}
    inline void Get(const char *&Start,const char *&Stop,unsigned int I) const
                    {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
            
index 142577e421e8c4a58658f5cf08ecf468e548bf20..415a6fd8d7c7e343a8dd442ac144249668999fd4 100644 (file)
@@ -6,6 +6,9 @@ apt (0.7.26) UNRELEASED; urgency=low
 
   [ David Kalnischkies ]
   * Switch to dpkg-source 3.0 (native) format
+  * apt-pkg/depcache.cc:
+    - remove Auto-Installed information from extended_states
+      together with the package itself (Closes: #572364)
   * cmdline/apt-mark:
     - don't crash if no arguments are given (Closes: #570962)
   * debian/control: