From 97be52d4372d1ca6b8d276060b434348876ca322 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 23 May 2011 18:10:48 +0200 Subject: log reinstall commands in history.log --- apt-pkg/deb/dpkgpm.cc | 47 +++++++++++++++---------- apt-pkg/depcache.h | 2 ++ debian/changelog | 1 + test/integration/test-bug-611729-mark-as-manual | 6 ++++ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index a9d23ea67..5ddcd47e9 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/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); diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 750da3d6f..9efe110f5 100644 --- a/apt-pkg/depcache.h +++ b/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) diff --git a/debian/changelog b/debian/changelog index 7f52d844e..fe562e363 100644 --- a/debian/changelog +++ b/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: diff --git a/test/integration/test-bug-611729-mark-as-manual b/test/integration/test-bug-611729-mark-as-manual index 4e3e2fa0b..9cf01610c 100755 --- a/test/integration/test-bug-611729-mark-as-manual +++ b/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... -- cgit v1.2.3