#include <apt-pkg/error.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/algorithms.h>
-
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/tagfile.h>
+#include <apt-pkg/progress.h>
+#include <apt-pkg/cacheset.h>
+#include <algorithm>
#include <iostream>
#include <sstream>
#include <set>
#include <apti18n.h>
/*}}}*/
+
+using std::string;
+
// helper for Install-Recommends-Sections and Never-MarkAuto-Sections /*{{{*/
static bool
ConfigValueInSubTree(const char* SubTree, const char *needle)
/* Set the current state of everything. In this state all of the
packages are kept exactly as is. See AllUpgrade */
int Done = 0;
- for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
+ for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
{
if (Prog != 0 && Done%20 == 0)
Prog->Progress(Done);
string const state = _config->FindFile("Dir::State::extended_states");
if(RealFileExists(state)) {
state_file.Open(state, FileFd::ReadOnly);
- int const file_size = state_file.Size();
+ off_t const file_size = state_file.Size();
if(Prog != NULL)
Prog->OverallProgress(0, file_size, 1,
_("Reading state information"));
pkgTagFile tagfile(&state_file);
pkgTagSection section;
- int amt = 0;
+ off_t amt = 0;
bool const debug_autoremove = _config->FindB("Debug::pkgAutoRemove",false);
while(tagfile.Step(section)) {
string const pkgname = section.FindS("Package");
// then write the ones we have not seen yet
std::ostringstream ostr;
- for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); pkg++) {
+ for(pkgCache::PkgIterator pkg=Cache->PkgBegin(); !pkg.end(); ++pkg) {
StateCache const &P = PkgState[pkg->ID];
if(P.Flags & Flag::Auto) {
if (pkgs_seen.find(pkg.FullName()) != pkgs_seen.end()) {
// Check the providing packages
PrvIterator P = Dep.TargetPkg().ProvidesList();
- PkgIterator Pkg = Dep.ParentPkg();
- for (; P.end() != true; P++)
+ for (; P.end() != true; ++P)
{
- /* Provides may never be applied against the same package (or group)
- if it is a conflicts. See the comment above. */
- if (P.OwnerPkg()->Group == Pkg->Group && Dep.IsNegative() == true)
+ if (Dep.IsIgnorable(P) == true)
continue;
-
+
// Check if the provides is a hit
if (Type == NowVersion)
{
{
unsigned char Group = 0;
- for (DepIterator D = V.DependsList(); D.end() != true; D++)
+ for (DepIterator D = V.DependsList(); D.end() != true; ++D)
{
// Build the dependency state.
unsigned char &State = DepState[D->ID];
// Compute a single dependency element (glob or)
DepIterator Start = D;
unsigned char State = 0;
- for (bool LastOR = true; D.end() == false && LastOR == true; D++)
+ for (bool LastOR = true; D.end() == false && LastOR == true; ++D)
{
State |= DepState[D->ID];
LastOR = (D->CompareOp & Dep::Or) == Dep::Or;
// Perform the depends pass
int Done = 0;
- for (PkgIterator I = PkgBegin(); I.end() != true; I++,Done++)
+ for (PkgIterator I = PkgBegin(); I.end() != true; ++I, ++Done)
{
if (Prog != 0 && Done%20 == 0)
Prog->Progress(Done);
- for (VerIterator V = I.VersionList(); V.end() != true; V++)
+ for (VerIterator V = I.VersionList(); V.end() != true; ++V)
{
unsigned char Group = 0;
- for (DepIterator D = V.DependsList(); D.end() != true; D++)
+ for (DepIterator D = V.DependsList(); D.end() != true; ++D)
{
// Build the dependency state.
unsigned char &State = DepState[D->ID];
void pkgDepCache::Update(DepIterator D)
{
// Update the reverse deps
- for (;D.end() != true; D++)
+ for (;D.end() != true; ++D)
{
unsigned char &State = DepState[D->ID];
State = DependencyState(D);
// Update the provides map for the current ver
if (Pkg->CurrentVer != 0)
for (PrvIterator P = Pkg.CurrentVer().ProvidesList();
- P.end() != true; P++)
+ P.end() != true; ++P)
Update(P.ParentPkg().RevDependsList());
// Update the provides map for the candidate ver
if (PkgState[Pkg->ID].CandidateVer != 0)
for (PrvIterator P = PkgState[Pkg->ID].CandidateVerIter(*this).ProvidesList();
- P.end() != true; P++)
+ P.end() != true; ++P)
Update(P.ParentPkg().RevDependsList());
}
/*}}}*/
// DepCache::MarkInstall - Put the package in the install state /*{{{*/
// ---------------------------------------------------------------------
/* */
+struct CompareProviders {
+ pkgCache::PkgIterator const Pkg;
+ CompareProviders(pkgCache::DepIterator const &Dep) : Pkg(Dep.TargetPkg()) {};
+ //bool operator() (APT::VersionList::iterator const &AV, APT::VersionList::iterator const &BV)
+ bool operator() (pkgCache::VerIterator const &AV, pkgCache::VerIterator const &BV)
+ {
+ pkgCache::PkgIterator const A = AV.ParentPkg();
+ pkgCache::PkgIterator const B = BV.ParentPkg();
+ // Prefer packages in the same group as the target; e.g. foo:i386, foo:amd64
+ if (A->Group != B->Group)
+ {
+ if (A->Group == Pkg->Group && B->Group != Pkg->Group)
+ return false;
+ else if (B->Group == Pkg->Group && A->Group != Pkg->Group)
+ return true;
+ }
+ // we like essentials
+ if ((A->Flags & pkgCache::Flag::Essential) != (B->Flags & pkgCache::Flag::Essential))
+ {
+ if ((A->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ return false;
+ else if ((B->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
+ return true;
+ }
+ if ((A->Flags & pkgCache::Flag::Important) != (B->Flags & pkgCache::Flag::Important))
+ {
+ if ((A->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return false;
+ else if ((B->Flags & pkgCache::Flag::Important) == pkgCache::Flag::Important)
+ return true;
+ }
+ // higher priority seems like a good idea
+ if (AV->Priority != BV->Priority)
+ return AV->Priority < BV->Priority;
+ // prefer native architecture
+ if (strcmp(A.Arch(), B.Arch()) != 0)
+ {
+ if (strcmp(A.Arch(), A.Cache()->NativeArch()) == 0)
+ return false;
+ else if (strcmp(B.Arch(), B.Cache()->NativeArch()) == 0)
+ return true;
+ std::vector<std::string> archs = APT::Configuration::getArchitectures();
+ for (std::vector<std::string>::const_iterator a = archs.begin(); a != archs.end(); ++a)
+ if (*a == A.Arch())
+ return false;
+ else if (*a == B.Arch())
+ return true;
+ }
+ // unable to decideā¦
+ return A->ID < B->ID;
+ }
+};
bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
unsigned long Depth, bool FromUser,
bool ForceImportantDeps)
DepIterator Start = Dep;
bool Result = true;
unsigned Ors = 0;
- for (bool LastOR = true; Dep.end() == false && LastOR == true; Dep++,Ors++)
+ for (bool LastOR = true; Dep.end() == false && LastOR == true; ++Dep, ++Ors)
{
LastOR = (Dep->CompareOp & Dep::Or) == Dep::Or;
/* This bit is for processing the possibilty of an install/upgrade
fixing the problem */
- SPtrArray<Version *> List = Start.AllTargets();
if (Start->Type != Dep::DpkgBreaks &&
(DepState[Start->ID] & DepCVer) == DepCVer)
{
- // Right, find the best version to install..
- Version **Cur = List;
- PkgIterator P = Start.TargetPkg();
- PkgIterator InstPkg(*Cache,0);
-
- // See if there are direct matches (at the start of the list)
- for (; *Cur != 0 && (*Cur)->ParentPkg == P.Index(); Cur++)
+ APT::VersionList verlist;
+ pkgCache::VerIterator Cand = PkgState[Start.TargetPkg()->ID].CandidateVerIter(*this);
+ if (Cand.end() == false && VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == true)
+ verlist.insert(Cand);
+ for (PrvIterator Prv = Start.TargetPkg().ProvidesList(); Prv.end() != true; ++Prv)
{
- PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
- if (PkgState[Pkg->ID].CandidateVer != *Cur)
+ pkgCache::VerIterator V = Prv.OwnerVer();
+ pkgCache::VerIterator Cand = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
+ if (Cand.end() == true || V != Cand ||
+ VS().CheckDep(Cand.VerStr(), Start->CompareOp, Start.TargetVer()) == false)
continue;
- InstPkg = Pkg;
- break;
+ verlist.insert(Cand);
}
+ CompareProviders comp(Start);
+ APT::VersionList::iterator InstVer = std::max_element(verlist.begin(), verlist.end(), comp);
- // Select the highest priority providing package
- if (InstPkg.end() == true)
- {
- pkgPrioSortList(*Cache,Cur);
- for (; *Cur != 0; Cur++)
- {
- PkgIterator Pkg(*Cache,Cache->PkgP + (*Cur)->ParentPkg);
- if (PkgState[Pkg->ID].CandidateVer != *Cur)
- continue;
- InstPkg = Pkg;
- break;
- }
- }
-
- if (InstPkg.end() == false)
+ if (InstVer != verlist.end())
{
+ pkgCache::PkgIterator InstPkg = InstVer.ParentPkg();
if(DebugAutoInstall == true)
std::clog << OutputInDepth(Depth) << "Installing " << InstPkg.Name()
<< " as " << Start.DepType() << " of " << Pkg.Name()
// mark automatic dependency
MarkInstall(InstPkg,true,Depth + 1, false, ForceImportantDeps);
// Set the autoflag, after MarkInstall because MarkInstall unsets it
- if (P->CurrentVer == 0)
+ if (InstPkg->CurrentVer == 0)
PkgState[InstPkg->ID].Flags |= Flag::Auto;
}
}
upgrade the package. */
if (Start.IsNegative() == true)
{
+ SPtrArray<Version *> List = Start.AllTargets();
for (Version **I = List; *I != 0; I++)
{
VerIterator Ver(*this,*I);
if (unlikely(Pkg.end() == true))
return;
+ APT::PackageList pkglist;
+ if (Pkg->CurrentVer != 0 &&
+ (Pkg.CurrentVer()-> MultiArch & pkgCache::Version::Same) == pkgCache::Version::Same)
+ {
+ pkgCache::GrpIterator Grp = Pkg.Group();
+ for (pkgCache::PkgIterator P = Grp.PackageList(); P.end() == false; P = Grp.NextPkg(P))
+ {
+ if (P->CurrentVer != 0)
+ pkglist.insert(P);
+ }
+ }
+ else
+ pkglist.insert(Pkg);
+
ActionGroup group(*this);
- RemoveSizes(Pkg);
- RemoveStates(Pkg);
-
- StateCache &P = PkgState[Pkg->ID];
- if (To == true)
- P.iFlags |= ReInstall;
- else
- P.iFlags &= ~ReInstall;
-
- AddStates(Pkg);
- AddSizes(Pkg);
+ for (APT::PackageList::const_iterator Pkg = pkglist.begin(); Pkg != pkglist.end(); ++Pkg)
+ {
+ RemoveSizes(Pkg);
+ RemoveStates(Pkg);
+
+ StateCache &P = PkgState[Pkg->ID];
+ if (To == true)
+ P.iFlags |= ReInstall;
+ else
+ P.iFlags &= ~ReInstall;
+
+ AddStates(Pkg);
+ AddSizes(Pkg);
+ }
}
/*}}}*/
// DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
unless they are already installed */
VerIterator Last(*(pkgCache *)this,0);
- for (VerIterator I = Pkg.VersionList(); I.end() == false; I++)
+ for (VerIterator I = Pkg.VersionList(); I.end() == false; ++I)
{
if (Pkg.CurrentVer() == I)
return I;
- for (VerFileIterator J = I.FileList(); J.end() == false; J++)
+ for (VerFileIterator J = I.FileList(); J.end() == false; ++J)
{
if ((J.File()->Flags & Flag::NotSource) != 0)
continue;
return true;
else if(Dep->Type == pkgCache::Dep::Recommends)
{
- if ( _config->FindB("APT::Install-Recommends", false))
+ if (InstallRecommends)
return true;
// we suport a special mode to only install-recommends for certain
// sections
return true;
}
else if(Dep->Type == pkgCache::Dep::Suggests)
- return _config->FindB("APT::Install-Suggests", false);
+ return InstallSuggests;
return false;
}
{
if(!(PkgState[p->ID].Flags & Flag::Auto) ||
(p->Flags & Flag::Essential) ||
+ (p->Flags & Flag::Important) ||
userFunc.InRootSet(p) ||
// be nice even then a required package violates the policy (#583517)
// and do the full mark process also for required packages