Browse Source

sanify API to get 'the' candidate version

This was discussed a while ago on #debian-apt and now that I see myself
making this mistake lets bite the bullet and fix it in the easy way out
version: Using a new name which fits with a similar named setter and
deprecate the old method instead of 'hostily' changing API.

Closes: #803471
tags/debian/1.1_exp15
David Kalnischkies 5 years ago
parent
commit
294a80209a
8 changed files with 56 additions and 11 deletions
  1. +1
    -1
      apt-pkg/algorithms.cc
  2. +2
    -2
      apt-pkg/deb/dpkgpm.cc
  3. +6
    -1
      apt-pkg/depcache.cc
  4. +13
    -2
      apt-pkg/depcache.h
  5. +4
    -3
      apt-pkg/edsp.cc
  6. +9
    -0
      apt-pkg/edsp/edsplistparser.cc
  7. +2
    -2
      apt-private/private-source.cc
  8. +19
    -0
      test/integration/test-external-dependency-solver-protocol

+ 1
- 1
apt-pkg/algorithms.cc View File

@@ -933,7 +933,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
Start.TargetPkg()->CurrentVer == 0 &&
Cache[Start.TargetPkg()].Delete() == false &&
(Flags[Start.TargetPkg()->ID] & ToRemove) != ToRemove &&
Cache.GetCandidateVer(Start.TargetPkg()).end() == false)
Cache.GetCandidateVersion(Start.TargetPkg()).end() == false)
{
/* Before removing or keeping the package with the broken dependency
try instead to install the first not previously installed package


+ 2
- 2
apt-pkg/deb/dpkgpm.cc View File

@@ -1718,11 +1718,11 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
if(pos != string::npos)
pkgname = pkgname.substr(0, pos);

// find the package versin and source package name
// find the package version and source package name
pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname);
if (Pkg.end() == true)
return;
pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
pkgCache::VerIterator Ver = Cache.GetCandidateVersion(Pkg);
if (Ver.end() == true)
return;
pkgver = Ver.VerStr() == NULL ? "unknown" : Ver.VerStr();


+ 6
- 1
apt-pkg/depcache.cc View File

@@ -153,7 +153,7 @@ bool pkgDepCache::Init(OpProgress * const Prog)
State.iFlags = 0;

// Figure out the install version
State.CandidateVer = GetCandidateVer(I);
State.CandidateVer = LocalPolicy->GetCandidateVer(I);
State.InstallVer = I.CurrentVer();
State.Mode = ModeKeep;

@@ -1467,6 +1467,11 @@ void pkgDepCache::SetReInstall(PkgIterator const &Pkg,bool To)
}
}
/*}}}*/
pkgCache::VerIterator pkgDepCache::GetCandidateVersion(PkgIterator const &Pkg)/*{{{*/
{
return PkgState[Pkg->ID].CandidateVerIter(*this);
}
/*}}}*/
// DepCache::SetCandidateVersion - Change the candidate version /*{{{*/
// ---------------------------------------------------------------------
/* */


+ 13
- 2
apt-pkg/depcache.h View File

@@ -360,9 +360,10 @@ class pkgDepCache : protected pkgCache::Namespace

inline pkgCache &GetCache() {return *Cache;};
inline pkgVersioningSystem &VS() {return *Cache->VS;};
// Policy implementation
inline VerIterator GetCandidateVer(PkgIterator const &Pkg) {return LocalPolicy->GetCandidateVer(Pkg);};
APT_DEPRECATED inline VerIterator GetCandidateVer(PkgIterator const &Pkg) {return /* GetCandidateVersion(Pkg); but for API compat: */ LocalPolicy->GetCandidateVer(Pkg);};

inline bool IsImportantDep(DepIterator Dep) const {return LocalPolicy->IsImportantDep(Dep);};
inline Policy &GetPolicy() {return *LocalPolicy;};
@@ -413,6 +414,16 @@ class pkgDepCache : protected pkgCache::Namespace
void MarkProtected(PkgIterator const &Pkg) { PkgState[Pkg->ID].iFlags |= Protected; };

void SetReInstall(PkgIterator const &Pkg,bool To);

/** @return 'the' candidate version of a package
*
* The version returned is the version previously set explicitly via
* SetCandidate* methods like #SetCandidateVersion or if there wasn't one
* set the version as choosen via #Policy.
*
* @param Pkg is the package to return the candidate for
*/
pkgCache::VerIterator GetCandidateVersion(pkgCache::PkgIterator const &Pkg);
void SetCandidateVersion(VerIterator TargetVer);
bool SetCandidateRelease(pkgCache::VerIterator TargetVer,
std::string const &TargetRel);


+ 4
- 3
apt-pkg/edsp.cc View File

@@ -84,7 +84,7 @@ static void WriteScenarioVersion(pkgDepCache &Cache, FILE* output, pkgCache::Pkg
fprintf(output, " %s\n", R->c_str());
}
fprintf(output, "APT-Pin: %d\n", Pin);
if (Cache.GetCandidateVer(Pkg) == Ver)
if (Cache.GetCandidateVersion(Pkg) == Ver)
fprintf(output, "APT-Candidate: yes\n");
if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
fprintf(output, "APT-Automatic: yes\n");
@@ -510,9 +510,10 @@ bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
}
else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
{
fprintf(output, "Install: %d\n", Cache.GetCandidateVer(Pkg)->ID);
pkgCache::VerIterator const CandVer = Cache.GetCandidateVersion(Pkg);
fprintf(output, "Install: %d\n", CandVer->ID);
if (Debug == true)
fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Cache.GetCandidateVer(Pkg).VerStr());
fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), CandVer.VerStr());
}
else if (Cache[Pkg].Garbage == true)
{


+ 9
- 0
apt-pkg/edsp/edsplistparser.cc View File

@@ -111,6 +111,15 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
return false;
}

// FIXME: Using an overriding pin is wrong.
if (Section.FindB("APT-Candidate", false))
{
std::string out;
strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
if (d->preferences.Write(out.c_str(), out.length()) == false)
return false;
}

signed short const pinvalue = Section.FindI("APT-Pin", 500);
if (pinvalue != 500)
{


+ 2
- 2
apt-private/private-source.cc View File

@@ -245,8 +245,8 @@ static pkgSrcRecords::Parser *FindSrc(const char *Name,
// choose a good candidate and proceed with that.
// Maybe we will find a source later on with the right VerTag
// or RelTag
pkgCache::VerIterator Ver = Cache->GetCandidateVer(Pkg);
if (Ver.end() == false)
pkgCache::VerIterator const Ver = Cache->GetCandidateVersion(Pkg);
if (Ver.end() == false)
{
if (strcmp(Ver.SourcePkgName(),Ver.ParentPkg().Name()) != 0)
Src = Ver.SourcePkgName();


+ 19
- 0
test/integration/test-external-dependency-solver-protocol View File

@@ -62,6 +62,25 @@ The following NEW packages will be installed:
Inst coolstuff (3 experimental [amd64])
Conf coolstuff (3 experimental [amd64])' aptget install --solver apt coolstuff -s -t experimental

testsuccessequal "Reading package lists...
Building dependency tree...
Selected version '3' (experimental [amd64]) for 'coolstuff'
Execute external solver...
The following NEW packages will be installed:
coolstuff
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Inst coolstuff (3 experimental [amd64])
Conf coolstuff (3 experimental [amd64])" aptget install --solver apt coolstuff/experimental -sq=0

testsuccessequal 'Reading package lists...
Building dependency tree...
Execute external solver...
The following NEW packages will be installed:
coolstuff
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Inst coolstuff (3 experimental [amd64])
Conf coolstuff (3 experimental [amd64])' aptget install --solver apt coolstuff=3 -sq=0

testsuccessequal 'Reading package lists...
Building dependency tree...
Execute external solver...


Loading…
Cancel
Save