Browse Source

Show "Manual-Installed: {yes|no}" in apt show

Michael Vogt 12 years ago
parent
commit
85d7c0eb60
2 changed files with 16 additions and 1 deletions
  1. 12 0
      apt-private/private-show.cc
  2. 4 1
      test/integration/test-apt-cli-show

+ 12 - 0
apt-private/private-show.cc

@@ -37,6 +37,9 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
    pkgCache *Cache = CacheFile.GetPkgCache();
    if (unlikely(Cache == NULL))
       return false;
+   pkgDepCache *depCache = CacheFile.GetDepCache();
+   if (unlikely(depCache == NULL))
+      return false;
 
    // Find an appropriate file
    pkgCache::VerFileIterator Vf = V.FileList();
@@ -73,6 +76,13 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
    else
       package_size = _("unknown");
 
+   pkgDepCache::StateCache &state = (*depCache)[V.ParentPkg()];
+   bool is_installed = V.ParentPkg().CurrentVer() == V;
+   const char *manual_installed;
+   if (is_installed)
+      manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no";
+   else
+      manual_installed = 0;
    std::string suite = GetArchiveSuite(CacheFile, V);
    TFRewriteData RW[] = {
       {"Conffiles",0},
@@ -81,8 +91,10 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
       {"Installed-Size", installed_size.c_str(), 0},
       {"Size", package_size.c_str(), "Download-Size"},
       {"Archive-Origin", suite.c_str(), 0},
+      {"Manual-Installed", manual_installed, 0},
       {}
    };
+
    if(TFRewrite(stdout, Tags, NULL, RW) == false)
       return _error->Error("Internal Error, Unable to parse a package record");
 

+ 4 - 1
test/integration/test-apt-cli-show

@@ -10,12 +10,14 @@ configarchitecture "i386"
 DESCR='Some description 
  That has multiple lines'
 insertpackage 'unstable' 'foo' 'all' '1.0' '' '' "$DESCR"
+insertinstalledpackage 'foo' 'all' '1.0'
 
 setupaptarchive
 
 APTARCHIVE=$(readlink -f ./aptarchive)
 
 # note that we do not display Description-md5 with the "apt" cmd
+# and also show some additional fields that are calculated
 testequal "Package: foo
 Priority: optional
 Section: other
@@ -25,7 +27,8 @@ Architecture: all
 Version: 1.0
 Filename: pool/main/foo/foo_1.0_all.deb
 Download-Size: unknown
-Archive-Origin: unstable
+Archive-Origin: unstable,now
+Manual-Installed: yes
 Description: Some description 
  That has multiple lines
 " apt show foo