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 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
158 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
159 a
!= archs
.end() && Pkg
.end() != true; ++a
)
160 Pkg
= Grp
.FindPkg(*a
);
162 if (Pkg
.end() == true)
167 showPackageSelection(Pkg
, CacheSetHelper::REGEX
, pattern
);
171 if (found
== false) {
172 canNotFindPackage(CacheSetHelper::REGEX
, pci
, Cache
, pattern
);
173 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
177 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
178 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
183 // PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/
184 bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface
* const pci
,
185 pkgCacheFile
&Cache
, std::string pattern
)
187 static const char * const isfnmatch
= ".?*[]!";
188 if (pattern
.find_first_of(isfnmatch
) == std::string::npos
)
191 bool const wasEmpty
= pci
->empty();
192 if (wasEmpty
== true)
193 pci
->setConstructor(CacheSetHelper::FNMATCH
);
195 size_t archfound
= pattern
.find_last_of(':');
196 std::string arch
= "native";
197 if (archfound
!= std::string::npos
) {
198 arch
= pattern
.substr(archfound
+1);
199 if (arch
.find_first_of(isfnmatch
) == std::string::npos
)
200 pattern
.erase(archfound
);
205 if (unlikely(Cache
.GetPkgCache() == 0))
208 APT::CacheFilter::PackageNameMatchesFnmatch
filter(pattern
);
211 for (pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->GrpBegin(); Grp
.end() == false; ++Grp
) {
212 if (filter(Grp
) == false)
214 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
215 if (Pkg
.end() == true) {
216 if (archfound
== std::string::npos
) {
217 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
218 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
219 a
!= archs
.end() && Pkg
.end() != true; ++a
)
220 Pkg
= Grp
.FindPkg(*a
);
222 if (Pkg
.end() == true)
227 showPackageSelection(Pkg
, CacheSetHelper::FNMATCH
, pattern
);
231 if (found
== false) {
232 canNotFindPackage(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
);
233 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
237 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
238 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
243 // PackageFromName - Returns the package defined by this string /*{{{*/
244 pkgCache::PkgIterator
CacheSetHelper::PackageFromName(pkgCacheFile
&Cache
,
245 std::string
const &str
) {
246 std::string pkg
= str
;
247 size_t archfound
= pkg
.find_last_of(':');
249 if (archfound
!= std::string::npos
) {
250 arch
= pkg
.substr(archfound
+1);
251 pkg
.erase(archfound
);
254 if (Cache
.GetPkgCache() == 0)
255 return pkgCache::PkgIterator(Cache
, 0);
257 pkgCache::PkgIterator
Pkg(Cache
, 0);
258 if (arch
.empty() == true) {
259 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
260 if (Grp
.end() == false)
261 Pkg
= Grp
.FindPreferredPkg();
263 Pkg
= Cache
.GetPkgCache()->FindPkg(pkg
, arch
);
265 if (Pkg
.end() == true)
266 return canNotFindPkgName(Cache
, str
);
270 // PackageFromPackageName - Returns the package defined by this string /*{{{*/
271 bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
273 if (unlikely(Cache
.GetPkgCache() == 0))
276 size_t const archfound
= pkg
.find_last_of(':');
278 if (archfound
!= std::string::npos
) {
279 arch
= pkg
.substr(archfound
+1);
280 pkg
.erase(archfound
);
281 if (arch
== "all" || arch
== "native")
282 arch
= _config
->Find("APT::Architecture");
285 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
286 if (Grp
.end() == false) {
287 if (arch
.empty() == true) {
288 pkgCache::PkgIterator Pkg
= Grp
.FindPreferredPkg();
289 if (Pkg
.end() == false)
296 // for 'linux-any' return the first package matching, for 'linux-*' return all matches
297 bool const isGlobal
= arch
.find('*') != std::string::npos
;
298 APT::CacheFilter::PackageArchitectureMatchesSpecification
pams(arch
);
299 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
)) {
300 if (pams(Pkg
) == false)
304 if (isGlobal
== false)
312 pkgCache::PkgIterator Pkg
= canNotFindPkgName(Cache
, pkg
);
313 if (Pkg
.end() == true)
320 // PackageFromString - Return all packages matching a specific string /*{{{*/
321 bool CacheSetHelper::PackageFromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
) {
323 _error
->PushToStack();
325 if (PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
) == false &&
326 PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, str
) == false &&
327 // FIXME: hm, hm, regexp/fnmatch incompatible?
328 PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, str
) == false &&
329 PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, str
) == false)
331 canNotFindPackage(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
336 _error
->RevertToStack();
338 _error
->MergeWithStack();
342 // PackageFromCommandLine - Return all packages specified on commandline /*{{{*/
343 bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
) {
345 for (const char **I
= cmdline
; *I
!= 0; ++I
)
346 found
|= PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, *I
);
350 // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
351 bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
352 pkgCacheFile
&Cache
, const char * cmdline
,
353 std::list
<PkgModifier
> const &mods
) {
354 std::string str
= cmdline
;
355 unsigned short fallback
= modID
;
356 bool modifierPresent
= false;
357 for (std::list
<PkgModifier
>::const_iterator mod
= mods
.begin();
358 mod
!= mods
.end(); ++mod
) {
359 size_t const alength
= strlen(mod
->Alias
);
361 case PkgModifier::POSTFIX
:
362 if (str
.compare(str
.length() - alength
, alength
,
363 mod
->Alias
, 0, alength
) != 0)
365 str
.erase(str
.length() - alength
);
368 case PkgModifier::PREFIX
:
370 case PkgModifier::NONE
:
373 modifierPresent
= true;
376 if (modifierPresent
== true) {
377 bool const errors
= showErrors(false);
378 bool const found
= PackageFrom(PACKAGENAME
, pci
, Cache
, cmdline
);
385 return PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
388 // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
389 bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID
,
390 VersionContainerInterface
* const vci
,
391 pkgCacheFile
&Cache
, const char * cmdline
,
392 std::list
<Modifier
> const &mods
,
393 CacheSetHelper
&helper
) {
394 CacheSetHelper::VerSelector select
= CacheSetHelper::NEWEST
;
395 std::string str
= cmdline
;
396 if (unlikely(str
.empty() == true))
398 bool modifierPresent
= false;
399 unsigned short fallback
= modID
;
400 for (std::list
<Modifier
>::const_iterator mod
= mods
.begin();
401 mod
!= mods
.end(); ++mod
) {
402 if (modID
== fallback
&& mod
->ID
== fallback
)
403 select
= mod
->SelectVersion
;
404 size_t const alength
= strlen(mod
->Alias
);
406 case Modifier::POSTFIX
:
407 if (str
.length() <= alength
||
408 str
.compare(str
.length() - alength
, alength
, mod
->Alias
, 0, alength
) != 0)
410 str
.erase(str
.length() - alength
);
412 select
= mod
->SelectVersion
;
414 case Modifier::PREFIX
:
419 modifierPresent
= true;
422 if (modifierPresent
== true) {
423 bool const errors
= helper
.showErrors(false);
424 bool const found
= VersionContainerInterface::FromString(vci
, Cache
, cmdline
, select
, helper
, true);
425 helper
.showErrors(errors
);
431 return FromString(vci
, Cache
, str
, select
, helper
);
434 // FromCommandLine - Return all versions specified on commandline /*{{{*/
435 bool VersionContainerInterface::FromCommandLine(VersionContainerInterface
* const vci
,
436 pkgCacheFile
&Cache
, const char **cmdline
,
437 CacheSetHelper::VerSelector
const fallback
,
438 CacheSetHelper
&helper
) {
440 for (const char **I
= cmdline
; *I
!= 0; ++I
)
441 found
|= VersionContainerInterface::FromString(vci
, Cache
, *I
, fallback
, helper
);
445 // FromString - Returns all versions spedcified by a string /*{{{*/
446 bool VersionContainerInterface::FromString(VersionContainerInterface
* const vci
,
447 pkgCacheFile
&Cache
, std::string pkg
,
448 CacheSetHelper::VerSelector
const fallback
,
449 CacheSetHelper
&helper
,
450 bool const onlyFromName
) {
452 if(FileExists(pkg
)) {
453 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
454 if(pkgset
.empty() == true)
456 return VersionContainerInterface::FromPackage(vci
, Cache
, pkgset
.begin(), fallback
, helper
);
460 bool verIsRel
= false;
461 size_t const vertag
= pkg
.find_last_of("/=");
462 if (vertag
!= std::string::npos
) {
463 ver
= pkg
.substr(vertag
+1);
464 verIsRel
= (pkg
[vertag
] == '/');
467 if (onlyFromName
== false)
468 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
470 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &pkgset
, Cache
, pkg
);
474 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
475 errors
= helper
.showErrors(false);
478 for (PackageSet::const_iterator P
= pkgset
.begin();
479 P
!= pkgset
.end(); ++P
) {
480 if (vertag
== std::string::npos
) {
481 found
|= VersionContainerInterface::FromPackage(vci
, Cache
, P
, fallback
, helper
);
484 pkgCache::VerIterator V
;
485 if (ver
== "installed")
486 V
= getInstalledVer(Cache
, P
, helper
);
487 else if (ver
== "candidate")
488 V
= getCandidateVer(Cache
, P
, helper
);
489 else if (ver
== "newest") {
490 if (P
->VersionList
!= 0)
493 V
= helper
.canNotGetVersion(CacheSetHelper::NEWEST
, Cache
, P
);
495 pkgVersionMatch
Match(ver
, (verIsRel
== true ? pkgVersionMatch::Release
:
496 pkgVersionMatch::Version
));
498 if (V
.end() == true) {
499 if (verIsRel
== true)
500 _error
->Error(_("Release '%s' for '%s' was not found"),
501 ver
.c_str(), P
.FullName(true).c_str());
503 _error
->Error(_("Version '%s' for '%s' was not found"),
504 ver
.c_str(), P
.FullName(true).c_str());
510 if (verIsRel
== true)
511 helper
.showVersionSelection(P
, V
, CacheSetHelper::RELEASE
, ver
);
513 helper
.showVersionSelection(P
, V
, CacheSetHelper::VERSIONNUMBER
, ver
);
517 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
518 helper
.showErrors(errors
);
522 // FromPackage - versions from package based on fallback /*{{{*/
523 bool VersionContainerInterface::FromPackage(VersionContainerInterface
* const vci
,
525 pkgCache::PkgIterator
const &P
,
526 CacheSetHelper::VerSelector
const fallback
,
527 CacheSetHelper
&helper
) {
528 pkgCache::VerIterator V
;
532 case CacheSetHelper::ALL
:
533 if (P
->VersionList
!= 0)
534 for (V
= P
.VersionList(); V
.end() != true; ++V
)
535 found
|= vci
->insert(V
);
537 helper
.canNotFindVersion(CacheSetHelper::ALL
, vci
, Cache
, P
);
539 case CacheSetHelper::CANDANDINST
:
540 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
541 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
543 case CacheSetHelper::CANDIDATE
:
544 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
546 case CacheSetHelper::INSTALLED
:
547 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
549 case CacheSetHelper::CANDINST
:
550 showErrors
= helper
.showErrors(false);
551 V
= getCandidateVer(Cache
, P
, helper
);
553 V
= getInstalledVer(Cache
, P
, helper
);
554 helper
.showErrors(showErrors
);
555 if (V
.end() == false)
556 found
|= vci
->insert(V
);
558 helper
.canNotFindVersion(CacheSetHelper::CANDINST
, vci
, Cache
, P
);
560 case CacheSetHelper::INSTCAND
:
561 showErrors
= helper
.showErrors(false);
562 V
= getInstalledVer(Cache
, P
, helper
);
564 V
= getCandidateVer(Cache
, P
, helper
);
565 helper
.showErrors(showErrors
);
566 if (V
.end() == false)
567 found
|= vci
->insert(V
);
569 helper
.canNotFindVersion(CacheSetHelper::INSTCAND
, vci
, Cache
, P
);
571 case CacheSetHelper::NEWEST
:
572 if (P
->VersionList
!= 0)
573 found
|= vci
->insert(P
.VersionList());
575 helper
.canNotFindVersion(CacheSetHelper::NEWEST
, vci
, Cache
, P
);
577 case CacheSetHelper::RELEASE
:
578 case CacheSetHelper::VERSIONNUMBER
:
579 // both make no sense here, so always false
585 // FromDependency - versions satisfying a given dependency /*{{{*/
586 bool VersionContainerInterface::FromDependency(VersionContainerInterface
* const vci
,
588 pkgCache::DepIterator
const &D
,
589 CacheSetHelper::VerSelector
const selector
,
590 CacheSetHelper
&helper
)
594 case CacheSetHelper::ALL
:
596 pkgCache::PkgIterator
const T
= D
.TargetPkg();
597 for (pkgCache::VerIterator Ver
= T
.VersionList(); Ver
.end() == false; ++Ver
)
599 if (D
.IsSatisfied(Ver
) == true)
604 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
606 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
607 if (unlikely(V
.end() == true) || D
.IsSatisfied(Prv
) == false)
615 case CacheSetHelper::CANDANDINST
:
617 found
= FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
);
618 found
&= FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
);
621 case CacheSetHelper::CANDIDATE
:
623 pkgCache::PkgIterator
const T
= D
.TargetPkg();
624 pkgCache::VerIterator
const Cand
= Cache
[T
].CandidateVerIter(Cache
);
625 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
630 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
632 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
633 pkgCache::VerIterator
const Cand
= Cache
[Prv
.OwnerPkg()].CandidateVerIter(Cache
);
634 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
641 case CacheSetHelper::INSTALLED
:
643 pkgCache::PkgIterator
const T
= D
.TargetPkg();
644 pkgCache::VerIterator
const Cand
= T
.CurrentVer();
645 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
650 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
652 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
653 pkgCache::VerIterator
const Cand
= Prv
.OwnerPkg().CurrentVer();
654 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
661 case CacheSetHelper::CANDINST
:
662 return FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
) ||
663 FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
);
664 case CacheSetHelper::INSTCAND
:
665 return FromDependency(vci
, Cache
, D
, CacheSetHelper::INSTALLED
, helper
) ||
666 FromDependency(vci
, Cache
, D
, CacheSetHelper::CANDIDATE
, helper
);
667 case CacheSetHelper::NEWEST
:
669 pkgCache::PkgIterator
const T
= D
.TargetPkg();
670 pkgCache::VerIterator
const Cand
= T
.VersionList();
671 if (Cand
.end() == false && D
.IsSatisfied(Cand
) == true)
676 for (pkgCache::PrvIterator Prv
= T
.ProvidesList(); Prv
.end() != true; ++Prv
)
678 pkgCache::VerIterator
const V
= Prv
.OwnerVer();
679 pkgCache::VerIterator
const Cand
= Prv
.OwnerPkg().VersionList();
680 if (Cand
.end() == true || V
!= Cand
|| D
.IsSatisfied(Prv
) == false)
687 case CacheSetHelper::RELEASE
:
688 case CacheSetHelper::VERSIONNUMBER
:
689 // both make no sense here, so always false
695 // getCandidateVer - Returns the candidate version of the given package /*{{{*/
696 pkgCache::VerIterator
VersionContainerInterface::getCandidateVer(pkgCacheFile
&Cache
,
697 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
698 pkgCache::VerIterator Cand
;
699 if (Cache
.IsDepCacheBuilt() == true) {
700 Cand
= Cache
[Pkg
].CandidateVerIter(Cache
);
701 } else if (unlikely(Cache
.GetPolicy() == nullptr)) {
702 return pkgCache::VerIterator(Cache
);
704 Cand
= Cache
.GetPolicy()->GetCandidateVer(Pkg
);
706 if (Cand
.end() == true)
707 return helper
.canNotGetVersion(CacheSetHelper::CANDIDATE
, Cache
, Pkg
);
711 // getInstalledVer - Returns the installed version of the given package /*{{{*/
712 pkgCache::VerIterator
VersionContainerInterface::getInstalledVer(pkgCacheFile
&Cache
,
713 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
714 if (Pkg
->CurrentVer
== 0)
715 return helper
.canNotGetVersion(CacheSetHelper::INSTALLED
, Cache
, Pkg
);
716 return Pkg
.CurrentVer();
720 // canNotFindPackage - with the given selector and pattern /*{{{*/
721 void CacheSetHelper::canNotFindPackage(enum PkgSelector
const select
,
722 PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
723 std::string
const &pattern
) {
725 APT_IGNORE_DEPRECATED_PUSH
726 case REGEX
: canNotFindRegEx(pci
, Cache
, pattern
); break;
727 case TASK
: canNotFindTask(pci
, Cache
, pattern
); break;
728 case FNMATCH
: canNotFindFnmatch(pci
, Cache
, pattern
); break;
729 case PACKAGENAME
: canNotFindPackage(pci
, Cache
, pattern
); break;
730 case STRING
: canNotFindPackage(pci
, Cache
, pattern
); break;
732 APT_IGNORE_DEPRECATED_POP
735 // canNotFindTask - handle the case no package is found for a task /*{{{*/
736 void CacheSetHelper::canNotFindTask(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
737 if (ShowError
== true)
738 _error
->Insert(ErrorType
, _("Couldn't find task '%s'"), pattern
.c_str());
741 // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
742 void CacheSetHelper::canNotFindRegEx(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
743 if (ShowError
== true)
744 _error
->Insert(ErrorType
, _("Couldn't find any package by regex '%s'"), pattern
.c_str());
747 // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
748 void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
749 if (ShowError
== true)
750 _error
->Insert(ErrorType
, _("Couldn't find any package by glob '%s'"), pattern
.c_str());
753 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
754 APT_CONST
void CacheSetHelper::canNotFindPackage(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string
const &/*str*/) {
758 // canNotFindPkgName - handle the case no package has this name /*{{{*/
759 pkgCache::PkgIterator
CacheSetHelper::canNotFindPkgName(pkgCacheFile
&Cache
,
760 std::string
const &str
) {
761 if (ShowError
== true)
762 _error
->Insert(ErrorType
, _("Unable to locate package %s"), str
.c_str());
763 return pkgCache::PkgIterator(Cache
, 0);
766 // canNotFindVersion - for package by selector /*{{{*/
767 void CacheSetHelper::canNotFindVersion(enum VerSelector
const select
, VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
)
770 APT_IGNORE_DEPRECATED_PUSH
771 case ALL
: canNotFindAllVer(vci
, Cache
, Pkg
); break;
772 case INSTCAND
: canNotFindInstCandVer(vci
, Cache
, Pkg
); break;
773 case CANDINST
: canNotFindCandInstVer(vci
, Cache
, Pkg
); break;
774 case NEWEST
: canNotFindNewestVer(Cache
, Pkg
); break;
775 case CANDIDATE
: canNotFindCandidateVer(Cache
, Pkg
); break;
776 case INSTALLED
: canNotFindInstalledVer(Cache
, Pkg
); break;
777 APT_IGNORE_DEPRECATED_POP
778 case CANDANDINST
: canNotGetCandInstVer(Cache
, Pkg
); break;
781 // invalid in this branch
785 // canNotFindAllVer /*{{{*/
786 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&/*Cache*/,
787 pkgCache::PkgIterator
const &Pkg
) {
788 if (ShowError
== true)
789 _error
->Insert(ErrorType
, _("Can't select versions from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
792 // canNotFindInstCandVer /*{{{*/
793 void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
794 pkgCache::PkgIterator
const &Pkg
) {
795 canNotGetInstCandVer(Cache
, Pkg
);
798 // canNotFindInstCandVer /*{{{*/
799 void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
800 pkgCache::PkgIterator
const &Pkg
) {
801 canNotGetCandInstVer(Cache
, Pkg
);
805 // canNotGetVersion - for package by selector /*{{{*/
806 pkgCache::VerIterator
CacheSetHelper::canNotGetVersion(enum VerSelector
const select
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
808 APT_IGNORE_DEPRECATED_PUSH
809 case NEWEST
: return canNotFindNewestVer(Cache
, Pkg
);
810 case CANDIDATE
: return canNotFindCandidateVer(Cache
, Pkg
);
811 case INSTALLED
: return canNotFindInstalledVer(Cache
, Pkg
);
812 APT_IGNORE_DEPRECATED_POP
813 case CANDINST
: return canNotGetCandInstVer(Cache
, Pkg
);
814 case INSTCAND
: return canNotGetInstCandVer(Cache
, Pkg
);
819 // invalid in this branch
820 return pkgCache::VerIterator(Cache
, 0);
822 return pkgCache::VerIterator(Cache
, 0);
824 // canNotFindNewestVer /*{{{*/
825 pkgCache::VerIterator
CacheSetHelper::canNotFindNewestVer(pkgCacheFile
&Cache
,
826 pkgCache::PkgIterator
const &Pkg
) {
827 if (ShowError
== true)
828 _error
->Insert(ErrorType
, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
829 return pkgCache::VerIterator(Cache
, 0);
832 // canNotFindCandidateVer /*{{{*/
833 pkgCache::VerIterator
CacheSetHelper::canNotFindCandidateVer(pkgCacheFile
&Cache
,
834 pkgCache::PkgIterator
const &Pkg
) {
835 if (ShowError
== true)
836 _error
->Insert(ErrorType
, _("Can't select candidate version from package %s as it has no candidate"), Pkg
.FullName(true).c_str());
837 return pkgCache::VerIterator(Cache
, 0);
840 // canNotFindInstalledVer /*{{{*/
841 pkgCache::VerIterator
CacheSetHelper::canNotFindInstalledVer(pkgCacheFile
&Cache
,
842 pkgCache::PkgIterator
const &Pkg
) {
843 if (ShowError
== true)
844 _error
->Insert(ErrorType
, _("Can't select installed version from package %s as it is not installed"), Pkg
.FullName(true).c_str());
845 return pkgCache::VerIterator(Cache
, 0);
848 // canNotFindInstCandVer /*{{{*/
849 pkgCache::VerIterator
CacheSetHelper::canNotGetInstCandVer(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);
856 // canNotFindInstCandVer /*{{{*/
857 pkgCache::VerIterator
CacheSetHelper::canNotGetCandInstVer(pkgCacheFile
&Cache
,
858 pkgCache::PkgIterator
const &Pkg
) {
859 if (ShowError
== true)
860 _error
->Insert(ErrorType
, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg
.FullName(true).c_str());
861 return pkgCache::VerIterator(Cache
, 0);
865 // showPackageSelection - by selector and given pattern /*{{{*/
866 void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator
const &pkg
, enum PkgSelector
const select
,
867 std::string
const &pattern
) {
869 APT_IGNORE_DEPRECATED_PUSH
870 case REGEX
: showRegExSelection(pkg
, pattern
); break;
871 case TASK
: showTaskSelection(pkg
, pattern
); break;
872 case FNMATCH
: showFnmatchSelection(pkg
, pattern
); break;
873 APT_IGNORE_DEPRECATED_POP
874 case PACKAGENAME
: /* no suprises here */ break;
875 case STRING
: /* handled by the special cases */ break;
879 // showTaskSelection /*{{{*/
880 APT_CONST
void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator
const &/*pkg*/,
881 std::string
const &/*pattern*/) {
884 // showRegExSelection /*{{{*/
885 APT_CONST
void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator
const &/*pkg*/,
886 std::string
const &/*pattern*/) {
889 // showFnmatchSelection /*{{{*/
890 APT_CONST
void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator
const &/*pkg*/,
891 std::string
const &/*pattern*/) {
895 // showVersionSelection /*{{{*/
896 void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator
const &Pkg
,
897 pkgCache::VerIterator
const &Ver
, enum VerSelector
const select
, std::string
const &pattern
) {
899 APT_IGNORE_DEPRECATED_PUSH
901 showSelectedVersion(Pkg
, Ver
, pattern
, true);
904 showSelectedVersion(Pkg
, Ver
, pattern
, false);
906 APT_IGNORE_DEPRECATED_POP
914 // not really suprises, but in fact: just not implemented
918 APT_CONST
void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator
const &/*Pkg*/,
919 pkgCache::VerIterator
const /*Ver*/,
920 std::string
const &/*ver*/,
921 bool const /*verIsRel*/) {
925 CacheSetHelper::CacheSetHelper(bool const ShowError
, GlobalError::MsgType ErrorType
) :
926 ShowError(ShowError
), ErrorType(ErrorType
), d(NULL
) {}
927 CacheSetHelper::~CacheSetHelper() {}
929 PackageContainerInterface::PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN
), d(NULL
) {}
930 PackageContainerInterface::PackageContainerInterface(CacheSetHelper::PkgSelector
const by
) : ConstructedBy(by
), d(NULL
) {}
931 PackageContainerInterface
& PackageContainerInterface::operator=(PackageContainerInterface
const &other
) {
933 this->ConstructedBy
= other
.ConstructedBy
;
936 PackageContainerInterface::~PackageContainerInterface() {}
938 PackageUniverse::PackageUniverse(pkgCache
* const Owner
) : _cont(Owner
), d(NULL
) {}
939 PackageUniverse::PackageUniverse(pkgCacheFile
* const Owner
) : _cont(Owner
->GetPkgCache()), d(NULL
) {}
940 PackageUniverse::~PackageUniverse() {}
942 VersionContainerInterface::VersionContainerInterface() : d(NULL
) {}
943 VersionContainerInterface
& VersionContainerInterface::operator=(VersionContainerInterface
const &) {
947 VersionContainerInterface::~VersionContainerInterface() {}