+// AddSelectedVersion - add version from package based on fallback /*{{{*/
+bool VersionSet::AddSelectedVersion(pkgCacheFile &Cache, VersionSet &verset,
+ pkgCache::PkgIterator const &P, VersionSet::Version const &fallback,
+ bool const &AllowError) {
+ pkgCache::VerIterator V;
+ switch(fallback) {
+ case VersionSet::ALL:
+ if (P->VersionList != 0)
+ for (V = P.VersionList(); V.end() != true; ++V)
+ verset.insert(V);
+ else if (AllowError == false)
+ return _error->Error(_("Can't select versions from package '%s' as it purely virtual"), P.FullName(true).c_str());
+ else
+ return false;
+ break;
+ case VersionSet::CANDANDINST:
+ verset.insert(getInstalledVer(Cache, P, AllowError));
+ verset.insert(getCandidateVer(Cache, P, AllowError));
+ break;
+ case VersionSet::CANDIDATE:
+ verset.insert(getCandidateVer(Cache, P, AllowError));
+ break;
+ case VersionSet::INSTALLED:
+ verset.insert(getInstalledVer(Cache, P, AllowError));
+ break;
+ case VersionSet::CANDINST:
+ V = getCandidateVer(Cache, P, true);
+ if (V.end() == true)
+ V = getInstalledVer(Cache, P, true);
+ if (V.end() == false)
+ verset.insert(V);
+ else if (AllowError == false)
+ return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str());
+ else
+ return false;
+ break;
+ case VersionSet::INSTCAND:
+ V = getInstalledVer(Cache, P, true);
+ if (V.end() == true)
+ V = getCandidateVer(Cache, P, true);
+ if (V.end() == false)
+ verset.insert(V);
+ else if (AllowError == false)
+ return _error->Error(_("Can't select installed nor candidate version from package '%s' as it has neither of them"), P.FullName(true).c_str());
+ else
+ return false;
+ break;
+ case VersionSet::NEWEST:
+ if (P->VersionList != 0)
+ verset.insert(P.VersionList());
+ else if (AllowError == false)
+ return _error->Error(_("Can't select newest version from package '%s' as it is purely virtual"), P.FullName(true).c_str());
+ else
+ return false;
+ break;
+ }
+ return true;
+}
+ /*}}}*/