Просмотр исходного кода

log reinstall commands in history.log

David Kalnischkies лет назад: 15
Родитель
Сommit
97be52d437
4 измененных файлов с 38 добавлено и 18 удалено
  1. 29 18
      apt-pkg/deb/dpkgpm.cc
  2. 2 0
      apt-pkg/depcache.h
  3. 1 0
      debian/changelog
  4. 6 0
      test/integration/test-bug-611729-mark-as-manual

+ 29 - 18
apt-pkg/deb/dpkgpm.cc

@@ -681,31 +681,42 @@ bool pkgDPkgPM::OpenLog()
 	 return _error->WarningE("OpenLog", _("Could not open file '%s'"), history_name.c_str());
       chmod(history_name.c_str(), 0644);
       fprintf(history_out, "\nStart-Date: %s\n", timestr);
-      string remove, purge, install, upgrade, downgrade;
+      string remove, purge, install, reinstall, upgrade, downgrade;
       for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
       {
-	 if (Cache[I].NewInstall())
-	 {
-	    install += I.FullName(false) + string(" (") + Cache[I].CandVersion;
-	    if (Cache[I].Flags & pkgCache::Flag::Auto)
-	       install+= ", automatic";
-	    install += string("), ");
-	 }
-	 else if (Cache[I].Upgrade())
-	    upgrade += I.FullName(false) + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
-	 else if (Cache[I].Downgrade())
-	    downgrade += I.FullName(false) + string(" (") + Cache[I].CurVersion + string(", ") + Cache[I].CandVersion + string("), ");
-	 else if (Cache[I].Delete())
-	 {
-	    if ((Cache[I].iFlags & pkgDepCache::Purge) == pkgDepCache::Purge)
-	       purge += I.FullName(false) + string(" (") + Cache[I].CurVersion + string("), ");	    
-	    else
-	       remove += I.FullName(false) + string(" (") + Cache[I].CurVersion + string("), ");	    
+	 enum { CANDIDATE, CANDIDATE_AUTO, CURRENT_CANDIDATE, CURRENT } infostring;
+	 string *line = NULL;
+	 #define HISTORYINFO(X, Y) { line = &X; infostring = Y; }
+	 if (Cache[I].NewInstall() == true)
+	    HISTORYINFO(install, CANDIDATE_AUTO)
+	 else if (Cache[I].ReInstall() == true)
+	    HISTORYINFO(reinstall, CANDIDATE)
+	 else if (Cache[I].Upgrade() == true)
+	    HISTORYINFO(upgrade, CURRENT_CANDIDATE)
+	 else if (Cache[I].Downgrade() == true)
+	    HISTORYINFO(downgrade, CURRENT_CANDIDATE)
+	 else if (Cache[I].Delete() == true)
+	    HISTORYINFO((Cache[I].Purge() ? purge : remove), CURRENT)
+	 else
+	    continue;
+	 #undef HISTORYINFO
+	 line->append(I.FullName(false)).append(" (");
+	 switch (infostring) {
+	 case CANDIDATE: line->append(Cache[I].CandVersion); break;
+	 case CANDIDATE_AUTO:
+	    line->append(Cache[I].CandVersion);
+	    if ((Cache[I].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+	       line->append(", automatic");
+	    break;
+	 case CURRENT_CANDIDATE: line->append(Cache[I].CurVersion).append(", ").append(Cache[I].CandVersion); break;
+	 case CURRENT: line->append(Cache[I].CurVersion); break;
 	 }
+	 line->append("), ");
       }
       if (_config->Exists("Commandline::AsString") == true)
 	 WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
       WriteHistoryTag("Install", install);
+      WriteHistoryTag("Reinstall", reinstall);
       WriteHistoryTag("Upgrade", upgrade);
       WriteHistoryTag("Downgrade",downgrade);
       WriteHistoryTag("Remove",remove);

+ 2 - 0
apt-pkg/depcache.h

@@ -231,6 +231,7 @@ class pkgDepCache : protected pkgCache::Namespace
       // Various test members for the current status of the package
       inline bool NewInstall() const {return Status == 2 && Mode == ModeInstall;};
       inline bool Delete() const {return Mode == ModeDelete;};
+      inline bool Purge() const {return Delete() == true && (iFlags & pkgDepCache::Purge) == pkgDepCache::Purge; };
       inline bool Keep() const {return Mode == ModeKeep;};
       inline bool Upgrade() const {return Status > 0 && Mode == ModeInstall;};
       inline bool Upgradable() const {return Status >= 1;};
@@ -241,6 +242,7 @@ class pkgDepCache : protected pkgCache::Namespace
       inline bool InstBroken() const {return (DepState & DepInstMin) != DepInstMin;};
       inline bool InstPolicyBroken() const {return (DepState & DepInstPolicy) != DepInstPolicy;};
       inline bool Install() const {return Mode == ModeInstall;};
+      inline bool ReInstall() const {return Delete() == false && (iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall;};
       inline VerIterator InstVerIter(pkgCache &Cache)
                 {return VerIterator(Cache,InstallVer);};
       inline VerIterator CandidateVerIter(pkgCache &Cache)

+ 1 - 0
debian/changelog

@@ -31,6 +31,7 @@ apt (0.8.14.2) UNRELEASED; urgency=low
   * apt-pkg/deb/dpkgpm.cc:
     - replace obsolete usleep with nanosleep
     - remove invalid pkgcache.bin and rebuild it if possible
+    - log reinstall commands in history.log
   * debian/apt{,-utils}.symbols:
     - update both experimental symbol-files to reflect 0.8.14 state
   * debian/rules:

+ 6 - 0
test/integration/test-bug-611729-mark-as-manual

@@ -48,11 +48,17 @@ b is already the newest version.
 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' aptget install b -d
 testmarkedauto 'b'
 
+rm rootdir/var/log/apt/history.log
+
 aptget install b --reinstall -y -qq 2>&1 > /dev/null
 testdpkgnotinstalled a
 testdpkginstalled b c
 testmarkedauto 'b'
 
+sed -i rootdir/var/log/apt/history.log -e '/^Commandline: / d' -e '/^Start-Date: / d' -e '/^End-Date: / d'
+testfileequal 'rootdir/var/log/apt/history.log' '
+Reinstall: b:i386 (1.0)'
+
 testequal 'Reading package lists...
 Building dependency tree...
 Reading state information...