summaryrefslogtreecommitdiff
path: root/apt-pkg/depcache.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-02-08 10:25:47 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-02-08 10:25:47 +0100
commit4c6cf49317769725fee34a132c52ec1fe076b8b5 (patch)
tree1394a74a187ce61982c6c8649721de2f543459a1 /apt-pkg/depcache.cc
parent931dcf2f960c6a2b117ab3cc847ce51c04e2140c (diff)
parent3eb9e257855d83d0486d7a5fa7cc5e2edebb6aaa (diff)
merged from lp:~donkult/apt/sid
Diffstat (limited to 'apt-pkg/depcache.cc')
-rw-r--r--apt-pkg/depcache.cc182
1 files changed, 175 insertions, 7 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index 23abc76c1..5f59b6d49 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -10,6 +10,7 @@
// Include Files /*{{{*/
#include <apt-pkg/depcache.h>
#include <apt-pkg/version.h>
+#include <apt-pkg/versionmatch.h>
#include <apt-pkg/error.h>
#include <apt-pkg/sptr.h>
#include <apt-pkg/algorithms.h>
@@ -166,7 +167,7 @@ bool pkgDepCache::readStateFile(OpProgress *Prog) /*{{{*/
{
FileFd state_file;
string const state = _config->FindFile("Dir::State::extended_states");
- if(FileExists(state)) {
+ if(RealFileExists(state)) {
state_file.Open(state, FileFd::ReadOnly);
int const file_size = state_file.Size();
if(Prog != NULL)
@@ -225,7 +226,7 @@ bool pkgDepCache::writeStateFile(OpProgress *prog, bool InstalledOnly) /*{{{*/
string const state = _config->FindFile("Dir::State::extended_states");
// if it does not exist, create a empty one
- if(!FileExists(state))
+ if(!RealFileExists(state))
{
StateFile.Open(state, FileFd::WriteAtomic);
StateFile.Close();
@@ -1329,8 +1330,6 @@ void pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
for (DepIterator D = instVer.DependsList(); D.end() != true; D++)
{
//FIXME: deal better with or-groups(?)
- DepIterator LocalStart = D;
-
if(IsImportantDep(D) && !D.IsCritical() &&
Start.TargetPkg() == D.TargetPkg())
{
@@ -1510,15 +1509,19 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
/* */
void pkgDepCache::SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo)
{
- ActionGroup group(*this);
pkgCache::PkgIterator Pkg = TargetVer.ParentPkg();
StateCache &P = PkgState[Pkg->ID];
+ if (P.CandidateVer == TargetVer)
+ return;
+
+ ActionGroup group(*this);
+
RemoveSizes(Pkg);
RemoveStates(Pkg);
- if (P.CandidateVer == P.InstallVer)
+ if (P.CandidateVer == P.InstallVer && P.Install() == true)
P.InstallVer = (Version *)TargetVer;
P.CandidateVer = (Version *)TargetVer;
P.Update(Pkg,*this);
@@ -1549,7 +1552,171 @@ void pkgDepCache::SetCandidateVersion(VerIterator TargetVer, bool const &Pseudo)
}
}
}
+ /*}}}*/
+// DepCache::SetCandidateRelease - Change the candidate version /*{{{*/
+// ---------------------------------------------------------------------
+/* changes the candidate of a package and walks over all its dependencies
+ to check if it needs to change the candidate of the dependency, too,
+ to reach a installable versionstate */
+bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
+ std::string const &TargetRel)
+{
+ std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > Changed;
+ return SetCandidateRelease(TargetVer, TargetRel, Changed);
+}
+bool pkgDepCache::SetCandidateRelease(pkgCache::VerIterator TargetVer,
+ std::string const &TargetRel,
+ std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> > &Changed)
+{
+ ActionGroup group(*this);
+ SetCandidateVersion(TargetVer);
+
+ if (TargetRel == "installed" || TargetRel == "candidate") // both doesn't make sense in this context
+ return true;
+
+ pkgVersionMatch Match(TargetRel, pkgVersionMatch::Release);
+ // save the position of the last element we will not undo - if we have to
+ std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::iterator newChanged = --(Changed.end());
+
+ for (pkgCache::DepIterator D = TargetVer.DependsList(); D.end() == false; ++D)
+ {
+ if (D->Type != pkgCache::Dep::PreDepends && D->Type != pkgCache::Dep::Depends &&
+ ((D->Type != pkgCache::Dep::Recommends && D->Type != pkgCache::Dep::Suggests) ||
+ IsImportantDep(D) == false))
+ continue;
+
+ // walk over an or-group and check if we need to do anything
+ // for simpilicity no or-group is handled as a or-group including one dependency
+ pkgCache::DepIterator Start = D;
+ bool itsFine = false;
+ for (bool stillOr = true; stillOr == true; ++Start)
+ {
+ stillOr = (Start->CompareOp & Dep::Or) == Dep::Or;
+ pkgCache::PkgIterator const P = Start.TargetPkg();
+ // virtual packages can't be a solution
+ if (P.end() == true || (P->ProvidesList == 0 && P->VersionList == 0))
+ continue;
+ pkgCache::VerIterator const Cand = PkgState[P->ID].CandidateVerIter(*this);
+ // no versioned dependency - but is it installable?
+ if (Start.TargetVer() == 0 || Start.TargetVer()[0] == '\0')
+ {
+ // Check if one of the providers is installable
+ if (P->ProvidesList != 0)
+ {
+ pkgCache::PrvIterator Prv = P.ProvidesList();
+ for (; Prv.end() == false; ++Prv)
+ {
+ pkgCache::VerIterator const C = PkgState[Prv.OwnerPkg()->ID].CandidateVerIter(*this);
+ if (C.end() == true || C != Prv.OwnerVer() ||
+ (VersionState(C.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) != DepCandMin)
+ continue;
+ break;
+ }
+ if (Prv.end() == true)
+ continue;
+ }
+ // no providers, so check if we have an installable candidate version
+ else if (Cand.end() == true ||
+ (VersionState(Cand.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) != DepCandMin)
+ continue;
+ itsFine = true;
+ break;
+ }
+ if (Cand.end() == true)
+ continue;
+ // check if the current candidate is enough for the versioned dependency - and installable?
+ if (VS().CheckDep(P.CandVersion(), Start->CompareOp, Start.TargetVer()) == true &&
+ (VersionState(Cand.DependsList(), DepInstall, DepCandMin, DepCandPolicy) & DepCandMin) == DepCandMin)
+ {
+ itsFine = true;
+ break;
+ }
+ }
+
+ if (itsFine == true) {
+ // something in the or-group was fine, skip all other members
+ for (; (D->CompareOp & Dep::Or) == Dep::Or; ++D);
+ continue;
+ }
+
+ // walk again over the or-group and check each if a candidate switch would help
+ itsFine = false;
+ for (bool stillOr = true; stillOr == true; ++D)
+ {
+ stillOr = (D->CompareOp & Dep::Or) == Dep::Or;
+ // changing candidate will not help if the dependency is not versioned
+ if (D.TargetVer() == 0 || D.TargetVer()[0] == '\0')
+ {
+ if (stillOr == true)
+ continue;
+ break;
+ }
+
+ pkgCache::VerIterator V;
+ if (TargetRel == "newest")
+ V = D.TargetPkg().VersionList();
+ else
+ V = Match.Find(D.TargetPkg());
+
+ // check if the version from this release could satisfy the dependency
+ if (V.end() == true || VS().CheckDep(V.VerStr(), D->CompareOp, D.TargetVer()) == false)
+ {
+ if (stillOr == true)
+ continue;
+ break;
+ }
+
+ pkgCache::VerIterator oldCand = PkgState[D.TargetPkg()->ID].CandidateVerIter(*this);
+ if (V == oldCand)
+ {
+ // Do we already touched this Version? If so, their versioned dependencies are okay, no need to check again
+ for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = Changed.begin();
+ c != Changed.end(); ++c)
+ {
+ if (c->first->ParentPkg != V->ParentPkg)
+ continue;
+ itsFine = true;
+ break;
+ }
+ }
+
+ if (itsFine == false)
+ {
+ // change the candidate
+ Changed.push_back(make_pair(oldCand, TargetVer));
+ if (SetCandidateRelease(V, TargetRel, Changed) == false)
+ {
+ if (stillOr == false)
+ break;
+ // undo the candidate changing
+ SetCandidateVersion(oldCand);
+ Changed.pop_back();
+ continue;
+ }
+ itsFine = true;
+ }
+
+ // something in the or-group was fine, skip all other members
+ for (; (D->CompareOp & Dep::Or) == Dep::Or; ++D);
+ break;
+ }
+ if (itsFine == false && (D->Type == pkgCache::Dep::PreDepends || D->Type == pkgCache::Dep::Depends))
+ {
+ // undo all changes which aren't lead to a solution
+ for (std::list<std::pair<pkgCache::VerIterator, pkgCache::VerIterator> >::const_iterator c = ++newChanged;
+ c != Changed.end(); ++c)
+ SetCandidateVersion(c->first);
+ Changed.erase(newChanged, Changed.end());
+ return false;
+ }
+ }
+ return true;
+}
+ /*}}}*/
+// DepCache::MarkAuto - set the Auto flag for a package /*{{{*/
+// ---------------------------------------------------------------------
+/* */
void pkgDepCache::MarkAuto(const PkgIterator &Pkg, bool Auto)
{
StateCache &state = PkgState[Pkg->ID];
@@ -1752,10 +1919,11 @@ void pkgDepCache::MarkPackage(const pkgCache::PkgIterator &pkg,
return;
VerIterator const currver = pkg.CurrentVer();
- VerIterator const candver = state.CandidateVerIter(*this);
VerIterator const instver = state.InstVerIter(*this);
#if 0
+ VerIterator const candver = state.CandidateVerIter(*this);
+
// If a package was garbage-collected but is now being marked, we
// should re-select it
// For cases when a pkg is set to upgrade and this trigger the