summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/acqprogress.cc4
-rw-r--r--apt-private/private-cachefile.cc4
-rw-r--r--apt-private/private-cacheset.cc89
-rw-r--r--apt-private/private-cacheset.h37
-rw-r--r--apt-private/private-cmndline.cc9
-rw-r--r--apt-private/private-download.cc5
-rw-r--r--apt-private/private-download.h6
-rw-r--r--apt-private/private-install.cc168
-rw-r--r--apt-private/private-install.h160
-rw-r--r--apt-private/private-list.cc41
-rw-r--r--apt-private/private-output.cc377
-rw-r--r--apt-private/private-output.h7
-rw-r--r--apt-private/private-search.cc82
-rw-r--r--apt-private/private-show.cc8
-rw-r--r--apt-private/private-update.cc30
-rw-r--r--apt-private/private-upgrade.cc16
-rw-r--r--apt-private/private-utils.cc58
-rw-r--r--apt-private/private-utils.h4
18 files changed, 618 insertions, 487 deletions
diff --git a/apt-private/acqprogress.cc b/apt-private/acqprogress.cc
index 17a12799c..d6ce192ad 100644
--- a/apt-private/acqprogress.cc
+++ b/apt-private/acqprogress.cc
@@ -202,9 +202,9 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
S += strlen(S);
// Show the short mode string
- if (I->CurrentItem->Owner->Mode != 0)
+ if (I->CurrentItem->Owner->ActiveSubprocess.empty() == false)
{
- snprintf(S,End-S," %s",I->CurrentItem->Owner->Mode);
+ snprintf(S,End-S, " %s", I->CurrentItem->Owner->ActiveSubprocess.c_str());
S += strlen(S);
}
diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc
index 5e955ac39..29e665245 100644
--- a/apt-private/private-cachefile.cc
+++ b/apt-private/private-cachefile.cc
@@ -32,8 +32,10 @@ int CacheFile::NameComp(const void *a,const void *b)
const pkgCache::Package &A = **(pkgCache::Package **)a;
const pkgCache::Package &B = **(pkgCache::Package **)b;
+ const pkgCache::Group * const GA = SortCache->GrpP + A.Group;
+ const pkgCache::Group * const GB = SortCache->GrpP + B.Group;
- return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name);
+ return strcmp(SortCache->StrP + GA->Name,SortCache->StrP + GB->Name);
}
/*}}}*/
// CacheFile::Sort - Sort by name /*{{{*/
diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc
index e37e7b227..cb68024db 100644
--- a/apt-private/private-cacheset.cc
+++ b/apt-private/private-cacheset.cc
@@ -14,74 +14,77 @@
#include <apti18n.h>
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
- LocalitySortedVersionSet &output_set,
- OpProgress &progress)
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+ APT::VersionContainerInterface * const vci,
+ OpProgress * const progress)
{
Matcher null_matcher = Matcher();
- return GetLocalitySortedVersionSet(CacheFile, output_set,
+ return GetLocalitySortedVersionSet(CacheFile, vci,
null_matcher, progress);
}
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
- LocalitySortedVersionSet &output_set,
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+ APT::VersionContainerInterface * const vci,
Matcher &matcher,
- OpProgress &progress)
+ OpProgress * const progress)
{
pkgCache *Cache = CacheFile.GetPkgCache();
pkgDepCache *DepCache = CacheFile.GetDepCache();
+ APT::CacheSetHelper helper(false);
int Done=0;
- progress.SubProgress(Cache->Head().PackageCount, _("Sorting"));
+ if (progress != NULL)
+ progress->SubProgress(Cache->Head().PackageCount, _("Sorting"));
+
+ bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false);
+ bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false);
+ bool const insertManualInstalled = _config->FindB("APT::Cmd::Manual-Installed", false);
+
for (pkgCache::PkgIterator P = Cache->PkgBegin(); P.end() == false; ++P)
{
- if (Done%500 == 0)
- progress.Progress(Done);
- Done++;
+ if (progress != NULL)
+ {
+ if (Done % 500 == 0)
+ progress->Progress(Done);
+ ++Done;
+ }
+
+ // exclude virtual pkgs
+ if (P->VersionList == 0)
+ continue;
if ((matcher)(P) == false)
- continue;
+ continue;
- // exclude virtual pkgs
- if (P.VersionList() == 0)
- continue;
pkgDepCache::StateCache &state = (*DepCache)[P];
- if (_config->FindB("APT::Cmd::Installed") == true)
+ if (insertCurrentVer == true)
{
- if (P.CurrentVer() != NULL)
- {
- output_set.insert(P.CurrentVer());
- }
+ if (P->CurrentVer != 0)
+ vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::INSTALLED, helper);
}
- else if (_config->FindB("APT::Cmd::Upgradable") == true)
+ else if (insertUpgradable == true)
{
- if(P.CurrentVer() && state.Upgradable())
- {
- pkgPolicy *policy = CacheFile.GetPolicy();
- output_set.insert(policy->GetCandidateVer(P));
- }
+ if(P.CurrentVer() && state.Upgradable())
+ vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
}
- else if (_config->FindB("APT::Cmd::Manual-Installed") == true)
+ else if (insertManualInstalled == true)
{
- if (P.CurrentVer() &&
- ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
- {
- pkgPolicy *policy = CacheFile.GetPolicy();
- output_set.insert(policy->GetCandidateVer(P));
- }
+ if (P.CurrentVer() &&
+ ((*DepCache)[P].Flags & pkgCache::Flag::Auto) == false)
+ vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper);
}
- else
+ else
{
- pkgPolicy *policy = CacheFile.GetPolicy();
- if (policy->GetCandidateVer(P).IsGood())
- output_set.insert(policy->GetCandidateVer(P));
- else
- // no candidate, this may happen for packages in
- // dpkg "deinstall ok config-file" state - we pick the first ver
- // (which should be the only one)
- output_set.insert(P.VersionList());
+ if (vci->FromPackage(vci, CacheFile, P, APT::CacheSetHelper::CANDIDATE, helper) == false)
+ {
+ // no candidate, this may happen for packages in
+ // dpkg "deinstall ok config-file" state - we pick the first ver
+ // (which should be the only one)
+ vci->insert(P.VersionList());
+ }
}
}
- progress.Done();
+ if (progress != NULL)
+ progress->Done();
return true;
}
diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h
index 854d16922..059c7637e 100644
--- a/apt-private/private-cacheset.h
+++ b/apt-private/private-cacheset.h
@@ -62,13 +62,13 @@ public:
};
// FIXME: add default argument for OpProgress (or overloaded function)
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
- LocalitySortedVersionSet &output_set,
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+ APT::VersionContainerInterface * const vci,
Matcher &matcher,
- OpProgress &progress);
-bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
- LocalitySortedVersionSet &output_set,
- OpProgress &progress);
+ OpProgress * const progress);
+bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
+ APT::VersionContainerInterface * const vci,
+ OpProgress * const progress);
// CacheSetHelper saving virtual packages /*{{{*/
@@ -76,19 +76,16 @@ class CacheSetHelperVirtuals: public APT::CacheSetHelper {
public:
APT::PackageSet virtualPkgs;
- virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
- virtualPkgs.insert(Pkg);
- return CacheSetHelper::canNotFindCandidateVer(Cache, Pkg);
+ virtual pkgCache::VerIterator canNotGetVersion(enum CacheSetHelper::VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+ if (select == NEWEST || select == CANDIDATE || select == ALL)
+ virtualPkgs.insert(Pkg);
+ return CacheSetHelper::canNotGetVersion(select, Cache, Pkg);
}
- virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
- virtualPkgs.insert(Pkg);
- return CacheSetHelper::canNotFindNewestVer(Cache, Pkg);
- }
-
- virtual void canNotFindAllVer(APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
- virtualPkgs.insert(Pkg);
- CacheSetHelper::canNotFindAllVer(vci, Cache, Pkg);
+ virtual void canNotFindVersion(enum CacheSetHelper::VerSelector const select, APT::VersionContainerInterface * vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+ if (select == NEWEST || select == CANDIDATE || select == ALL)
+ virtualPkgs.insert(Pkg);
+ return CacheSetHelper::canNotFindVersion(select, vci, Cache, Pkg);
}
CacheSetHelperVirtuals(bool const ShowErrors = true, GlobalError::MsgType const &ErrorType = GlobalError::NOTICE) : CacheSetHelper(ShowErrors, ErrorType) {}
@@ -190,7 +187,7 @@ public:
}
virtual pkgCache::VerIterator canNotFindCandidateVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
- APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE);
+ APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::CANDIDATE);
if (verset.empty() == false)
return *(verset.begin());
else if (ShowError == true) {
@@ -203,7 +200,7 @@ public:
virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
if (Pkg->ProvidesList != 0)
{
- APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST);
+ APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, CacheSetHelper::NEWEST);
if (verset.empty() == false)
return *(verset.begin());
if (ShowError == true)
@@ -231,7 +228,7 @@ public:
}
APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg,
- APT::VersionSet::Version const &select) {
+ CacheSetHelper::VerSelector const select) {
/* This is a pure virtual package and there is a single available
candidate providing it. */
if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0)
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index a21a9dc8c..a4490f5b4 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -70,6 +70,8 @@ static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char cons
else
return false;
+ bool const found_something = Args.empty() == false;
+
// FIXME: move to the correct command(s)
addArg('g', "generate", "APT::Cache::Generate", 0);
addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg);
@@ -77,7 +79,8 @@ static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char cons
addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg);
addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg);
- return true;
+
+ return found_something;
}
/*}}}*/
static bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
@@ -172,6 +175,8 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const
addArg('s', "no-act", "APT::Get::Simulate", 0);
}
+ bool const found_something = Args.empty() == false;
+
// FIXME: move to the correct command(s)
addArg('d',"download-only","APT::Get::Download-Only",0);
addArg('y',"yes","APT::Get::Assume-Yes",0);
@@ -197,7 +202,7 @@ static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const
addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean);
addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
- return true;
+ return found_something;
}
/*}}}*/
static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
diff --git a/apt-private/private-download.cc b/apt-private/private-download.cc
index a095f0c67..be7d23c31 100644
--- a/apt-private/private-download.cc
+++ b/apt-private/private-download.cc
@@ -28,6 +28,11 @@ bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser)
if (UntrustedList == "")
return true;
+ return AuthPrompt(UntrustedList, PromptUser);
+}
+
+bool AuthPrompt(std::string UntrustedList, bool const PromptUser)
+{
ShowList(c2out,_("WARNING: The following packages cannot be authenticated!"),UntrustedList,"");
if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
diff --git a/apt-private/private-download.h b/apt-private/private-download.h
index a108aa531..a90ac7eaa 100644
--- a/apt-private/private-download.h
+++ b/apt-private/private-download.h
@@ -5,7 +5,13 @@
class pkgAcquire;
+// Check if all files in the fetcher are authenticated
APT_PUBLIC bool CheckAuth(pkgAcquire& Fetcher, bool const PromptUser);
+
+// show a authentication warning prompt and return true if the system
+// should continue
+APT_PUBLIC bool AuthPrompt(std::string UntrustedList, bool const PromptUser);
+
APT_PUBLIC bool AcquireRun(pkgAcquire &Fetcher, int const PulseInterval, bool * const Failure, bool * const TransientNetworkFailure);
#endif
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index d9e485462..86ba52857 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -19,7 +19,7 @@
#include <apt-pkg/macros.h>
#include <apt-pkg/packagemanager.h>
#include <apt-pkg/pkgcache.h>
-#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/upgrade.h>
#include <apt-pkg/install-progress.h>
#include <errno.h>
@@ -527,15 +527,14 @@ static bool DoAutomaticRemove(CacheFile &Cache)
static const unsigned short MOD_REMOVE = 1;
static const unsigned short MOD_INSTALL = 2;
-bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache)
+bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode)
{
std::map<unsigned short, APT::VersionSet> verset;
- return DoCacheManipulationFromCommandLine(CmdL, Cache, verset);
+ return DoCacheManipulationFromCommandLine(CmdL, Cache, verset, UpgradeMode);
}
bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
- std::map<unsigned short, APT::VersionSet> &verset)
+ std::map<unsigned short, APT::VersionSet> &verset, int UpgradeMode)
{
-
// Enter the special broken fixing mode if the user specified arguments
bool BrokenFix = false;
if (Cache->BrokenCount() != 0)
@@ -561,9 +560,9 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
std::list<APT::VersionSet::Modifier> mods;
mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
- APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDIDATE));
+ APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::CANDIDATE));
mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
- APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::NEWEST));
+ APT::VersionSet::Modifier::POSTFIX, APT::CacheSetHelper::NEWEST));
CacheSetHelperAPTGet helper(c0out);
verset = APT::VersionSet::GroupedFromCommandLine(Cache,
CmdL.FileList + 1, mods, fallback, helper);
@@ -620,7 +619,17 @@ bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
if (Fix != NULL)
{
// Call the scored problem resolver
- Fix->Resolve(true);
+ OpTextProgress Progress(*_config);
+ bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0;
+
+ bool resolver_fail = false;
+ if (distUpgradeMode == true || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING)
+ resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress);
+ else
+ resolver_fail = Fix->Resolve(true, &Progress);
+
+ if (resolver_fail == false && Cache->BrokenCount() == 0)
+ return false;
}
// Now we check the state of the packages,
@@ -702,7 +711,7 @@ bool DoInstall(CommandLine &CmdL)
std::map<unsigned short, APT::VersionSet> verset;
- if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset))
+ if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset, 0))
return false;
/* Print out a list of packages that are going to be installed extra
@@ -828,3 +837,144 @@ bool DoInstall(CommandLine &CmdL)
return InstallPackages(Cache,false);
}
/*}}}*/
+
+// TryToInstall - Mark a package for installation /*{{{*/
+void TryToInstall::operator() (pkgCache::VerIterator const &Ver) {
+ pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+
+ Cache->GetDepCache()->SetCandidateVersion(Ver);
+ pkgDepCache::StateCache &State = (*Cache)[Pkg];
+
+ // Handle the no-upgrade case
+ if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
+ ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
+ Pkg.FullName(true).c_str());
+ // Ignore request for install if package would be new
+ else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
+ ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
+ Pkg.FullName(true).c_str());
+ else {
+ if (Fix != NULL) {
+ Fix->Clear(Pkg);
+ Fix->Protect(Pkg);
+ }
+ Cache->GetDepCache()->MarkInstall(Pkg,false);
+
+ if (State.Install() == false) {
+ if (_config->FindB("APT::Get::ReInstall",false) == true) {
+ if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
+ ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
+ Pkg.FullName(true).c_str());
+ else
+ Cache->GetDepCache()->SetReInstall(Pkg, true);
+ } else
+ ioprintf(c1out,_("%s is already the newest version.\n"),
+ Pkg.FullName(true).c_str());
+ }
+
+ // Install it with autoinstalling enabled (if we not respect the minial
+ // required deps or the policy)
+ if (FixBroken == false)
+ doAutoInstallLater.insert(Pkg);
+ }
+
+ // see if we need to fix the auto-mark flag
+ // e.g. apt-get install foo
+ // where foo is marked automatic
+ if (State.Install() == false &&
+ (State.Flags & pkgCache::Flag::Auto) &&
+ _config->FindB("APT::Get::ReInstall",false) == false &&
+ _config->FindB("APT::Get::Only-Upgrade",false) == false &&
+ _config->FindB("APT::Get::Download-Only",false) == false)
+ {
+ ioprintf(c1out,_("%s set to manually installed.\n"),
+ Pkg.FullName(true).c_str());
+ Cache->GetDepCache()->MarkAuto(Pkg,false);
+ AutoMarkChanged++;
+ }
+}
+ /*}}}*/
+bool TryToInstall::propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > const &start, std::ostream &out)/*{{{*/
+{
+ for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
+ s != start.end(); ++s)
+ Cache->GetDepCache()->SetCandidateVersion(s->first);
+
+ bool Success = true;
+ // the Changed list contains:
+ // first: "new version"
+ // second: "what-caused the change"
+ std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
+ for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
+ s != start.end(); ++s)
+ {
+ Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
+ // We continue here even if it failed to enhance the ShowBroken output
+ Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
+ }
+ for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
+ c != Changed.end(); ++c)
+ {
+ if (c->second.end() == true)
+ ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
+ c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
+ else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
+ {
+ pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
+ ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
+ V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
+ }
+ }
+ return Success;
+}
+ /*}}}*/
+void TryToInstall::doAutoInstall() { /*{{{*/
+ for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
+ P != doAutoInstallLater.end(); ++P) {
+ pkgDepCache::StateCache &State = (*Cache)[P];
+ if (State.InstBroken() == false && State.InstPolicyBroken() == false)
+ continue;
+ Cache->GetDepCache()->MarkInstall(P, true);
+ }
+ doAutoInstallLater.clear();
+}
+ /*}}}*/
+// TryToRemove - Mark a package for removal /*{{{*/
+void TryToRemove::operator() (pkgCache::VerIterator const &Ver)
+{
+ pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+
+ if (Fix != NULL)
+ {
+ Fix->Clear(Pkg);
+ Fix->Protect(Pkg);
+ Fix->Remove(Pkg);
+ }
+
+ if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
+ (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
+ {
+ pkgCache::GrpIterator Grp = Pkg.Group();
+ pkgCache::PkgIterator P = Grp.PackageList();
+ for (; P.end() != true; P = Grp.NextPkg(P))
+ {
+ if (P == Pkg)
+ continue;
+ if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
+ {
+ // TRANSLATORS: Note, this is not an interactive question
+ ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
+ Pkg.FullName(true).c_str(), P.FullName(true).c_str());
+ break;
+ }
+ }
+ if (P.end() == true)
+ ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
+
+ // MarkInstall refuses to install packages on hold
+ Pkg->SelectedState = pkgCache::State::Hold;
+ }
+ else
+ Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
+}
+ /*}}}*/
diff --git a/apt-private/private-install.h b/apt-private/private-install.h
index 5e18560c5..8daa4a776 100644
--- a/apt-private/private-install.h
+++ b/apt-private/private-install.h
@@ -3,43 +3,33 @@
#include <apt-pkg/cachefile.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/depcache.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
#include <apt-pkg/cacheset.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/algorithms.h>
#include <apt-pkg/macros.h>
-#include <apt-private/private-output.h>
-
-#include <stddef.h>
-#include <iosfwd>
#include <list>
-#include <map>
#include <string>
#include <utility>
-
-#include <apti18n.h>
-
class CacheFile;
class CommandLine;
+class pkgProblemResolver;
#define RAMFS_MAGIC 0x858458f6
APT_PUBLIC bool DoInstall(CommandLine &Cmd);
bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache,
- std::map<unsigned short, APT::VersionSet> &verset);
-bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache);
+ std::map<unsigned short, APT::VersionSet> &verset, int UpgradeMode);
+bool DoCacheManipulationFromCommandLine(CommandLine &CmdL, CacheFile &Cache, int UpgradeMode);
APT_PUBLIC bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
bool Safety = true);
// TryToInstall - Mark a package for installation /*{{{*/
-struct TryToInstall {
+struct APT_PUBLIC TryToInstall {
pkgCacheFile* Cache;
pkgProblemResolver* Fix;
bool FixBroken;
@@ -49,109 +39,13 @@ struct TryToInstall {
TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM),
FixBroken(FixBroken), AutoMarkChanged(0) {};
- void operator() (pkgCache::VerIterator const &Ver) {
- pkgCache::PkgIterator Pkg = Ver.ParentPkg();
-
- Cache->GetDepCache()->SetCandidateVersion(Ver);
- pkgDepCache::StateCache &State = (*Cache)[Pkg];
-
- // Handle the no-upgrade case
- if (_config->FindB("APT::Get::upgrade",true) == false && Pkg->CurrentVer != 0)
- ioprintf(c1out,_("Skipping %s, it is already installed and upgrade is not set.\n"),
- Pkg.FullName(true).c_str());
- // Ignore request for install if package would be new
- else if (_config->FindB("APT::Get::Only-Upgrade", false) == true && Pkg->CurrentVer == 0)
- ioprintf(c1out,_("Skipping %s, it is not installed and only upgrades are requested.\n"),
- Pkg.FullName(true).c_str());
- else {
- if (Fix != NULL) {
- Fix->Clear(Pkg);
- Fix->Protect(Pkg);
- }
- Cache->GetDepCache()->MarkInstall(Pkg,false);
-
- if (State.Install() == false) {
- if (_config->FindB("APT::Get::ReInstall",false) == true) {
- if (Pkg->CurrentVer == 0 || Pkg.CurrentVer().Downloadable() == false)
- ioprintf(c1out,_("Reinstallation of %s is not possible, it cannot be downloaded.\n"),
- Pkg.FullName(true).c_str());
- else
- Cache->GetDepCache()->SetReInstall(Pkg, true);
- } else
- ioprintf(c1out,_("%s is already the newest version.\n"),
- Pkg.FullName(true).c_str());
- }
-
- // Install it with autoinstalling enabled (if we not respect the minial
- // required deps or the policy)
- if (FixBroken == false)
- doAutoInstallLater.insert(Pkg);
- }
-
- // see if we need to fix the auto-mark flag
- // e.g. apt-get install foo
- // where foo is marked automatic
- if (State.Install() == false &&
- (State.Flags & pkgCache::Flag::Auto) &&
- _config->FindB("APT::Get::ReInstall",false) == false &&
- _config->FindB("APT::Get::Only-Upgrade",false) == false &&
- _config->FindB("APT::Get::Download-Only",false) == false)
- {
- ioprintf(c1out,_("%s set to manually installed.\n"),
- Pkg.FullName(true).c_str());
- Cache->GetDepCache()->MarkAuto(Pkg,false);
- AutoMarkChanged++;
- }
- }
-
- bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > start, std::ostream &out)
- {
- for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
- s != start.end(); ++s)
- Cache->GetDepCache()->SetCandidateVersion(s->first);
-
- bool Success = true;
- // the Changed list contains:
- // first: "new version"
- // second: "what-caused the change"
- std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
- for (std::list<std::pair<pkgCache::VerIterator, std::string> >::const_iterator s = start.begin();
- s != start.end(); ++s)
- {
- Changed.push_back(std::make_pair(s->first, pkgCache::VerIterator(*Cache)));
- // We continue here even if it failed to enhance the ShowBroken output
- Success &= Cache->GetDepCache()->SetCandidateRelease(s->first, s->second, Changed);
- }
- for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
- c != Changed.end(); ++c)
- {
- if (c->second.end() == true)
- ioprintf(out, _("Selected version '%s' (%s) for '%s'\n"),
- c->first.VerStr(), c->first.RelStr().c_str(), c->first.ParentPkg().FullName(true).c_str());
- else if (c->first.ParentPkg()->Group != c->second.ParentPkg()->Group)
- {
- pkgCache::VerIterator V = (*Cache)[c->first.ParentPkg()].CandidateVerIter(*Cache);
- ioprintf(out, _("Selected version '%s' (%s) for '%s' because of '%s'\n"), V.VerStr(),
- V.RelStr().c_str(), V.ParentPkg().FullName(true).c_str(), c->second.ParentPkg().FullName(true).c_str());
- }
- }
- return Success;
- }
-
- void doAutoInstall() {
- for (APT::PackageSet::const_iterator P = doAutoInstallLater.begin();
- P != doAutoInstallLater.end(); ++P) {
- pkgDepCache::StateCache &State = (*Cache)[P];
- if (State.InstBroken() == false && State.InstPolicyBroken() == false)
- continue;
- Cache->GetDepCache()->MarkInstall(P, true);
- }
- doAutoInstallLater.clear();
- }
+ void operator() (pkgCache::VerIterator const &Ver);
+ bool propergateReleaseCandiateSwitching(std::list<std::pair<pkgCache::VerIterator, std::string> > const &start, std::ostream &out);
+ void doAutoInstall();
};
/*}}}*/
// TryToRemove - Mark a package for removal /*{{{*/
-struct TryToRemove {
+struct APT_PUBLIC TryToRemove {
pkgCacheFile* Cache;
pkgProblemResolver* Fix;
bool PurgePkgs;
@@ -159,43 +53,7 @@ struct TryToRemove {
TryToRemove(pkgCacheFile &Cache, pkgProblemResolver *PM) : Cache(&Cache), Fix(PM),
PurgePkgs(_config->FindB("APT::Get::Purge", false)) {};
- void operator() (pkgCache::VerIterator const &Ver)
- {
- pkgCache::PkgIterator Pkg = Ver.ParentPkg();
-
- if (Fix != NULL)
- {
- Fix->Clear(Pkg);
- Fix->Protect(Pkg);
- Fix->Remove(Pkg);
- }
-
- if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
- (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
- {
- pkgCache::GrpIterator Grp = Pkg.Group();
- pkgCache::PkgIterator P = Grp.PackageList();
- for (; P.end() != true; P = Grp.NextPkg(P))
- {
- if (P == Pkg)
- continue;
- if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
- {
- // TRANSLATORS: Note, this is not an interactive question
- ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
- Pkg.FullName(true).c_str(), P.FullName(true).c_str());
- break;
- }
- }
- if (P.end() == true)
- ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
-
- // MarkInstall refuses to install packages on hold
- Pkg->SelectedState = pkgCache::State::Hold;
- }
- else
- Cache->GetDepCache()->MarkDelete(Pkg, PurgePkgs);
- }
+ void operator() (pkgCache::VerIterator const &Ver);
};
/*}}}*/
diff --git a/apt-private/private-list.cc b/apt-private/private-list.cc
index e85aaf64c..aa3a2c24b 100644
--- a/apt-private/private-list.cc
+++ b/apt-private/private-list.cc
@@ -77,15 +77,14 @@ private:
};
/*}}}*/
static void ListAllVersions(pkgCacheFile &CacheFile, pkgRecords &records,/*{{{*/
- pkgCache::PkgIterator P,
- std::ostream &outs,
- bool include_summary=true)
+ pkgCache::PkgIterator const &P, std::ostream &outs,
+ std::string const &format)
{
for (pkgCache::VerIterator Ver = P.VersionList();
Ver.end() == false; ++Ver)
{
- ListSingleVersion(CacheFile, records, Ver, outs, include_summary);
- outs << "\n";
+ ListSingleVersion(CacheFile, records, Ver, outs, format);
+ outs << std::endl;
}
}
/*}}}*/
@@ -109,10 +108,9 @@ bool DoList(CommandLine &Cmd)
patterns = Cmd.FileList + 1;
}
- std::map<std::string, std::string> output_map;
- std::map<std::string, std::string>::const_iterator K;
-
- bool includeSummary = _config->FindB("APT::Cmd::List-Include-Summary");
+ std::string format = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture}${ }${apt:Status}";
+ if (_config->FindB("APT::Cmd::List-Include-Summary", false) == true)
+ format += "\n ${Description}\n";
PackageNameMatcher matcher(patterns);
LocalitySortedVersionSet bag;
@@ -121,37 +119,34 @@ bool DoList(CommandLine &Cmd)
Cache->Head().PackageCount,
Cache->Head().PackageCount,
_("Listing"));
- GetLocalitySortedVersionSet(CacheFile, bag, matcher, progress);
- bool ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false);
+ GetLocalitySortedVersionSet(CacheFile, &bag, matcher, &progress);
+ bool const ShowAllVersions = _config->FindB("APT::Cmd::All-Versions", false);
+ std::map<std::string, std::string> output_map;
for (LocalitySortedVersionSet::iterator V = bag.begin(); V != bag.end(); ++V)
{
std::stringstream outs;
if(ShowAllVersions == true)
- {
- ListAllVersions(CacheFile, records, V.ParentPkg(), outs, includeSummary);
- output_map.insert(std::make_pair<std::string, std::string>(
- V.ParentPkg().Name(), outs.str()));
- } else {
- ListSingleVersion(CacheFile, records, V, outs, includeSummary);
- output_map.insert(std::make_pair<std::string, std::string>(
- V.ParentPkg().Name(), outs.str()));
- }
+ ListAllVersions(CacheFile, records, V.ParentPkg(), outs, format);
+ else
+ ListSingleVersion(CacheFile, records, V, outs, format);
+ output_map.insert(std::make_pair<std::string, std::string>(
+ V.ParentPkg().Name(), outs.str()));
}
// FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
// output the sorted map
+ std::map<std::string, std::string>::const_iterator K;
for (K = output_map.begin(); K != output_map.end(); ++K)
std::cout << (*K).second << std::endl;
-
// be nice and tell the user if there is more to see
if (bag.size() == 1 && ShowAllVersions == false)
{
// start with -1 as we already displayed one version
int versions = -1;
pkgCache::VerIterator Ver = *bag.begin();
- for ( ; Ver.end() == false; Ver++)
- versions++;
+ for ( ; Ver.end() == false; ++Ver)
+ ++versions;
if (versions > 0)
_error->Notice(P_("There is %i additional version. Please use the '-a' switch to see it", "There are %i additional versions. Please use the '-a' switch to see them.", versions), versions);
}
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc
index 32f27a3dd..fc76a05bc 100644
--- a/apt-private/private-output.cc
+++ b/apt-private/private-output.cc
@@ -94,7 +94,7 @@ bool InitOutput() /*{{{*/
static std::string GetArchiveSuite(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator ver) /*{{{*/
{
std::string suite = "";
- if (ver && ver.FileList() && ver.FileList())
+ if (ver && ver.FileList())
{
pkgCache::VerFileIterator VF = ver.FileList();
for (; VF.end() == false ; ++VF)
@@ -118,7 +118,7 @@ static std::string GetFlagsStr(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)
std::string flags_str;
if (state.NowBroken())
flags_str = "B";
- if (P.CurrentVer() && state.Upgradable())
+ if (P.CurrentVer() && state.Upgradable() && state.CandidateVer != NULL)
flags_str = "g";
else if (P.CurrentVer() != NULL)
flags_str = "i";
@@ -164,15 +164,26 @@ static std::string GetVersion(pkgCacheFile &/*CacheFile*/, pkgCache::VerIterator
/*}}}*/
static std::string GetArchitecture(pkgCacheFile &CacheFile, pkgCache::PkgIterator P)/*{{{*/
{
- pkgPolicy *policy = CacheFile.GetPolicy();
- pkgCache::VerIterator inst = P.CurrentVer();
- pkgCache::VerIterator cand = policy->GetCandidateVer(P);
-
- // this may happen for packages in dpkg "deinstall ok config-file" state
- if (inst.IsGood() == false && cand.IsGood() == false)
- return P.VersionList().Arch();
-
- return inst ? inst.Arch() : cand.Arch();
+ if (P->CurrentVer == 0)
+ {
+ pkgDepCache * const DepCache = CacheFile.GetDepCache();
+ pkgDepCache::StateCache const &state = (*DepCache)[P];
+ if (state.CandidateVer != NULL)
+ {
+ pkgCache::VerIterator const CandV(CacheFile, state.CandidateVer);
+ return CandV.Arch();
+ }
+ else
+ {
+ pkgCache::VerIterator const V = P.VersionList();
+ if (V.end() == false)
+ return V.Arch();
+ else
+ return P.Arch();
+ }
+ }
+ else
+ return P.CurrentVer().Arch();
}
/*}}}*/
static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/
@@ -196,80 +207,90 @@ static std::string GetShortDescription(pkgCacheFile &CacheFile, pkgRecords &reco
return ShortDescription;
}
/*}}}*/
-void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/
- pkgCache::VerIterator V, std::ostream &out,
- bool include_summary)
+static std::string GetLongDescription(pkgCacheFile &CacheFile, pkgRecords &records, pkgCache::PkgIterator P)/*{{{*/
{
- pkgCache::PkgIterator P = V.ParentPkg();
+ pkgPolicy *policy = CacheFile.GetPolicy();
- pkgDepCache *DepCache = CacheFile.GetDepCache();
- pkgDepCache::StateCache &state = (*DepCache)[P];
+ pkgCache::VerIterator ver;
+ if (P->CurrentVer != 0)
+ ver = P.CurrentVer();
+ else
+ ver = policy->GetCandidateVer(P);
- std::string suite = GetArchiveSuite(CacheFile, V);
- std::string name_str = P.Name();
+ std::string const EmptyDescription = "(none)";
+ if(ver.end() == true)
+ return EmptyDescription;
+
+ pkgCache::DescIterator const Desc = ver.TranslatedDescription();
+ pkgRecords::Parser & parser = records.Lookup(Desc.FileList());
+ std::string const longdesc = parser.LongDesc();
+ if (longdesc.empty() == true)
+ return EmptyDescription;
+ return SubstVar(longdesc, "\n ", "\n ");
+}
+ /*}}}*/
+void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/
+ pkgCache::VerIterator const &V, std::ostream &out,
+ std::string const &format)
+{
+ pkgCache::PkgIterator const P = V.ParentPkg();
+ pkgDepCache * const DepCache = CacheFile.GetDepCache();
+ pkgDepCache::StateCache const &state = (*DepCache)[P];
+ std::string output;
if (_config->FindB("APT::Cmd::use-format", false))
+ output = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}");
+ else
+ output = format;
+
+ // FIXME: some of these names are really icky – and all is nowhere documented
+ output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P));
+ output = SubstVar(output, "${Package}", P.Name());
+ std::string const ArchStr = GetArchitecture(CacheFile, P);
+ output = SubstVar(output, "${Architecture}", ArchStr);
+ std::string const InstalledVerStr = GetInstalledVersion(CacheFile, P);
+ output = SubstVar(output, "${installed:Version}", InstalledVerStr);
+ std::string const CandidateVerStr = GetCandidateVersion(CacheFile, P);
+ output = SubstVar(output, "${candidate:Version}", CandidateVerStr);
+ std::string const VersionStr = GetVersion(CacheFile, V);
+ output = SubstVar(output, "${Version}", VersionStr);
+ output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V));
+
+ std::string StatusStr = "";
+ if (P->CurrentVer != 0)
{
- std::string format = _config->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}");
- std::string output = format;
-
- output = SubstVar(output, "${db::Status-Abbrev}", GetFlagsStr(CacheFile, P));
- output = SubstVar(output, "${Package}", name_str);
- output = SubstVar(output, "${installed:Version}", GetInstalledVersion(CacheFile, P));
- output = SubstVar(output, "${candidate:Version}", GetCandidateVersion(CacheFile, P));
- output = SubstVar(output, "${Version}", GetVersion(CacheFile, V));
- output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P));
- output = SubstVar(output, "${Origin}", GetArchiveSuite(CacheFile, V));
- out << output << std::endl;
- } else {
- // raring/linux-kernel version [upradable: new-version]
- // description
- pkgPolicy *policy = CacheFile.GetPolicy();
- std::string VersionStr = GetVersion(CacheFile, V);
- std::string CandidateVerStr = GetCandidateVersion(CacheFile, P);
- std::string InstalledVerStr = GetInstalledVersion(CacheFile, P);
- std::string StatusStr;
- if(P.CurrentVer() == V && state.Upgradable()) {
- strprintf(StatusStr, _("[installed,upgradable to: %s]"),
- CandidateVerStr.c_str());
- } else if (P.CurrentVer() == V) {
- if(!V.Downloadable())
- StatusStr = _("[installed,local]");
- else
- if(V.Automatic() && state.Garbage)
- StatusStr = _("[installed,auto-removable]");
- else if (state.Flags & pkgCache::Flag::Auto)
- StatusStr = _("[installed,automatic]");
- else
- StatusStr = _("[installed]");
- } else if (P.CurrentVer() &&
- policy->GetCandidateVer(P) == V &&
- state.Upgradable()) {
- strprintf(StatusStr, _("[upgradable from: %s]"),
- InstalledVerStr.c_str());
- } else {
- if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles)
- StatusStr = _("[residual-config]");
- else
- StatusStr = "";
- }
- out << std::setiosflags(std::ios::left)
- << _config->Find("APT::Color::Highlight", "")
- << name_str
- << _config->Find("APT::Color::Neutral", "")
- << "/" << suite
- << " "
- << VersionStr << " "
- << GetArchitecture(CacheFile, P);
- if (StatusStr != "")
- out << " " << StatusStr;
- if (include_summary)
+ if (P.CurrentVer() == V)
{
- out << std::endl
- << " " << GetShortDescription(CacheFile, records, P)
- << std::endl;
+ if (state.Upgradable() && state.CandidateVer != NULL)
+ strprintf(StatusStr, _("[installed,upgradable to: %s]"),
+ CandidateVerStr.c_str());
+ else if (V.Downloadable() == false)
+ StatusStr = _("[installed,local]");
+ else if(V.Automatic() == true && state.Garbage == true)
+ StatusStr = _("[installed,auto-removable]");
+ else if ((state.Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
+ StatusStr = _("[installed,automatic]");
+ else
+ StatusStr = _("[installed]");
}
+ else if (state.CandidateVer == V && state.Upgradable())
+ strprintf(StatusStr, _("[upgradable from: %s]"),
+ InstalledVerStr.c_str());
}
+ else if (V.ParentPkg()->CurrentState == pkgCache::State::ConfigFiles)
+ StatusStr = _("[residual-config]");
+ output = SubstVar(output, "${apt:Status}", StatusStr);
+ output = SubstVar(output, "${color:highlight}", _config->Find("APT::Color::Highlight", ""));
+ output = SubstVar(output, "${color:neutral}", _config->Find("APT::Color::Neutral", ""));
+ output = SubstVar(output, "${Description}", GetShortDescription(CacheFile, records, P));
+ output = SubstVar(output, "${LongDescription}", GetLongDescription(CacheFile, records, P));
+ output = SubstVar(output, "${ }${ }", "${ }");
+ output = SubstVar(output, "${ }\n", "\n");
+ output = SubstVar(output, "${ }", " ");
+ if (APT::String::Endswith(output, " ") == true)
+ output.erase(output.length() - 1);
+
+ out << output;
}
/*}}}*/
// ShowList - Show a list /*{{{*/
@@ -344,129 +365,141 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList)
Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
Depends: libsasl7 but it is not going to be installed
*/
-void ShowBroken(ostream &out,CacheFile &Cache,bool Now)
+static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now)
{
- if (Cache->BrokenCount() == 0)
+ if (Now == true)
+ {
+ if ((*Cache)[Pkg].NowBroken() == false)
+ return;
+ }
+ else
+ {
+ if ((*Cache)[Pkg].InstBroken() == false)
+ return;
+ }
+
+ // Print out each package and the failed dependencies
+ out << " " << Pkg.FullName(true) << " :";
+ unsigned const Indent = Pkg.FullName(true).size() + 3;
+ bool First = true;
+ pkgCache::VerIterator Ver;
+
+ if (Now == true)
+ Ver = Pkg.CurrentVer();
+ else
+ Ver = (*Cache)[Pkg].InstVerIter(*Cache);
+
+ if (Ver.end() == true)
+ {
+ out << endl;
return;
+ }
- out << _("The following packages have unmet dependencies:") << endl;
- for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
+ for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
{
- pkgCache::PkgIterator I(Cache,Cache.List[J]);
-
+ // Compute a single dependency element (glob or)
+ pkgCache::DepIterator Start;
+ pkgCache::DepIterator End;
+ D.GlobOr(Start,End); // advances D
+
+ if ((*Cache)->IsImportantDep(End) == false)
+ continue;
+
if (Now == true)
{
- if (Cache[I].NowBroken() == false)
+ if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
continue;
}
else
{
- if (Cache[I].InstBroken() == false)
+ if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
continue;
}
-
- // Print out each package and the failed dependencies
- out << " " << I.FullName(true) << " :";
- unsigned const Indent = I.FullName(true).size() + 3;
- bool First = true;
- pkgCache::VerIterator Ver;
-
- if (Now == true)
- Ver = I.CurrentVer();
- else
- Ver = Cache[I].InstVerIter(Cache);
-
- if (Ver.end() == true)
- {
- out << endl;
- continue;
- }
-
- for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;)
+
+ bool FirstOr = true;
+ while (1)
{
- // Compute a single dependency element (glob or)
- pkgCache::DepIterator Start;
- pkgCache::DepIterator End;
- D.GlobOr(Start,End); // advances D
+ if (First == false)
+ for (unsigned J = 0; J != Indent; J++)
+ out << ' ';
+ First = false;
- if (Cache->IsImportantDep(End) == false)
- continue;
-
- if (Now == true)
+ if (FirstOr == false)
{
- if ((Cache[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow)
- continue;
+ for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
+ out << ' ';
}
else
+ out << ' ' << End.DepType() << ": ";
+ FirstOr = false;
+
+ out << Start.TargetPkg().FullName(true);
+
+ // Show a quick summary of the version requirements
+ if (Start.TargetVer() != 0)
+ out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
+
+ /* Show a summary of the target package if possible. In the case
+ of virtual packages we show nothing */
+ pkgCache::PkgIterator Targ = Start.TargetPkg();
+ if (Targ->ProvidesList == 0)
{
- if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
- continue;
- }
-
- bool FirstOr = true;
- while (1)
- {
- if (First == false)
- for (unsigned J = 0; J != Indent; J++)
- out << ' ';
- First = false;
+ out << ' ';
+ pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache);
+ if (Now == true)
+ Ver = Targ.CurrentVer();
- if (FirstOr == false)
+ if (Ver.end() == false)
{
- for (unsigned J = 0; J != strlen(End.DepType()) + 3; J++)
- out << ' ';
+ if (Now == true)
+ ioprintf(out,_("but %s is installed"),Ver.VerStr());
+ else
+ ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
}
else
- out << ' ' << End.DepType() << ": ";
- FirstOr = false;
-
- out << Start.TargetPkg().FullName(true);
-
- // Show a quick summary of the version requirements
- if (Start.TargetVer() != 0)
- out << " (" << Start.CompType() << " " << Start.TargetVer() << ")";
-
- /* Show a summary of the target package if possible. In the case
- of virtual packages we show nothing */
- pkgCache::PkgIterator Targ = Start.TargetPkg();
- if (Targ->ProvidesList == 0)
{
- out << ' ';
- pkgCache::VerIterator Ver = Cache[Targ].InstVerIter(Cache);
- if (Now == true)
- Ver = Targ.CurrentVer();
-
- if (Ver.end() == false)
+ if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true)
{
- if (Now == true)
- ioprintf(out,_("but %s is installed"),Ver.VerStr());
+ if (Targ->ProvidesList == 0)
+ out << _("but it is not installable");
else
- ioprintf(out,_("but %s is to be installed"),Ver.VerStr());
- }
+ out << _("but it is a virtual package");
+ }
else
- {
- if (Cache[Targ].CandidateVerIter(Cache).end() == true)
- {
- if (Targ->ProvidesList == 0)
- out << _("but it is not installable");
- else
- out << _("but it is a virtual package");
- }
- else
- out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
- }
+ out << (Now?_("but it is not installed"):_("but it is not going to be installed"));
}
-
- if (Start != End)
- out << _(" or");
- out << endl;
-
- if (Start == End)
- break;
- ++Start;
- }
- }
- }
+ }
+
+ if (Start != End)
+ out << _(" or");
+ out << endl;
+
+ if (Start == End)
+ break;
+ ++Start;
+ }
+ }
+}
+void ShowBroken(ostream &out, CacheFile &Cache, bool const Now)
+{
+ if (Cache->BrokenCount() == 0)
+ return;
+
+ out << _("The following packages have unmet dependencies:") << endl;
+ for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
+ {
+ pkgCache::PkgIterator const I(Cache,Cache.List[J]);
+ ShowBrokenPackage(out, &Cache, I, Now);
+ }
+}
+void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now)
+{
+ if (Cache->BrokenCount() == 0)
+ return;
+
+ out << _("The following packages have unmet dependencies:") << endl;
+ for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); Pkg.end() == false; ++Pkg)
+ ShowBrokenPackage(out, &Cache, Pkg, Now);
}
/*}}}*/
// ShowNew - Show packages to newly install /*{{{*/
diff --git a/apt-private/private-output.h b/apt-private/private-output.h
index 9633d0c37..e0dc9bf62 100644
--- a/apt-private/private-output.h
+++ b/apt-private/private-output.h
@@ -23,12 +23,13 @@ APT_PUBLIC extern unsigned int ScreenWidth;
APT_PUBLIC bool InitOutput();
void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,
- pkgCache::VerIterator V, std::ostream &out,
- bool include_summary=true);
+ pkgCache::VerIterator const &V, std::ostream &out,
+ std::string const &format);
// helper to describe global state
-APT_PUBLIC void ShowBroken(std::ostream &out,CacheFile &Cache,bool Now);
+APT_PUBLIC void ShowBroken(std::ostream &out, CacheFile &Cache, bool const Now);
+APT_PUBLIC void ShowBroken(std::ostream &out, pkgCacheFile &Cache, bool const Now);
APT_PUBLIC bool ShowList(std::ostream &out, std::string Title, std::string List,
std::string VersionsList);
diff --git a/apt-private/private-search.cc b/apt-private/private-search.cc
index ecd5d7fad..6bce9ffa4 100644
--- a/apt-private/private-search.cc
+++ b/apt-private/private-search.cc
@@ -32,61 +32,95 @@ bool FullTextSearch(CommandLine &CmdL) /*{{{*/
pkgCacheFile CacheFile;
pkgCache *Cache = CacheFile.GetPkgCache();
pkgDepCache::Policy *Plcy = CacheFile.GetPolicy();
- pkgRecords records(CacheFile);
if (unlikely(Cache == NULL || Plcy == NULL))
return false;
- const char **patterns;
- patterns = CmdL.FileList + 1;
+ // Make sure there is at least one argument
+ unsigned int const NumPatterns = CmdL.FileSize() -1;
+ if (NumPatterns < 1)
+ return _error->Error(_("You must give at least one search pattern"));
+
+#define APT_FREE_PATTERNS() for (std::vector<regex_t>::iterator P = Patterns.begin(); \
+ P != Patterns.end(); ++P) { regfree(&(*P)); }
+
+ // Compile the regex pattern
+ std::vector<regex_t> Patterns;
+ for (unsigned int I = 0; I != NumPatterns; ++I)
+ {
+ regex_t pattern;
+ if (regcomp(&pattern, CmdL.FileList[I + 1], REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
+ {
+ APT_FREE_PATTERNS();
+ return _error->Error("Regex compilation error");
+ }
+ Patterns.push_back(pattern);
+ }
+
+ bool const NamesOnly = _config->FindB("APT::Cache::NamesOnly", false);
std::map<std::string, std::string> output_map;
- std::map<std::string, std::string>::const_iterator K;
LocalitySortedVersionSet bag;
OpTextProgress progress(*_config);
progress.OverallProgress(0, 100, 50, _("Sorting"));
- GetLocalitySortedVersionSet(CacheFile, bag, progress);
+ GetLocalitySortedVersionSet(CacheFile, &bag, &progress);
LocalitySortedVersionSet::iterator V = bag.begin();
progress.OverallProgress(50, 100, 50, _("Full Text Search"));
progress.SubProgress(bag.size());
+ pkgRecords records(CacheFile);
+
+ std::string format = "${color:highlight}${Package}${color:neutral}/${Origin} ${Version} ${Architecture}${ }${apt:Status}\n";
+ if (_config->FindB("APT::Cache::ShowFull",false) == false)
+ format += " ${Description}\n";
+ else
+ format += " ${LongDescription}\n";
+
int Done = 0;
+ std::vector<bool> PkgsDone(Cache->Head().PackageCount, false);
for ( ;V != bag.end(); ++V)
{
if (Done%500 == 0)
progress.Progress(Done);
++Done;
-
- int i;
+
+ // we want to list each package only once
+ pkgCache::PkgIterator const P = V.ParentPkg();
+ if (PkgsDone[P->ID] == true)
+ continue;
+
+ char const * const PkgName = P.Name();
pkgCache::DescIterator Desc = V.TranslatedDescription();
pkgRecords::Parser &parser = records.Lookup(Desc.FileList());
-
+ std::string const LongDesc = parser.LongDesc();
+
bool all_found = true;
- for(i=0; patterns[i] != NULL; ++i)
+ for (std::vector<regex_t>::const_iterator pattern = Patterns.begin();
+ pattern != Patterns.end(); ++pattern)
{
- // FIXME: use regexp instead of simple find()
- const char *pattern = patterns[i];
- all_found &= (
- strstr(V.ParentPkg().Name(), pattern) != NULL ||
- strcasestr(parser.ShortDesc().c_str(), pattern) != NULL ||
- strcasestr(parser.LongDesc().c_str(), pattern) != NULL);
- // search patterns are AND by default so we can skip looking further
- // on the first mismatch
- if(all_found == false)
- break;
+ if (regexec(&(*pattern), PkgName, 0, 0, 0) == 0)
+ continue;
+ else if (NamesOnly == false && regexec(&(*pattern), LongDesc.c_str(), 0, 0, 0) == 0)
+ continue;
+ // search patterns are AND, so one failing fails all
+ all_found = false;
+ break;
}
- if (all_found)
+ if (all_found == true)
{
- std::stringstream outs;
- ListSingleVersion(CacheFile, records, V, outs);
- output_map.insert(std::make_pair<std::string, std::string>(
- V.ParentPkg().Name(), outs.str()));
+ PkgsDone[P->ID] = true;
+ std::stringstream outs;
+ ListSingleVersion(CacheFile, records, V, outs, format);
+ output_map.insert(std::make_pair<std::string, std::string>(
+ PkgName, outs.str()));
}
}
+ APT_FREE_PATTERNS();
progress.Done();
// FIXME: SORT! and make sorting flexible (alphabetic, by pkg status)
// output the sorted map
+ std::map<std::string, std::string>::const_iterator K;
for (K = output_map.begin(); K != output_map.end(); ++K)
std::cout << (*K).second << std::endl;
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc
index 8ae6a6dac..289f035a6 100644
--- a/apt-private/private-show.cc
+++ b/apt-private/private-show.cc
@@ -141,16 +141,16 @@ bool ShowPackage(CommandLine &CmdL) /*{{{*/
{
pkgCacheFile CacheFile;
CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
- APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", false) ?
- APT::VersionList::ALL : APT::VersionList::CANDIDATE;
+ APT::CacheSetHelper::VerSelector const select = _config->FindB("APT::Cache::AllVersions", false) ?
+ APT::CacheSetHelper::ALL : APT::CacheSetHelper::CANDIDATE;
APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper);
for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver)
if (DisplayRecord(CacheFile, Ver, c1out) == false)
return false;
- if (select == APT::VersionList::CANDIDATE)
+ if (select == APT::CacheSetHelper::CANDIDATE)
{
- APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::ALL, helper);
+ APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::ALL, helper);
int const records = verset_all.size() - verset.size();
if (records > 0)
_error->Notice(P_("There is %i additional record. Please use the '-a' switch to see it", "There are %i additional records. Please use the '-a' switch to see them.", records), records);
diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc
index da83d7741..1cf3012ed 100644
--- a/apt-private/private-update.cc
+++ b/apt-private/private-update.cc
@@ -56,10 +56,17 @@ bool DoUpdate(CommandLine &CmdL)
if (List->GetIndexes(&Fetcher,true) == false)
return false;
+ std::string compExt = APT::Configuration::getCompressionTypes()[0];
pkgAcquire::UriIterator I = Fetcher.UriBegin();
for (; I != Fetcher.UriEnd(); ++I)
- c1out << '\'' << I->URI << "' " << flNotDir(I->Owner->DestFile) << ' ' <<
+ {
+ std::string FileName = flNotDir(I->Owner->DestFile);
+ if(compExt.empty() == false &&
+ APT::String::Endswith(FileName, compExt))
+ FileName = FileName.substr(0, FileName.size() - compExt.size() - 1);
+ c1out << '\'' << I->URI << "' " << FileName << ' ' <<
I->Owner->FileSize << ' ' << I->Owner->HashSum() << std::endl;
+ }
return true;
}
@@ -75,6 +82,27 @@ bool DoUpdate(CommandLine &CmdL)
return false;
}
+ // show basic stats (if the user whishes)
+ if (_config->FindB("APT::Cmd::Show-Update-Stats", false) == true)
+ {
+ int upgradable = 0;
+ Cache.Open();
+ for (pkgCache::PkgIterator I = Cache->PkgBegin(); I.end() != true; ++I)
+ {
+ pkgDepCache::StateCache &state = Cache[I];
+ if (I->CurrentVer != 0 && state.Upgradable() && state.CandidateVer != NULL)
+ upgradable++;
+ }
+ const char *msg = P_(
+ "%i package can be upgraded. Run 'apt list --upgradable' to see it.\n",
+ "%i packages can be upgraded. Run 'apt list --upgradable' to see them.\n",
+ upgradable);
+ if (upgradable == 0)
+ c1out << _("All packages are up to date.") << std::endl;
+ else
+ ioprintf(c1out, msg, upgradable);
+ }
+
return true;
}
/*}}}*/
diff --git a/apt-private/private-upgrade.cc b/apt-private/private-upgrade.cc
index 68b2c5e00..d13a6af49 100644
--- a/apt-private/private-upgrade.cc
+++ b/apt-private/private-upgrade.cc
@@ -22,19 +22,9 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags)
if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
return false;
- c0out << _("Calculating upgrade... ") << std::flush;
- if (APT::Upgrade::Upgrade(Cache, UpgradeFlags) == false)
- {
- c0out << _("Failed") << std::endl;
- ShowBroken(c1out,Cache,false);
- return _error->Error(_("Internal error, Upgrade broke stuff"));
- }
- c0out << _("Done") << std::endl;
-
- // parse additional cmdline pkg manipulation switches
- if(!DoCacheManipulationFromCommandLine(CmdL, Cache))
+ if(!DoCacheManipulationFromCommandLine(CmdL, Cache, UpgradeFlags))
return false;
-
+
return InstallPackages(Cache,true);
}
@@ -43,7 +33,7 @@ static bool UpgradeHelper(CommandLine &CmdL, int UpgradeFlags)
/* Intelligent upgrader that will install and remove packages at will */
bool DoDistUpgrade(CommandLine &CmdL)
{
- return UpgradeHelper(CmdL, 0);
+ return UpgradeHelper(CmdL, APT::Upgrade::ALLOW_EVERYTHING);
}
/*}}}*/
bool DoUpgrade(CommandLine &CmdL) /*{{{*/
diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc
index 9547a1b75..34af83c08 100644
--- a/apt-private/private-utils.cc
+++ b/apt-private/private-utils.cc
@@ -8,45 +8,69 @@
#include <cstdlib>
#include <unistd.h>
-// DisplayFileInPager - Display File with pager /*{{{*/
-void DisplayFileInPager(std::string filename)
+// DisplayFileInPager - Display File with pager /*{{{*/
+void DisplayFileInPager(std::string const &filename)
{
- std::string pager = _config->Find("Dir::Bin::Pager",
- "/usr/bin/sensible-pager");
-
pid_t Process = ExecFork();
if (Process == 0)
{
const char *Args[3];
- Args[0] = pager.c_str();
Args[1] = filename.c_str();
- Args[2] = 0;
+ Args[2] = NULL;
+ if (isatty(STDOUT_FILENO) == 1)
+ {
+ // likely installed, provided by sensible-utils
+ std::string const pager = _config->Find("Dir::Bin::Pager",
+ "sensible-pager");
+ Args[0] = pager.c_str();
+ execvp(Args[0],(char **)Args);
+ // lets try some obvious alternatives
+ Args[0] = getenv("PAGER");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = "pager";
+ execvp(Args[0],(char **)Args);
+ }
+ // we could read the file ourselves, but… meh
+ Args[0] = "cat";
execvp(Args[0],(char **)Args);
exit(100);
}
-
+
// Wait for the subprocess
- ExecWait(Process, "sensible-pager", false);
+ ExecWait(Process, "pager", false);
}
/*}}}*/
-// EditFileInSensibleEditor - Edit File with editor /*{{{*/
-void EditFileInSensibleEditor(std::string filename)
+// EditFileInSensibleEditor - Edit File with editor /*{{{*/
+void EditFileInSensibleEditor(std::string const &filename)
{
- std::string editor = _config->Find("Dir::Bin::Editor",
- "/usr/bin/sensible-editor");
-
pid_t Process = ExecFork();
if (Process == 0)
{
+ // likely installed, provided by sensible-utils
+ std::string const editor = _config->Find("Dir::Bin::Editor",
+ "sensible-editor");
const char *Args[3];
Args[0] = editor.c_str();
Args[1] = filename.c_str();
- Args[2] = 0;
+ Args[2] = NULL;
+ execvp(Args[0],(char **)Args);
+ // the usual suspects we can try as an alternative
+ Args[0] = getenv("VISUAL");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = getenv("EDITOR");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = "editor";
execvp(Args[0],(char **)Args);
exit(100);
}
-
+
// Wait for the subprocess
- ExecWait(Process, "sensible-editor", false);
+ ExecWait(Process, "editor", false);
}
/*}}}*/
diff --git a/apt-private/private-utils.h b/apt-private/private-utils.h
index 432699787..8ba480bd4 100644
--- a/apt-private/private-utils.h
+++ b/apt-private/private-utils.h
@@ -5,7 +5,7 @@
#include <string>
-APT_PUBLIC void DisplayFileInPager(std::string filename);
-APT_PUBLIC void EditFileInSensibleEditor(std::string filename);
+APT_PUBLIC void DisplayFileInPager(std::string const &filename);
+APT_PUBLIC void EditFileInSensibleEditor(std::string const &filename);
#endif