Browse Source

hidden support more apt-get/apt-cache commands in apt

apt is supposed to be a user-friendly interface, so while these commands
are usually poweruser material and therefore do not need to be shown in
general introduction manpages/help messages its of no use to not allow
users to use them.

This includes clean, autoclean, build-dep, source, download, changelog,
depends, rdepends and showsrc – it doesn't include more non-interactive
commands like dump or xvcg as those are usually used by scripts if at
all.

Closes: 778234, 780700, 781237
David Kalnischkies 8 years ago
parent
commit
9055d5e68b

+ 152 - 0
apt-private/private-depends.cc

@@ -0,0 +1,152 @@
+// Include Files							/*{{{*/
+#include<config.h>
+
+#include <apt-pkg/algorithms.h>
+#include <apt-pkg/cachefile.h>
+#include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <apt-private/private-cacheset.h>
+#include <apt-private/private-depends.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <stddef.h>
+
+#include <apti18n.h>
+									/*}}}*/
+
+// ShowDepends - Helper for printing out a dependency tree		/*{{{*/
+static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
+{
+   pkgCacheFile CacheFile;
+   pkgCache *Cache = CacheFile.GetPkgCache();
+   if (unlikely(Cache == NULL))
+      return false;
+
+   CacheSetHelperVirtuals helper(false);
+   APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
+   if (verset.empty() == true && helper.virtualPkgs.empty() == true)
+      return _error->Error(_("No packages found"));
+   std::vector<bool> Shown(Cache->Head().PackageCount);
+
+   bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
+   bool const Installed = _config->FindB("APT::Cache::Installed", false);
+   bool const Important = _config->FindB("APT::Cache::Important", false);
+   bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
+   bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
+   bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
+   bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
+   bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
+   bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
+   bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
+   bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
+   bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
+   bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
+   bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
+   bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
+
+   while (verset.empty() != true)
+   {
+      pkgCache::VerIterator Ver = *verset.begin();
+      verset.erase(verset.begin());
+      pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+      Shown[Pkg->ID] = true;
+
+      std::cout << Pkg.FullName(true) << std::endl;
+
+      if (RevDepends == true)
+	 std::cout << "Reverse Depends:" << std::endl;
+      for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
+	    D.end() == false; ++D)
+      {
+	 switch (D->Type) {
+	    case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
+	    case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
+	    case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
+	    case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
+	    case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
+	    case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
+	    case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
+	    case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
+	 }
+	 if (ShowImplicit == false && D.IsImplicit())
+	    continue;
+
+	 pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
+
+	 if((Installed && Trg->CurrentVer != 0) || !Installed)
+	 {
+
+	    if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
+	       std::cout << " |";
+	    else
+	       std::cout << "  ";
+
+	    // Show the package
+	    if (ShowDepType == true)
+	       std::cout << D.DepType() << ": ";
+	    if (Trg->VersionList == 0)
+	       std::cout << "<" << Trg.FullName(true) << ">";
+	    else
+	       std::cout << Trg.FullName(true);
+	    if (ShowVersion == true && D->Version != 0)
+	       std::cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
+	    std::cout << std::endl;
+
+	    if (Recurse == true && Shown[Trg->ID] == false)
+	    {
+	       Shown[Trg->ID] = true;
+	       verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
+	    }
+
+	 }
+
+	 // Display all solutions
+	 std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
+	 pkgPrioSortList(*Cache,List.get());
+	 for (pkgCache::Version **I = List.get(); *I != 0; I++)
+	 {
+	    pkgCache::VerIterator V(*Cache,*I);
+	    if (V != Cache->VerP + V.ParentPkg()->VersionList ||
+		  V->ParentPkg == D->Package)
+	       continue;
+	    std::cout << "    " << V.ParentPkg().FullName(true) << std::endl;
+
+	    if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
+	    {
+	       Shown[V.ParentPkg()->ID] = true;
+	       verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
+	    }
+	 }
+
+	 if (ShowOnlyFirstOr == true)
+	    while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
+      }
+   }
+
+   for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
+	 Pkg != helper.virtualPkgs.end(); ++Pkg)
+      std::cout << '<' << Pkg.FullName(true) << '>' << std::endl;
+
+   return true;
+}
+									/*}}}*/
+// Depends - Print out a dependency tree				/*{{{*/
+bool Depends(CommandLine &CmdL)
+{
+   return ShowDepends(CmdL, false);
+}
+									/*}}}*/
+// RDepends - Print out a reverse dependency tree			/*{{{*/
+bool RDepends(CommandLine &CmdL)
+{
+   return ShowDepends(CmdL, true);
+}
+									/*}}}*/

+ 11 - 0
apt-private/private-depends.h

@@ -0,0 +1,11 @@
+#ifndef APT_PRIVATE_DEPENDS_H
+#define APT_PRIVATE_DEPENDS_H
+
+#include <apt-pkg/macros.h>
+
+class CommandLine;
+
+APT_PUBLIC bool Depends(CommandLine &CmdL);
+APT_PUBLIC bool RDepends(CommandLine &CmdL);
+
+#endif

+ 202 - 1
apt-private/private-download.cc

@@ -3,13 +3,18 @@
 
 #include <apt-pkg/acquire.h>
 #include <apt-pkg/acquire-item.h>
+#include <apt-pkg/cacheset.h>
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/clean.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/strutl.h>
 
-#include <apt-private/private-output.h>
+#include <apt-private/private-cachefile.h>
 #include <apt-private/private-download.h>
+#include <apt-private/private-output.h>
+#include <apt-private/private-utils.h>
 #include <apt-private/acqprogress.h>
 
 #include <fstream>
@@ -155,3 +160,199 @@ aptAcquireWithTextStatus::aptAcquireWithTextStatus() : pkgAcquire::pkgAcquire(),
 {
    SetLog(&Stat);
 }
+
+// DoDownload - download a binary					/*{{{*/
+bool DoDownload(CommandLine &CmdL)
+{
+   CacheFile Cache;
+   if (Cache.ReadOnlyOpen() == false)
+      return false;
+
+   APT::CacheSetHelper helper;
+   APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
+		CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
+
+   if (verset.empty() == true)
+      return false;
+
+   pkgRecords Recs(Cache);
+   pkgSourceList *SrcList = Cache.GetSourceList();
+
+   // reuse the usual acquire methods for deb files, but don't drop them into
+   // the usual directories - keep everything in the current directory
+   aptAcquireWithTextStatus Fetcher;
+   std::vector<std::string> storefile(verset.size());
+   std::string const cwd = SafeGetCWD();
+   _config->Set("Dir::Cache::Archives", cwd);
+   int i = 0;
+   for (APT::VersionSet::const_iterator Ver = verset.begin();
+	 Ver != verset.end(); ++Ver, ++i)
+   {
+      pkgAcquire::Item *I = new pkgAcqArchive(&Fetcher, SrcList, &Recs, *Ver, storefile[i]);
+      if (storefile[i].empty())
+	 continue;
+      std::string const filename = cwd + flNotDir(storefile[i]);
+      storefile[i].assign(filename);
+      I->DestFile.assign(filename);
+   }
+
+   // Just print out the uris and exit if the --print-uris flag was used
+   if (_config->FindB("APT::Get::Print-URIs") == true)
+   {
+      pkgAcquire::UriIterator I = Fetcher.UriBegin();
+      for (; I != Fetcher.UriEnd(); ++I)
+	 std::cout << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile)  << ' ' <<
+	       I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
+      return true;
+   }
+
+   if (_error->PendingError() == true || CheckAuth(Fetcher, false) == false)
+      return false;
+
+   bool Failed = false;
+   if (AcquireRun(Fetcher, 0, &Failed, NULL) == false)
+      return false;
+
+   // copy files in local sources to the current directory
+   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
+   {
+      std::string const filename = cwd + flNotDir((*I)->DestFile);
+      if ((*I)->Local == true &&
+          filename != (*I)->DestFile &&
+          (*I)->Status == pkgAcquire::Item::StatDone)
+      {
+	 std::ifstream src((*I)->DestFile.c_str(), std::ios::binary);
+	 std::ofstream dst(filename.c_str(), std::ios::binary);
+	 dst << src.rdbuf();
+      }
+   }
+   return Failed == false;
+}
+									/*}}}*/
+// DoChangelog - Get changelog from the command line			/*{{{*/
+bool DoChangelog(CommandLine &CmdL)
+{
+   CacheFile Cache;
+   if (Cache.ReadOnlyOpen() == false)
+      return false;
+
+   APT::CacheSetHelper helper;
+   APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
+		CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
+   if (verset.empty() == true)
+      return false;
+
+   bool const downOnly = _config->FindB("APT::Get::Download-Only", false);
+   bool const printOnly = _config->FindB("APT::Get::Print-URIs", false);
+
+   aptAcquireWithTextStatus Fetcher;
+   for (APT::VersionList::const_iterator Ver = verset.begin();
+        Ver != verset.end();
+        ++Ver)
+   {
+      if (printOnly)
+	 new pkgAcqChangelog(&Fetcher, Ver, "/dev/null");
+      else if (downOnly)
+	 new pkgAcqChangelog(&Fetcher, Ver, ".");
+      else
+	 new pkgAcqChangelog(&Fetcher, Ver);
+   }
+
+   if (printOnly == false)
+   {
+      bool Failed = false;
+      if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == true)
+	 return false;
+   }
+
+   if (downOnly == false || printOnly == true)
+   {
+      bool Failed = false;
+      for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); ++I)
+      {
+	 if (printOnly)
+	 {
+	    if ((*I)->ErrorText.empty() == false)
+	    {
+	       Failed = true;
+	       _error->Error("%s", (*I)->ErrorText.c_str());
+	    }
+	    else
+	       std::cout << '\'' << (*I)->DescURI() << "' " << flNotDir((*I)->DestFile)  << std::endl;
+	 }
+	 else
+	    DisplayFileInPager((*I)->DestFile);
+      }
+      return Failed == false;
+   }
+
+   return true;
+}
+									/*}}}*/
+
+// DoClean - Remove download archives					/*{{{*/
+bool DoClean(CommandLine &)
+{
+   std::string const archivedir = _config->FindDir("Dir::Cache::archives");
+   std::string const listsdir = _config->FindDir("Dir::state::lists");
+
+   if (_config->FindB("APT::Get::Simulate") == true)
+   {
+      std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
+      std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
+      std::cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< std::endl
+	   << "Del " << listsdir << "partial/*" << std::endl
+	   << "Del " << pkgcache << " " << srcpkgcache << std::endl;
+      return true;
+   }
+
+   pkgAcquire Fetcher;
+   Fetcher.GetLock(archivedir);
+   Fetcher.Clean(archivedir);
+   Fetcher.Clean(archivedir + "partial/");
+
+   Fetcher.GetLock(listsdir);
+   Fetcher.Clean(listsdir + "partial/");
+
+   pkgCacheFile::RemoveCaches();
+
+   return true;
+}
+									/*}}}*/
+// DoAutoClean - Smartly remove downloaded archives			/*{{{*/
+// ---------------------------------------------------------------------
+/* This is similar to clean but it only purges things that cannot be 
+   downloaded, that is old versions of cached packages. */
+ class LogCleaner : public pkgArchiveCleaner
+{
+   protected:
+      virtual void Erase(const char *File, std::string Pkg, std::string Ver,struct stat &St) APT_OVERRIDE
+      {
+	 c1out << "Del " << Pkg << " " << Ver << " [" << SizeToStr(St.st_size) << "B]" << std::endl;
+
+	 if (_config->FindB("APT::Get::Simulate") == false)
+	    unlink(File);
+      };
+};
+bool DoAutoClean(CommandLine &)
+{
+   // Lock the archive directory
+   FileFd Lock;
+   if (_config->FindB("Debug::NoLocking",false) == false)
+   {
+      int lock_fd = GetLock(_config->FindDir("Dir::Cache::Archives") + "lock");
+      if (lock_fd < 0)
+	 return _error->Error(_("Unable to lock the download directory"));
+      Lock.Fd(lock_fd);
+   }
+
+   CacheFile Cache;
+   if (Cache.Open() == false)
+      return false;
+
+   LogCleaner Cleaner;
+
+   return Cleaner.Go(_config->FindDir("Dir::Cache::archives"),*Cache) &&
+      Cleaner.Go(_config->FindDir("Dir::Cache::archives") + "partial/",*Cache);
+}
+									/*}}}*/

+ 8 - 0
apt-private/private-download.h

@@ -27,4 +27,12 @@ public:
    aptAcquireWithTextStatus();
 };
 
+class CommandLine;
+
+APT_PUBLIC bool DoDownload(CommandLine &CmdL);
+APT_PUBLIC bool DoChangelog(CommandLine &CmdL);
+
+APT_PUBLIC bool DoClean(CommandLine &CmdL);
+APT_PUBLIC bool DoAutoClean(CommandLine &CmdL);
+
 #endif

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

@@ -17,6 +17,7 @@
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/macros.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/policy.h>
 
 #include <apt-private/private-cacheset.h>
 #include <apt-private/private-output.h>
@@ -297,3 +298,183 @@ bool ShowPackage(CommandLine &CmdL)					/*{{{*/
    return true;
 }
 									/*}}}*/
+bool ShowSrcPackage(CommandLine &CmdL)					/*{{{*/
+{
+   pkgCacheFile CacheFile;
+   pkgSourceList *List = CacheFile.GetSourceList();
+   if (unlikely(List == NULL))
+      return false;
+
+   // Create the text record parsers
+   pkgSrcRecords SrcRecs(*List);
+   if (_error->PendingError() == true)
+      return false;
+
+   bool found = false;
+   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+   {
+      SrcRecs.Restart();
+
+      pkgSrcRecords::Parser *Parse;
+      bool found_this = false;
+      while ((Parse = SrcRecs.Find(*I,false)) != 0) {
+	 // SrcRecs.Find() will find both binary and source names
+	 if (_config->FindB("APT::Cache::Only-Source", false) == true)
+	    if (Parse->Package() != *I)
+	       continue;
+	 std::cout << Parse->AsStr() << std::endl;;
+	 found = true;
+	 found_this = true;
+      }
+      if (found_this == false) {
+	 _error->Warning(_("Unable to locate package %s"),*I);
+	 continue;
+      }
+   }
+   if (found == false)
+      _error->Notice(_("No packages found"));
+   return true;
+}
+									/*}}}*/
+// Policy - Show the results of the preferences file			/*{{{*/
+bool Policy(CommandLine &CmdL)
+{
+   pkgCacheFile CacheFile;
+   pkgCache *Cache = CacheFile.GetPkgCache();
+   pkgPolicy *Plcy = CacheFile.GetPolicy();
+   pkgSourceList *SrcList = CacheFile.GetSourceList();
+   if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL))
+      return false;
+
+   bool OldPolicy = _config->FindI("APT::Policy", 1) < 1;
+
+   // Print out all of the package files
+   if (CmdL.FileList[1] == 0)
+   {
+      std::cout << _("Package files:") << std::endl;
+      for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F)
+      {
+	 if (F.Flagged(pkgCache::Flag::NoPackages))
+	    continue;
+	 // Locate the associated index files so we can derive a description
+	 pkgIndexFile *Indx;
+	 if (SrcList->FindIndex(F,Indx) == false &&
+	       _system->FindIndex(F,Indx) == false)
+	    return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
+
+	 printf("%4i %s\n",
+	       Plcy->GetPriority(F),Indx->Describe(true).c_str());
+
+	 // Print the reference information for the package
+	 std::string Str = F.RelStr();
+	 if (Str.empty() == false)
+	    printf("     release %s\n",F.RelStr().c_str());
+	 if (F.Site() != 0 && F.Site()[0] != 0)
+	    printf("     origin %s\n",F.Site());
+      }
+
+      // Show any packages have explicit pins
+      std::cout << _("Pinned packages:") << std::endl;
+      pkgCache::PkgIterator I = Cache->PkgBegin();
+      for (;I.end() != true; ++I)
+      {
+	 // Old code for debugging
+	 if (OldPolicy)
+	 {
+	    if (Plcy->GetPriority(I) == 0)
+	       continue;
+
+	    // Print the package name and the version we are forcing to
+	    std::cout << "     " << I.FullName(true) << " -> ";
+
+	    pkgCache::VerIterator V = Plcy->GetMatch(I);
+	    if (V.end() == true)
+	       std::cout << _("(not found)") << std::endl;
+	    else
+	       std::cout << V.VerStr() << std::endl;
+
+	    continue;
+	 }
+	 // New code
+	 for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) {
+	    auto Prio = Plcy->GetPriority(V, false);
+	    if (Prio == 0)
+	       continue;
+
+	    std::cout << "     ";
+	    // Print the package name and the version we are forcing to
+	    ioprintf(std::cout, _("%s -> %s with priority %d\n"), I.FullName(true).c_str(), V.VerStr(), Prio);
+	 }
+      }
+      return true;
+   }
+
+   char const * const msgInstalled = _("  Installed: ");
+   char const * const msgCandidate = _("  Candidate: ");
+   short const InstalledLessCandidate =
+      mbstowcs(NULL, msgInstalled, 0) - mbstowcs(NULL, msgCandidate, 0);
+   short const deepInstalled =
+      (InstalledLessCandidate < 0 ? (InstalledLessCandidate*-1) : 0) - 1;
+   short const deepCandidate =
+      (InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1;
+
+   // Print out detailed information for each package
+   APT::CacheSetHelper helper(true, GlobalError::NOTICE);
+   APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper);
+   for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
+   {
+      std::cout << Pkg.FullName(true) << ":" << std::endl;
+
+      // Installed version
+      std::cout << msgInstalled << OutputInDepth(deepInstalled, " ");
+      if (Pkg->CurrentVer == 0)
+	 std::cout << _("(none)") << std::endl;
+      else
+	 std::cout << Pkg.CurrentVer().VerStr() << std::endl;
+
+      // Candidate Version 
+      std::cout << msgCandidate << OutputInDepth(deepCandidate, " ");
+      pkgCache::VerIterator V = Plcy->GetCandidateVer(Pkg);
+      if (V.end() == true)
+	 std::cout << _("(none)") << std::endl;
+      else
+	 std::cout << V.VerStr() << std::endl;
+
+      // Pinned version
+      if (OldPolicy && Plcy->GetPriority(Pkg) != 0)
+      {
+	 std::cout << _("  Package pin: ");
+	 V = Plcy->GetMatch(Pkg);
+	 if (V.end() == true)
+	    std::cout << _("(not found)") << std::endl;
+	 else
+	    std::cout << V.VerStr() << std::endl;
+      }
+
+      // Show the priority tables
+      std::cout << _("  Version table:") << std::endl;
+      for (V = Pkg.VersionList(); V.end() == false; ++V)
+      {
+	 if (Pkg.CurrentVer() == V)
+	    std::cout << " *** " << V.VerStr();
+	 else
+	    std::cout << "     " << V.VerStr();
+	 if (_config->FindI("APT::Policy", 1) < 1)
+	    std::cout << " " << Plcy->GetPriority(Pkg) << std::endl;
+	 else
+	    std::cout << " " << Plcy->GetPriority(V) << std::endl;
+	 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF)
+	 {
+	    // Locate the associated index files so we can derive a description
+	    pkgIndexFile *Indx;
+	    if (SrcList->FindIndex(VF.File(),Indx) == false &&
+		  _system->FindIndex(VF.File(),Indx) == false)
+	       return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
+	    printf("       %4i %s\n",Plcy->GetPriority(VF.File()),
+		  Indx->Describe(true).c_str());
+	 }
+      }
+   }
+   return true;
+}
+									/*}}}*/

+ 2 - 0
apt-private/private-show.h

@@ -11,5 +11,7 @@ class pkgCacheFile;
 
 APT_PUBLIC bool ShowPackage(CommandLine &CmdL);
 APT_PUBLIC bool DisplayRecordV1(pkgCacheFile &CacheFile, pkgCache::VerIterator const &V, std::ostream &out);
+APT_PUBLIC bool ShowSrcPackage(CommandLine &CmdL);
+APT_PUBLIC bool Policy(CommandLine &CmdL);
 
 #endif

File diff suppressed because it is too large
+ 1028 - 0
apt-private/private-source.cc


+ 11 - 0
apt-private/private-source.h

@@ -0,0 +1,11 @@
+#ifndef APT_PRIVATE_SOURCE_H
+#define APT_PRIVATE_SOURCE_H
+
+#include <apt-pkg/macros.h>
+
+class CommandLine;
+
+APT_PUBLIC bool DoSource(CommandLine &CmdL);
+APT_PUBLIC bool DoBuildDep(CommandLine &CmdL);
+
+#endif

+ 1 - 321
cmdline/apt-cache.cc

@@ -43,6 +43,7 @@
 
 #include <apt-private/private-cacheset.h>
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-depends.h>
 #include <apt-private/private-show.h>
 #include <apt-private/private-search.h>
 #include <apt-private/private-main.h>
@@ -638,138 +639,6 @@ static bool DumpAvail(CommandLine &)
    return !_error->PendingError();
 }
 									/*}}}*/
-// ShowDepends - Helper for printing out a dependency tree		/*{{{*/
-static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
-{
-   pkgCacheFile CacheFile;
-   pkgCache *Cache = CacheFile.GetPkgCache();
-   if (unlikely(Cache == NULL))
-      return false;
-
-   CacheSetHelperVirtuals helper(false);
-   APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
-   if (verset.empty() == true && helper.virtualPkgs.empty() == true)
-      return _error->Error(_("No packages found"));
-   std::vector<bool> Shown(Cache->Head().PackageCount);
-
-   bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
-   bool const Installed = _config->FindB("APT::Cache::Installed", false);
-   bool const Important = _config->FindB("APT::Cache::Important", false);
-   bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
-   bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
-   bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
-   bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
-   bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
-   bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
-   bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
-   bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
-   bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
-   bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
-   bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
-   bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
-
-   while (verset.empty() != true)
-   {
-      pkgCache::VerIterator Ver = *verset.begin();
-      verset.erase(verset.begin());
-      pkgCache::PkgIterator Pkg = Ver.ParentPkg();
-      Shown[Pkg->ID] = true;
-
-	 cout << Pkg.FullName(true) << endl;
-
-	 if (RevDepends == true)
-	    cout << "Reverse Depends:" << endl;
-	 for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
-	      D.end() == false; ++D)
-	 {
-	    switch (D->Type) {
-	    case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
-	    case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
-	    case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
-	    case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
-	    case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
-	    case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
-	    case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
-	    case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
-	    }
-	    if (ShowImplicit == false && D.IsImplicit())
-	       continue;
-
-	    pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
-
-	    if((Installed && Trg->CurrentVer != 0) || !Installed)
-	      {
-
-		if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
-		  cout << " |";
-		else
-		  cout << "  ";
-	    
-		// Show the package
-		if (ShowDepType == true)
-		  cout << D.DepType() << ": ";
-		if (Trg->VersionList == 0)
-		  cout << "<" << Trg.FullName(true) << ">";
-		else
-		  cout << Trg.FullName(true);
-		if (ShowVersion == true && D->Version != 0)
-		   cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
-		cout << std::endl;
-
-		if (Recurse == true && Shown[Trg->ID] == false)
-		{
-		  Shown[Trg->ID] = true;
-		  verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
-		}
-
-	      }
-	    
-	    // Display all solutions
-	    std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
-	    pkgPrioSortList(*Cache,List.get());
-	    for (pkgCache::Version **I = List.get(); *I != 0; I++)
-	    {
-	       pkgCache::VerIterator V(*Cache,*I);
-	       if (V != Cache->VerP + V.ParentPkg()->VersionList ||
-		   V->ParentPkg == D->Package)
-		  continue;
-	       cout << "    " << V.ParentPkg().FullName(true) << endl;
-
-		if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
-		{
-		  Shown[V.ParentPkg()->ID] = true;
-		  verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
-		}
-	    }
-
-	    if (ShowOnlyFirstOr == true)
-	       while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
-	 }
-   }
-
-   for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
-	Pkg != helper.virtualPkgs.end(); ++Pkg)
-      cout << '<' << Pkg.FullName(true) << '>' << endl;
-
-   return true;
-}
-									/*}}}*/
-// Depends - Print out a dependency tree				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool Depends(CommandLine &CmdL)
-{
-   return ShowDepends(CmdL, false);
-}
-									/*}}}*/
-// RDepends - Print out a reverse dependency tree			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool RDepends(CommandLine &CmdL)
-{
-   return ShowDepends(CmdL, true);
-}
-									/*}}}*/
 // xvcg - Generate a graph for xvcg					/*{{{*/
 // ---------------------------------------------------------------------
 // Code contributed from Junichi Uekawa <dancer@debian.org> on 20 June 2002.
@@ -1246,195 +1115,6 @@ static bool ShowPkgNames(CommandLine &CmdL)
       cout << I.Name() << endl;
    }
    
-   return true;
-}
-									/*}}}*/
-// ShowSrcPackage - Show source package records				/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowSrcPackage(CommandLine &CmdL)
-{
-   pkgCacheFile CacheFile;
-   pkgSourceList *List = CacheFile.GetSourceList();
-   if (unlikely(List == NULL))
-      return false;
-
-   // Create the text record parsers
-   pkgSrcRecords SrcRecs(*List);
-   if (_error->PendingError() == true)
-      return false;
-
-   unsigned found = 0;
-   for (const char **I = CmdL.FileList + 1; *I != 0; I++)
-   {
-      SrcRecs.Restart();
-      
-      pkgSrcRecords::Parser *Parse;
-      unsigned found_this = 0;
-      while ((Parse = SrcRecs.Find(*I,false)) != 0) {
-         // SrcRecs.Find() will find both binary and source names
-         if (_config->FindB("APT::Cache::Only-Source", false) == true)
-            if (Parse->Package() != *I)
-               continue;
-        cout << Parse->AsStr() << endl;;
-        found++;
-        found_this++;
-      }
-      if (found_this == 0) {
-        _error->Warning(_("Unable to locate package %s"),*I);
-        continue;
-      }
-   }
-   if (found == 0)
-      _error->Notice(_("No packages found"));
-   return true;
-}
-									/*}}}*/
-// Policy - Show the results of the preferences file			/*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool Policy(CommandLine &CmdL)
-{
-   pkgCacheFile CacheFile;
-   pkgCache *Cache = CacheFile.GetPkgCache();
-   pkgPolicy *Plcy = CacheFile.GetPolicy();
-   pkgSourceList *SrcList = CacheFile.GetSourceList();
-   if (unlikely(Cache == NULL || Plcy == NULL || SrcList == NULL))
-      return false;
-
-   /* Should the MultiArchKiller be run to see which pseudo packages for an
-      arch all package are currently installed? Activating it gives a speed
-      penality for no real gain beside enhanced debugging, so in general no. */
-   if (_config->FindB("APT::Cache::Policy::DepCache", false) == true)
-      CacheFile.GetDepCache();
-
-   // Print out all of the package files
-   if (CmdL.FileList[1] == 0)
-   {
-      cout << _("Package files:") << endl;   
-      for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F.end() == false; ++F)
-      {
-	 if (F.Flagged(pkgCache::Flag::NoPackages))
-	    continue;
-	 // Locate the associated index files so we can derive a description
-	 pkgIndexFile *Indx;
-	 if (SrcList->FindIndex(F,Indx) == false &&
-	     _system->FindIndex(F,Indx) == false)
-	    return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
-	 
-	 printf("%4i %s\n",
-		Plcy->GetPriority(F),Indx->Describe(true).c_str());
-	 
-	 // Print the reference information for the package
-	 string Str = F.RelStr();
-	 if (Str.empty() == false)
-	    printf("     release %s\n",F.RelStr().c_str());
-	 if (F.Site() != 0 && F.Site()[0] != 0)
-	    printf("     origin %s\n",F.Site());
-      }
-      
-      // Show any packages have explicit pins
-      cout << _("Pinned packages:") << endl;
-      pkgCache::PkgIterator I = Cache->PkgBegin();
-      for (;I.end() != true; ++I)
-      {
-	 // Old code for debugging
-	 if (_config->FindI("APT::Policy", 1) < 1) {
-	    if (Plcy->GetPriority(I) == 0)
-	       continue;
-
-	    // Print the package name and the version we are forcing to
-	    cout << "     " << I.FullName(true) << " -> ";
-
-	    pkgCache::VerIterator V = Plcy->GetMatch(I);
-	    if (V.end() == true)
-	       cout << _("(not found)") << endl;
-	    else
-	       cout << V.VerStr() << endl;
-
-	    continue;
-	 }
-	 // New code
-	 for (pkgCache::VerIterator V = I.VersionList(); !V.end(); V++) {
-	    auto Prio = Plcy->GetPriority(V, false);
-	    if (Prio == 0)
-	       continue;
-
-	    cout << "     ";
-	    // Print the package name and the version we are forcing to
-	    ioprintf(cout, _("%s -> %s with priority %d\n"), I.FullName(true).c_str(), V.VerStr(), Prio);
-	 }
-      }
-      return true;
-   }
-
-   char const * const msgInstalled = _("  Installed: ");
-   char const * const msgCandidate = _("  Candidate: ");
-   short const InstalledLessCandidate =
-		mbstowcs(NULL, msgInstalled, 0) - mbstowcs(NULL, msgCandidate, 0);
-   short const deepInstalled =
-		(InstalledLessCandidate < 0 ? (InstalledLessCandidate*-1) : 0) - 1;
-   short const deepCandidate =
-		(InstalledLessCandidate > 0 ? (InstalledLessCandidate) : 0) - 1;
-
-   // Print out detailed information for each package
-   APT::CacheSetHelper helper(true, GlobalError::NOTICE);
-   APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1, helper);
-   for (APT::PackageList::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
-   {
-      cout << Pkg.FullName(true) << ":" << endl;
-
-      // Installed version
-      cout << msgInstalled << OutputInDepth(deepInstalled, " ");
-      if (Pkg->CurrentVer == 0)
-	 cout << _("(none)") << endl;
-      else
-	 cout << Pkg.CurrentVer().VerStr() << endl;
-      
-      // Candidate Version 
-      cout << msgCandidate << OutputInDepth(deepCandidate, " ");
-      pkgCache::VerIterator V = Plcy->GetCandidateVer(Pkg);
-      if (V.end() == true)
-	 cout << _("(none)") << endl;
-      else
-	 cout << V.VerStr() << endl;
-
-      // Pinned version
-      if (_config->FindI("APT::Policy", 1) < 1 && Plcy->GetPriority(Pkg) != 0)
-      {
-	 cout << _("  Package pin: ");
-	 V = Plcy->GetMatch(Pkg);
-	 if (V.end() == true)
-	    cout << _("(not found)") << endl;
-	 else
-	    cout << V.VerStr() << endl;
-      }
-      
-      // Show the priority tables
-      cout << _("  Version table:") << endl;
-      for (V = Pkg.VersionList(); V.end() == false; ++V)
-      {
-	 if (Pkg.CurrentVer() == V)
-	    cout << " *** " << V.VerStr();
-	 else
-	    cout << "     " << V.VerStr();
-	 if (_config->FindI("APT::Policy", 1) < 1)
-	    cout << " " << Plcy->GetPriority(Pkg) << endl;
-	 else
-	    cout << " " << Plcy->GetPriority(V) << endl;
-	 for (pkgCache::VerFileIterator VF = V.FileList(); VF.end() == false; ++VF)
-	 {
-	    // Locate the associated index files so we can derive a description
-	    pkgIndexFile *Indx;
-	    if (SrcList->FindIndex(VF.File(),Indx) == false &&
-		_system->FindIndex(VF.File(),Indx) == false)
-	       return _error->Error(_("Cache is out of sync, can't x-ref a package file"));
-	    printf("       %4i %s\n",Plcy->GetPriority(VF.File()),
-		   Indx->Describe(true).c_str());
-	 }
-      }
-   }
-   
    return true;
 }
 									/*}}}*/

File diff suppressed because it is too large
+ 1 - 1184
cmdline/apt-get.cc


+ 18 - 1
cmdline/apt.cc

@@ -29,6 +29,9 @@
 #include <apt-private/private-show.h>
 #include <apt-private/private-main.h>
 #include <apt-private/private-sources.h>
+#include <apt-private/private-source.h>
+#include <apt-private/private-depends.h>
+#include <apt-private/private-download.h>
 
 #include <unistd.h>
 #include <iostream>
@@ -67,11 +70,25 @@ std::vector<aptDispatchWithHelp> GetCommands()				/*{{{*/
       {"update", &DoUpdate, _("update list of available packages")},
       {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
       {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
-      {"dist-upgrade", &DoDistUpgrade, nullptr}, // for compat with muscle memory
 
       // misc
       {"edit-sources", &EditSources, _("edit the source information file")},
       {"moo", &DoMoo, nullptr},
+
+      // for compat with muscle memory
+      {"dist-upgrade", &DoDistUpgrade, nullptr},
+      {"showsrc",&ShowSrcPackage, nullptr},
+      {"depends",&Depends, nullptr},
+      {"rdepends",&RDepends, nullptr},
+      {"policy",&Policy, nullptr},
+      {"build-dep", &DoBuildDep,nullptr},
+      {"clean", &DoClean, nullptr},
+      {"autoclean", &DoAutoClean, nullptr},
+      {"auto-clean", &DoAutoClean, nullptr},
+      {"source", &DoSource, nullptr},
+      {"download", &DoDownload, nullptr},
+      {"changelog", &DoChangelog, nullptr},
+
       {nullptr, nullptr, nullptr}
    };
 }