1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Simple wrapper around a std::set to provide a similar interface to
6 a set of cache structures as to the complete set of all structures
7 in the pkgCache. Currently only Package is supported.
9 ##################################################################### */
11 // Include Files /*{{{*/
14 #include <apt-pkg/aptconfiguration.h>
15 #include <apt-pkg/cachefile.h>
16 #include <apt-pkg/cachefilter.h>
17 #include <apt-pkg/cacheset.h>
18 #include <apt-pkg/error.h>
19 #include <apt-pkg/versionmatch.h>
20 #include <apt-pkg/pkgrecords.h>
21 #include <apt-pkg/policy.h>
22 #include <apt-pkg/cacheiterators.h>
23 #include <apt-pkg/configuration.h>
24 #include <apt-pkg/depcache.h>
25 #include <apt-pkg/macros.h>
26 #include <apt-pkg/pkgcache.h>
27 #include <apt-pkg/fileutl.h>
40 // PackageFrom - selecting the appropriate method for package selection /*{{{*/
41 bool CacheSetHelper::PackageFrom(enum PkgSelector
const select
, PackageContainerInterface
* const pci
,
42 pkgCacheFile
&Cache
, std::string
const &pattern
) {
44 case UNKNOWN
: return false;
45 case REGEX
: return PackageFromRegEx(pci
, Cache
, pattern
);
46 case TASK
: return PackageFromTask(pci
, Cache
, pattern
);
47 case FNMATCH
: return PackageFromFnmatch(pci
, Cache
, pattern
);
48 case PACKAGENAME
: return PackageFromPackageName(pci
, Cache
, pattern
);
49 case STRING
: return PackageFromString(pci
, Cache
, pattern
);
54 // PackageFromTask - Return all packages in the cache from a specific task /*{{{*/
55 bool CacheSetHelper::PackageFromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
) {
56 size_t const archfound
= pattern
.find_last_of(':');
57 std::string arch
= "native";
58 if (archfound
!= std::string::npos
) {
59 arch
= pattern
.substr(archfound
+1);
60 pattern
.erase(archfound
);
63 if (pattern
[pattern
.length() -1] != '^')
65 pattern
.erase(pattern
.length()-1);
67 if (unlikely(Cache
.GetPkgCache() == 0 || Cache
.GetDepCache() == 0))
70 bool const wasEmpty
= pci
->empty();
72 pci
->setConstructor(CacheSetHelper::TASK
);
75 pkgRecords
Recs(Cache
);
77 // build regexp for the task
80 snprintf(S
, sizeof(S
), "^Task:.*[, ]%s([, ]|$)", pattern
.c_str());
81 if(regcomp(&Pattern
,S
, REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
) != 0) {
82 _error
->Error("Failed to compile task regexp");
87 for (pkgCache::GrpIterator Grp
= Cache
->GrpBegin(); Grp
.end() == false; ++Grp
) {
88 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
89 if (Pkg
.end() == true)
91 pkgCache::VerIterator ver
= Cache
[Pkg
].CandidateVerIter(Cache
);
95 pkgRecords::Parser
&parser
= Recs
.Lookup(ver
.FileList());
96 const char *start
, *end
;
97 parser
.GetRec(start
,end
);
98 unsigned int const length
= end
- start
;
99 if (unlikely(length
== 0))
102 strncpy(buf
, start
, length
);
103 buf
[length
-1] = '\0';
104 if (regexec(&Pattern
, buf
, 0, 0, 0) != 0)
108 showPackageSelection(Pkg
, CacheSetHelper::TASK
, pattern
);
113 if (found
== false) {
114 canNotFindPackage(CacheSetHelper::TASK
, pci
, Cache
, pattern
);
115 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
119 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
120 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
125 // PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/
126 bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
) {
127 static const char * const isregex
= ".?+*|[^$";
128 if (pattern
.find_first_of(isregex
) == std::string::npos
)
131 bool const wasEmpty
= pci
->empty();
132 if (wasEmpty
== true)
133 pci
->setConstructor(CacheSetHelper::REGEX
);
135 size_t archfound
= pattern
.find_last_of(':');
136 std::string arch
= "native";
137 if (archfound
!= std::string::npos
) {
138 arch
= pattern
.substr(archfound
+1);
139 if (arch
.find_first_of(isregex
) == std::string::npos
)
140 pattern
.erase(archfound
);
145 if (unlikely(Cache
.GetPkgCache() == 0))
148 APT::CacheFilter::PackageNameMatchesRegEx
regexfilter(pattern
);
151 for (pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->GrpBegin(); Grp
.end() == false; ++Grp
) {
152 if (regexfilter(Grp
) == false)
154 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
155 if (Pkg
.end() == true) {
156 if (archfound
== std::string::npos
)
157 Pkg
= Grp
.FindPreferredPkg(true);
158 if (Pkg
.end() == true)
163 showPackageSelection(Pkg
, CacheSetHelper::REGEX
, pattern
);
167 if (found
== false) {
168 canNotFindPackage(CacheSetHelper::REGEX
, pci
, Cache
, pattern
);
169 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
173 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
174 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
179 // PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/
180 bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface
* const pci
,
181 pkgCacheFile
&Cache
, std::string pattern
)
183 static const char * const isfnmatch
= ".?*[]!";
184 if (pattern
.find_first_of(isfnmatch
) == std::string::npos
)
187 bool const wasEmpty
= pci
->empty();
188 if (wasEmpty
== true)
189 pci
->setConstructor(CacheSetHelper::FNMATCH
);
191 size_t archfound
= pattern
.find_last_of(':');
192 std::string arch
= "native";
193 if (archfound
!= std::string::npos
) {
194 arch
= pattern
.substr(archfound
+1);
195 if (arch
.find_first_of(isfnmatch
) == std::string::npos
)
196 pattern
.erase(archfound
);
201 if (unlikely(Cache
.GetPkgCache() == 0))
204 APT::CacheFilter::PackageNameMatchesFnmatch
filter(pattern
);
207 for (pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->GrpBegin(); Grp
.end() == false; ++Grp
) {
208 if (filter(Grp
) == false)
210 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
211 if (Pkg
.end() == true) {
212 if (archfound
== std::string::npos
)
213 Pkg
= Grp
.FindPreferredPkg(true);
214 if (Pkg
.end() == true)
219 showPackageSelection(Pkg
, CacheSetHelper::FNMATCH
, pattern
);
223 if (found
== false) {
224 canNotFindPackage(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
);
225 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
229 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
230 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
235 // PackageFromName - Returns the package defined by this string /*{{{*/
236 pkgCache::PkgIterator
CacheSetHelper::PackageFromName(pkgCacheFile
&Cache
,
237 std::string
const &str
) {
238 std::string pkg
= str
;
239 size_t archfound
= pkg
.find_last_of(':');
241 if (archfound
!= std::string::npos
) {
242 arch
= pkg
.substr(archfound
+1);
243 pkg
.erase(archfound
);
246 if (Cache
.GetPkgCache() == 0)
247 return pkgCache::PkgIterator(Cache
, 0);
249 pkgCache::PkgIterator
Pkg(Cache
, 0);
250 if (arch
.empty() == true) {
251 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
252 if (Grp
.end() == false)
253 Pkg
= Grp
.FindPreferredPkg();
255 Pkg
= Cache
.GetPkgCache()->FindPkg(pkg
, arch
);
257 if (Pkg
.end() == true)
258 return canNotFindPkgName(Cache
, str
);
262 // PackageFromPackageName - Returns the package defined by this string /*{{{*/
263 bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
265 if (unlikely(Cache
.GetPkgCache() == 0))
268 size_t const archfound
= pkg
.find_last_of(':');
270 if (archfound
!= std::string::npos
) {
271 arch
= pkg
.substr(archfound
+1);
272 pkg
.erase(archfound
);
273 if (arch
== "all" || arch
== "native")
274 arch
= _config
->Find("APT::Architecture");
277 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
278 if (Grp
.end() == false) {
279 if (arch
.empty() == true) {
280 pkgCache::PkgIterator Pkg
= Grp
.FindPreferredPkg();
281 if (Pkg
.end() == false)
288 // for 'linux-any' return the first package matching, for 'linux-*' return all matches
289 bool const isGlobal
= arch
.find('*') != std::string::npos
;
290 APT::CacheFilter::PackageArchitectureMatchesSpecification
pams(arch
);
291 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
)) {
292 if (pams(Pkg
) == false)
296 if (isGlobal
== false)
304 pkgCache::PkgIterator Pkg
= canNotFindPkgName(Cache
, pkg
);
305 if (Pkg
.end() == true)
312 // PackageFromString - Return all packages matching a specific string /*{{{*/
313 bool CacheSetHelper::PackageFromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
) {
315 _error
->PushToStack();
317 if (PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
) == false &&
318 PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, str
) == false &&
319 // FIXME: hm, hm, regexp/fnmatch incompatible?
320 PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, str
) == false &&
321 PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, str
) == false)
323 canNotFindPackage(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
328 _error
->RevertToStack();
330 _error
->MergeWithStack();
334 // PackageFromCommandLine - Return all packages specified on commandline /*{{{*/
335 bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
) {
337 for (const char **I
= cmdline
; *I
!= 0; ++I
)
338 found
|= PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, *I
);
342 // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
343 bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
344 pkgCacheFile
&Cache
, const char * cmdline
,
345 std::list
<PkgModifier
> const &mods
) {
346 std::string str
= cmdline
;
347 unsigned short fallback
= modID
;
348 bool modifierPresent
= false;
349 for (std::list
<PkgModifier
>::const_iterator mod
= mods
.begin();
350 mod
!= mods
.end(); ++mod
) {
351 size_t const alength
= strlen(mod
->Alias
);
353 case PkgModifier::POSTFIX
:
354 if (str
.compare(str
.length() - alength
, alength
,
355 mod
->Alias
, 0, alength
) != 0)
357 str
.erase(str
.length() - alength
);
360 case PkgModifier::PREFIX
:
362 case PkgModifier::NONE
:
365 modifierPresent
= true;
368 if (modifierPresent
== true) {
369 bool const errors
= showErrors(false);
370 bool const found
= PackageFrom(PACKAGENAME
, pci
, Cache
, cmdline
);
377 return PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
380 // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
381 bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID
,
382 VersionContainerInterface
* const vci
,
383 pkgCacheFile
&Cache
, const char * cmdline
,
384 std::list
<Modifier
> const &mods
,
385 CacheSetHelper
&helper
) {
386 CacheSetHelper::VerSelector select
= CacheSetHelper::NEWEST
;
387 std::string str
= cmdline
;
388 if (unlikely(str
.empty() == true))
390 bool modifierPresent
= false;
391 unsigned short fallback
= modID
;
392 for (std::list
<Modifier
>::const_iterator mod
= mods
.begin();
393 mod
!= mods
.end(); ++mod
) {
394 if (modID
== fallback
&& mod
->ID
== fallback
)
395 select
= mod
->SelectVersion
;
396 size_t const alength
= strlen(mod
->Alias
);
398 case Modifier::POSTFIX
:
399 if (str
.length() <= alength
||
400 str
.compare(str
.length() - alength
, alength
, mod
->Alias
, 0, alength
) != 0)
402 str
.erase(str
.length() - alength
);
404 select
= mod
->SelectVersion
;
406 case Modifier::PREFIX
:
411 modifierPresent
= true;
414 if (modifierPresent
== true) {
415 bool const errors
= helper
.showErrors(false);
416 bool const found
= VersionContainerInterface::FromString(vci
, Cache
, cmdline
, select
, helper
, true);
417 helper
.showErrors(errors
);
423 return FromString(vci
, Cache
, str
, select
, helper
);
426 // FromCommandLine - Return all versions specified on commandline /*{{{*/
427 bool VersionContainerInterface::FromCommandLine(VersionContainerInterface
* const vci
,
428 pkgCacheFile
&Cache
, const char **cmdline
,
429 CacheSetHelper::VerSelector
const fallback
,
430 CacheSetHelper
&helper
) {
432 for (const char **I
= cmdline
; *I
!= 0; ++I
)
433 found
|= VersionContainerInterface::FromString(vci
, Cache
, *I
, fallback
, helper
);
437 // FromString - Returns all versions spedcified by a string /*{{{*/
438 bool VersionContainerInterface::FromString(VersionContainerInterface
* const vci
,
439 pkgCacheFile
&Cache
, std::string pkg
,
440 CacheSetHelper::VerSelector
const fallback
,
441 CacheSetHelper
&helper
,
442 bool const onlyFromName
) {
444 if(FileExists(pkg
)) {
445 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
446 if(pkgset
.empty() == true)
448 return VersionContainerInterface::FromPackage(vci
, Cache
, pkgset
.begin(), fallback
, helper
);
452 bool verIsRel
= false;
453 size_t const vertag
= pkg
.find_last_of("/=");
454 if (vertag
!= std::string::npos
) {
455 ver
= pkg
.substr(vertag
+1);
456 verIsRel
= (pkg
[vertag
] == '/');
459 if (onlyFromName
== false)
460 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
462 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &pkgset
, Cache
, pkg
);
466 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
467 errors
= helper
.showErrors(false);
470 for (PackageSet::const_iterator P
= pkgset
.begin();
471 P
!= pkgset
.end(); ++P
) {
472 if (vertag
== std::string::npos
) {
473 found
|= VersionContainerInterface::FromPackage(vci
, Cache
, P
, fallback
, helper
);
476 pkgCache::VerIterator V
;
477 if (ver
== "installed")
478 V
= getInstalledVer(Cache
, P
, helper
);
479 else if (ver
== "candidate")
480 V
= getCandidateVer(Cache
, P
, helper
);
481 else if (ver
== "newest") {
482 if (P
->VersionList
!= 0)
485 V
= helper
.canNotGetVersion(CacheSetHelper::NEWEST
, Cache
, P
);
487 pkgVersionMatch
Match(ver
, (verIsRel
== true ? pkgVersionMatch::Release
:
488 pkgVersionMatch::Version
));
490 if (V
.end() == true) {
491 if (verIsRel
== true)
492 _error
->Error(_("Release '%s' for '%s' was not found"),
493 ver
.c_str(), P
.FullName(true).c_str());
495 _error
->Error(_("Version '%s' for '%s' was not found"),
496 ver
.c_str(), P
.FullName(true).c_str());
502 if (verIsRel
== true)
503 helper
.showVersionSelection(P
, V
, CacheSetHelper::RELEASE
, ver
);
505 helper
.showVersionSelection(P
, V
, CacheSetHelper::VERSIONNUMBER
, ver
);
509 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
510 helper
.showErrors(errors
);
514 // FromPackage - versions from package based on fallback /*{{{*/
515 bool VersionContainerInterface::FromPackage(VersionContainerInterface
* const vci
,
517 pkgCache::PkgIterator
const &P
,
518 CacheSetHelper::VerSelector
const fallback
,
519 CacheSetHelper
&helper
) {
520 pkgCache::VerIterator V
;
524 case CacheSetHelper::ALL
:
525 if (P
->VersionList
!= 0)
526 for (V
= P
.VersionList(); V
.end() != true; ++V
)
527 found
|= vci
->insert(V
);
529 helper
.canNotFindVersion(CacheSetHelper::ALL
, vci
, Cache
, P
);
531 case CacheSetHelper::CANDANDINST
:
532 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
533 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
535 case CacheSetHelper::CANDIDATE
:
536 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
538 case CacheSetHelper::INSTALLED
:
539 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
541 case CacheSetHelper::CANDINST
:
542 showErrors
= helper
.showErrors(false);
543 V
= getCandidateVer(Cache
, P
, helper
);
545 V
= getInstalledVer(Cache
, P
, helper
);
546 helper
.showErrors(showErrors
);
547 if (V
.end() == false)
548 found
|= vci
->insert(V
);
550 helper
.canNotFindVersion(CacheSetHelper::CANDINST
, vci
, Cache
, P
);
552 case CacheSetHelper::INSTCAND
:
553 showErrors
= helper
.showErrors(false);
554 V
= getInstalledVer(Cache
, P
, helper
);
556 V
= getCandidateVer(Cache
, P
, helper
);
557 helper
.showErrors(showErrors
);
558 if (V
.end() == false)
559 found
|= vci
->insert(V
);
561 helper
.canNotFindVersion(CacheSetHelper::INSTCAND
, vci
, Cache
, P
);
563 case CacheSetHelper::NEWEST
:
564 if (P
->VersionList
!= 0)
565 found
|= vci
->insert(P
.VersionList());
567 helper
.canNotFindVersion(CacheSetHelper::NEWEST
, vci
, Cache
, P
);
569 case CacheSetHelper::RELEASE
:
570 case CacheSetHelper::VERSIONNUMBER
:
571 // both make no sense here, so always false
577 // FromDependency - versions satisfying a given dependency /*{{{*/
578 bool VersionContainerInterface::FromDependency(VersionContainerInterface
* const vci
,
580 pkgCache::DepIterator
const &D
,
581 CacheSetHelper::VerSelector
const selector
,
582 CacheSetHelper
&helper
)
586 case CacheSetHelper::ALL
:
588 pkgCache::PkgIterator
const T
= D
.TargetPkg();
589 for (pkgCache::VerIterator Ver
= T
.VersionList(); Ver
.end() == false; ++Ver
)
591 if (D
.IsSatisfied(Ver
) == true)
596 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
598 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
599 if (unlikely(V
.end() == true) || D
.IsSatisfied(Prv
) == false)
607 case CacheSetHelper::CANDANDINST
:
609 found
= FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
);
610 found
&= FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
);
613 case CacheSetHelper::CANDIDATE
:
615 pkgCache::PkgIterator
const T
= D
.TargetPkg();
616 pkgCache::VerIterator
const Cand
= Cache
[T
].CandidateVerIter(Cache
);
617 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
622 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
624 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
625 pkgCache::VerIterator
const Cand
= Cache
[Prv
.OwnerPkg()].CandidateVerIter(Cache
);
626 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
633 case CacheSetHelper::INSTALLED
:
635 pkgCache::PkgIterator
const T
= D
.TargetPkg();
636 pkgCache::VerIterator
const Cand
= T
.CurrentVer();
637 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
642 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
644 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
645 pkgCache::VerIterator
const Cand
= Prv
.OwnerPkg().CurrentVer();
646 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
653 case CacheSetHelper::CANDINST
:
654 return FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
) ||
655 FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
);
656 case CacheSetHelper::INSTCAND
:
657 return FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
) ||
658 FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
);
659 case CacheSetHelper::NEWEST
:
661 pkgCache::PkgIterator
const T
= D
.TargetPkg();
662 pkgCache::VerIterator
const Cand
= T
.VersionList();
663 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
668 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
670 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
671 pkgCache::VerIterator
const Cand
= Prv
.OwnerPkg().VersionList();
672 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
679 case CacheSetHelper::RELEASE
:
680 case CacheSetHelper::VERSIONNUMBER
:
681 // both make no sense here, so always false
687 // getCandidateVer - Returns the candidate version of the given package /*{{{*/
688 pkgCache::VerIterator
VersionContainerInterface::getCandidateVer(pkgCacheFile
&Cache
,
689 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
690 pkgCache::VerIterator Cand
;
691 if (Cache
.IsDepCacheBuilt() == true) {
692 Cand
= Cache
[Pkg
].CandidateVerIter(Cache
);
693 } else if (unlikely(Cache
.GetPolicy() == nullptr)) {
694 return pkgCache::VerIterator(Cache
);
696 Cand
= Cache
.GetPolicy()->GetCandidateVer(Pkg
);
698 if (Cand
.end() == true)
699 return helper
.canNotGetVersion(CacheSetHelper::CANDIDATE
, Cache
, Pkg
);
703 // getInstalledVer - Returns the installed version of the given package /*{{{*/
704 pkgCache::VerIterator
VersionContainerInterface::getInstalledVer(pkgCacheFile
&Cache
,
705 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
706 if (Pkg
->CurrentVer
== 0)
707 return helper
.canNotGetVersion(CacheSetHelper::INSTALLED
, Cache
, Pkg
);
708 return Pkg
.CurrentVer();
712 // canNotFindPackage - with the given selector and pattern /*{{{*/
713 void CacheSetHelper::canNotFindPackage(enum PkgSelector
const select
,
714 PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
715 std::string
const &pattern
) {
717 APT_IGNORE_DEPRECATED_PUSH
718 case REGEX
: canNotFindRegEx(pci
, Cache
, pattern
); break;
719 case TASK
: canNotFindTask(pci
, Cache
, pattern
); break;
720 case FNMATCH
: canNotFindFnmatch(pci
, Cache
, pattern
); break;
721 case PACKAGENAME
: canNotFindPackage(pci
, Cache
, pattern
); break;
722 case STRING
: canNotFindPackage(pci
, Cache
, pattern
); break;
724 APT_IGNORE_DEPRECATED_POP
727 // canNotFindTask - handle the case no package is found for a task /*{{{*/
728 void CacheSetHelper::canNotFindTask(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
729 if (ShowError
== true)
730 _error
->Insert(ErrorType
, _("Couldn't find task '%s'"), pattern
.c_str());
733 // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
734 void CacheSetHelper::canNotFindRegEx(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
735 if (ShowError
== true)
736 _error
->Insert(ErrorType
, _("Couldn't find any package by regex '%s'"), pattern
.c_str());
739 // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
740 void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
741 if (ShowError
== true)
742 _error
->Insert(ErrorType
, _("Couldn't find any package by glob '%s'"), pattern
.c_str());
745 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
746 APT_CONST
void CacheSetHelper::canNotFindPackage(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string
const &/*str*/) {
750 // canNotFindPkgName - handle the case no package has this name /*{{{*/
751 pkgCache::PkgIterator
CacheSetHelper::canNotFindPkgName(pkgCacheFile
&Cache
,
752 std::string
const &str
) {
753 if (ShowError
== true)
754 _error
->Insert(ErrorType
, _("Unable to locate package %s"), str
.c_str());
755 return pkgCache::PkgIterator(Cache
, 0);
758 // canNotFindVersion - for package by selector /*{{{*/
759 void CacheSetHelper::canNotFindVersion(enum VerSelector
const select
, VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
)
762 APT_IGNORE_DEPRECATED_PUSH
763 case ALL
: canNotFindAllVer(vci
, Cache
, Pkg
); break;
764 case INSTCAND
: canNotFindInstCandVer(vci
, Cache
, Pkg
); break;
765 case CANDINST
: canNotFindCandInstVer(vci
, Cache
, Pkg
); break;
766 case NEWEST
: canNotFindNewestVer(Cache
, Pkg
); break;
767 case CANDIDATE
: canNotFindCandidateVer(Cache
, Pkg
); break;
768 case INSTALLED
: canNotFindInstalledVer(Cache
, Pkg
); break;
769 APT_IGNORE_DEPRECATED_POP
770 case CANDANDINST
: canNotGetCandInstVer(Cache
, Pkg
); break;
773 // invalid in this branch
777 // canNotFindAllVer /*{{{*/
778 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&/*Cache*/,
779 pkgCache::PkgIterator
const &Pkg
) {
780 if (ShowError
== true)
781 _error
->Insert(ErrorType
, _("Can't select versions from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
784 // canNotFindInstCandVer /*{{{*/
785 void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
786 pkgCache::PkgIterator
const &Pkg
) {
787 canNotGetInstCandVer(Cache
, Pkg
);
790 // canNotFindInstCandVer /*{{{*/
791 void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
792 pkgCache::PkgIterator
const &Pkg
) {
793 canNotGetCandInstVer(Cache
, Pkg
);
797 // canNotGetVersion - for package by selector /*{{{*/
798 pkgCache::VerIterator
CacheSetHelper::canNotGetVersion(enum VerSelector
const select
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
800 APT_IGNORE_DEPRECATED_PUSH
801 case NEWEST
: return canNotFindNewestVer(Cache
, Pkg
);
802 case CANDIDATE
: return canNotFindCandidateVer(Cache
, Pkg
);
803 case INSTALLED
: return canNotFindInstalledVer(Cache
, Pkg
);
804 APT_IGNORE_DEPRECATED_POP
805 case CANDINST
: return canNotGetCandInstVer(Cache
, Pkg
);
806 case INSTCAND
: return canNotGetInstCandVer(Cache
, Pkg
);
811 // invalid in this branch
812 return pkgCache::VerIterator(Cache
, 0);
814 return pkgCache::VerIterator(Cache
, 0);
816 // canNotFindNewestVer /*{{{*/
817 pkgCache::VerIterator
CacheSetHelper::canNotFindNewestVer(pkgCacheFile
&Cache
,
818 pkgCache::PkgIterator
const &Pkg
) {
819 if (ShowError
== true)
820 _error
->Insert(ErrorType
, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
821 return pkgCache::VerIterator(Cache
, 0);
824 // canNotFindCandidateVer /*{{{*/
825 pkgCache::VerIterator
CacheSetHelper::canNotFindCandidateVer(pkgCacheFile
&Cache
,
826 pkgCache::PkgIterator
const &Pkg
) {
827 if (ShowError
== true)
828 _error
->Insert(ErrorType
, _("Can't select candidate version from package %s as it has no candidate"), Pkg
.FullName(true).c_str());
829 return pkgCache::VerIterator(Cache
, 0);
832 // canNotFindInstalledVer /*{{{*/
833 pkgCache::VerIterator
CacheSetHelper::canNotFindInstalledVer(pkgCacheFile
&Cache
,
834 pkgCache::PkgIterator
const &Pkg
) {
835 if (ShowError
== true)
836 _error
->Insert(ErrorType
, _("Can't select installed version from package %s as it is not installed"), Pkg
.FullName(true).c_str());
837 return pkgCache::VerIterator(Cache
, 0);
840 // canNotFindInstCandVer /*{{{*/
841 pkgCache::VerIterator
CacheSetHelper::canNotGetInstCandVer(pkgCacheFile
&Cache
,
842 pkgCache::PkgIterator
const &Pkg
) {
843 if (ShowError
== true)
844 _error
->Insert(ErrorType
, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg
.FullName(true).c_str());
845 return pkgCache::VerIterator(Cache
, 0);
848 // canNotFindInstCandVer /*{{{*/
849 pkgCache::VerIterator
CacheSetHelper::canNotGetCandInstVer(pkgCacheFile
&Cache
,
850 pkgCache::PkgIterator
const &Pkg
) {
851 if (ShowError
== true)
852 _error
->Insert(ErrorType
, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg
.FullName(true).c_str());
853 return pkgCache::VerIterator(Cache
, 0);
857 // showPackageSelection - by selector and given pattern /*{{{*/
858 void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator
const &pkg
, enum PkgSelector
const select
,
859 std::string
const &pattern
) {
861 APT_IGNORE_DEPRECATED_PUSH
862 case REGEX
: showRegExSelection(pkg
, pattern
); break;
863 case TASK
: showTaskSelection(pkg
, pattern
); break;
864 case FNMATCH
: showFnmatchSelection(pkg
, pattern
); break;
865 APT_IGNORE_DEPRECATED_POP
866 case PACKAGENAME
: /* no suprises here */ break;
867 case STRING
: /* handled by the special cases */ break;
871 // showTaskSelection /*{{{*/
872 APT_CONST
void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator
const &/*pkg*/,
873 std::string
const &/*pattern*/) {
876 // showRegExSelection /*{{{*/
877 APT_CONST
void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator
const &/*pkg*/,
878 std::string
const &/*pattern*/) {
881 // showFnmatchSelection /*{{{*/
882 APT_CONST
void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator
const &/*pkg*/,
883 std::string
const &/*pattern*/) {
887 // showVersionSelection /*{{{*/
888 void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator
const &Pkg
,
889 pkgCache::VerIterator
const &Ver
, enum VerSelector
const select
, std::string
const &pattern
) {
891 APT_IGNORE_DEPRECATED_PUSH
893 showSelectedVersion(Pkg
, Ver
, pattern
, true);
896 showSelectedVersion(Pkg
, Ver
, pattern
, false);
898 APT_IGNORE_DEPRECATED_POP
906 // not really suprises, but in fact: just not implemented
910 APT_CONST
void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator
const &/*Pkg*/,
911 pkgCache::VerIterator
const /*Ver*/,
912 std::string
const &/*ver*/,
913 bool const /*verIsRel*/) {
917 CacheSetHelper::CacheSetHelper(bool const ShowError
, GlobalError::MsgType ErrorType
) :
918 ShowError(ShowError
), ErrorType(ErrorType
), d(NULL
) {}
919 CacheSetHelper::~CacheSetHelper() {}
921 PackageContainerInterface::PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN
), d(NULL
) {}
922 PackageContainerInterface::PackageContainerInterface(CacheSetHelper::PkgSelector
const by
) : ConstructedBy(by
), d(NULL
) {}
923 PackageContainerInterface
& PackageContainerInterface::operator=(PackageContainerInterface
const &other
) {
925 this->ConstructedBy
= other
.ConstructedBy
;
928 PackageContainerInterface::~PackageContainerInterface() {}
930 PackageUniverse::PackageUniverse(pkgCache
* const Owner
) : _cont(Owner
), d(NULL
) {}
931 PackageUniverse::PackageUniverse(pkgCacheFile
* const Owner
) : _cont(Owner
->GetPkgCache()), d(NULL
) {}
932 PackageUniverse::~PackageUniverse() {}
934 VersionContainerInterface::VersionContainerInterface() : d(NULL
) {}
935 VersionContainerInterface
& VersionContainerInterface::operator=(VersionContainerInterface
const &) {
939 VersionContainerInterface::~VersionContainerInterface() {}