Преглед изворни кода

* apt-pkg/depcache.cc:
- remove Auto-Installed information from extended_states
together with the package itself (Closes: #572364)

David Kalnischkies пре 16 година
родитељ
комит
c176c4d0ad
5 измењених фајлова са 44 додато и 20 уклоњено
  1. 24 7
      apt-pkg/depcache.cc
  2. 1 1
      apt-pkg/depcache.h
  3. 2 11
      apt-pkg/tagfile.cc
  4. 14 1
      apt-pkg/tagfile.h
  5. 3 0
      debian/changelog

+ 24 - 7
apt-pkg/depcache.cc

@@ -235,16 +235,30 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly)	/*{{{*/
    std::set<string> pkgs_seen;
    std::set<string> pkgs_seen;
    const char *nullreorderlist[] = {0};
    const char *nullreorderlist[] = {0};
    while(tagfile.Step(section)) {
    while(tagfile.Step(section)) {
-	 string pkgname = section.FindS("Package");
+	 string const pkgname = section.FindS("Package");
 	 // Silently ignore unknown packages and packages with no actual
 	 // Silently ignore unknown packages and packages with no actual
 	 // version.
 	 // version.
 	 pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
 	 pkgCache::PkgIterator pkg=Cache->FindPkg(pkgname);
 	 if(pkg.end() || pkg.VersionList().end()) 
 	 if(pkg.end() || pkg.VersionList().end()) 
 	    continue;
 	    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))
 	 if(_config->FindB("Debug::pkgAutoRemove",false))
 	    std::clog << "Update existing AutoInstall info: " 
 	    std::clog << "Update existing AutoInstall info: " 
-		      << pkg.Name() << std::endl;
+		      << pkgname << std::endl;
 	 TFRewriteData rewrite[2];
 	 TFRewriteData rewrite[2];
 	 rewrite[0].Tag = "Auto-Installed";
 	 rewrite[0].Tag = "Auto-Installed";
 	 rewrite[0].Rewrite = newAuto ? "1" : "0";
 	 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
    // then write the ones we have not seen yet
    std::ostringstream ostr;
    std::ostringstream ostr;
    for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); pkg++) {
    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 (pkgs_seen.find(pkg.Name()) != pkgs_seen.end()) {
 	    if(debug_autoremove)
 	    if(debug_autoremove)
 	       std::clog << "Skipping already written " << pkg.Name() << std::endl;
 	       std::clog << "Skipping already written " << pkg.Name() << std::endl;
 	    continue;
 	    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)
 	 if(debug_autoremove)
 	    std::clog << "Writing new AutoInstall: " 
 	    std::clog << "Writing new AutoInstall: " 
 		      << pkg.Name() << std::endl;
 		      << pkg.Name() << std::endl;

+ 1 - 1
apt-pkg/depcache.h

@@ -447,7 +447,7 @@ class pkgDepCache : protected pkgCache::Namespace
 
 
    // read persistent states
    // read persistent states
    bool readStateFile(OpProgress *prog);
    bool readStateFile(OpProgress *prog);
-   bool writeStateFile(OpProgress *prog, bool InstalledOnly=false);
+   bool writeStateFile(OpProgress *prog, bool InstalledOnly=true);
    
    
    // Size queries
    // Size queries
    inline double UsrSize() {return iUsrSize;};
    inline double UsrSize() {return iUsrSize;};

+ 2 - 11
apt-pkg/tagfile.cc

@@ -193,17 +193,8 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long Offset)
 									/*}}}*/
 									/*}}}*/
 // TagSection::Scan - Scan for the end of the header information	/*{{{*/
 // 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)
 bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
 {
 {
    const char *End = Start + MaxLength;
    const char *End = Start + MaxLength;

+ 14 - 1
apt-pkg/tagfile.h

@@ -33,7 +33,18 @@ class pkgTagSection
    unsigned int AlphaIndexes[0x100];
    unsigned int AlphaIndexes[0x100];
    
    
    unsigned int TagCount;
    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:
    protected:
    const char *Stop;
    const char *Stop;
 
 
@@ -54,6 +65,8 @@ class pkgTagSection
    virtual void TrimRecord(bool BeforeRecord, const char* &End);
    virtual void TrimRecord(bool BeforeRecord, const char* &End);
    
    
    inline unsigned int Count() const {return TagCount;};
    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
    inline void Get(const char *&Start,const char *&Stop,unsigned int I) const
                    {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
                    {Start = Section + Indexes[I]; Stop = Section + Indexes[I+1];}
 	    
 	    

+ 3 - 0
debian/changelog

@@ -6,6 +6,9 @@ apt (0.7.26) UNRELEASED; urgency=low
 
 
   [ David Kalnischkies ]
   [ David Kalnischkies ]
   * Switch to dpkg-source 3.0 (native) format
   * 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:
   * cmdline/apt-mark:
     - don't crash if no arguments are given (Closes: #570962)
     - don't crash if no arguments are given (Closes: #570962)
   * debian/control:
   * debian/control: