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>
41 // PackageFrom - selecting the appropriate method for package selection /*{{{*/
42 bool CacheSetHelper::PackageFrom(enum PkgSelector
const select
, PackageContainerInterface
* const pci
,
43 pkgCacheFile
&Cache
, std::string
const &pattern
) {
45 case UNKNOWN
: return false;
46 case REGEX
: return PackageFromRegEx(pci
, Cache
, pattern
);
47 case TASK
: return PackageFromTask(pci
, Cache
, pattern
);
48 case FNMATCH
: return PackageFromFnmatch(pci
, Cache
, pattern
);
49 case PACKAGENAME
: return PackageFromPackageName(pci
, Cache
, pattern
);
50 case STRING
: return PackageFromString(pci
, Cache
, pattern
);
55 // PackageFromTask - Return all packages in the cache from a specific task /*{{{*/
56 bool CacheSetHelper::PackageFromTask(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
) {
57 size_t const archfound
= pattern
.find_last_of(':');
58 std::string arch
= "native";
59 if (archfound
!= std::string::npos
) {
60 arch
= pattern
.substr(archfound
+1);
61 pattern
.erase(archfound
);
64 if (pattern
[pattern
.length() -1] != '^')
66 pattern
.erase(pattern
.length()-1);
68 if (unlikely(Cache
.GetPkgCache() == 0 || Cache
.GetDepCache() == 0))
71 bool const wasEmpty
= pci
->empty();
73 pci
->setConstructor(CacheSetHelper::TASK
);
76 pkgRecords
Recs(Cache
);
78 // build regexp for the task
81 snprintf(S
, sizeof(S
), "^Task:.*[, ]%s([, ]|$)", pattern
.c_str());
82 if(regcomp(&Pattern
,S
, REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
) != 0) {
83 _error
->Error("Failed to compile task regexp");
88 for (pkgCache::GrpIterator Grp
= Cache
->GrpBegin(); Grp
.end() == false; ++Grp
) {
89 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
90 if (Pkg
.end() == true)
92 pkgCache::VerIterator ver
= Cache
[Pkg
].CandidateVerIter(Cache
);
96 pkgRecords::Parser
&parser
= Recs
.Lookup(ver
.FileList());
97 const char *start
, *end
;
98 parser
.GetRec(start
,end
);
99 unsigned int const length
= end
- start
;
100 if (unlikely(length
== 0))
103 strncpy(buf
, start
, length
);
104 buf
[length
-1] = '\0';
105 if (regexec(&Pattern
, buf
, 0, 0, 0) != 0)
109 showPackageSelection(Pkg
, CacheSetHelper::TASK
, pattern
);
114 if (found
== false) {
115 canNotFindPackage(CacheSetHelper::TASK
, pci
, Cache
, pattern
);
116 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
120 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
121 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
126 // PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/
127 bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string pattern
) {
128 static const char * const isregex
= ".?+*|[^$";
129 if (pattern
.find_first_of(isregex
) == std::string::npos
)
132 bool const wasEmpty
= pci
->empty();
133 if (wasEmpty
== true)
134 pci
->setConstructor(CacheSetHelper::REGEX
);
136 size_t archfound
= pattern
.find_last_of(':');
137 std::string arch
= "native";
138 if (archfound
!= std::string::npos
) {
139 arch
= pattern
.substr(archfound
+1);
140 if (arch
.find_first_of(isregex
) == std::string::npos
)
141 pattern
.erase(archfound
);
146 if (unlikely(Cache
.GetPkgCache() == 0))
149 APT::CacheFilter::PackageNameMatchesRegEx
regexfilter(pattern
);
152 for (pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->GrpBegin(); Grp
.end() == false; ++Grp
) {
153 if (regexfilter(Grp
) == false)
155 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
156 if (Pkg
.end() == true) {
157 if (archfound
== std::string::npos
) {
158 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
159 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
160 a
!= archs
.end() && Pkg
.end() != true; ++a
)
161 Pkg
= Grp
.FindPkg(*a
);
163 if (Pkg
.end() == true)
168 showPackageSelection(Pkg
, CacheSetHelper::REGEX
, pattern
);
172 if (found
== false) {
173 canNotFindPackage(CacheSetHelper::REGEX
, pci
, Cache
, pattern
);
174 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
178 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
179 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
184 // PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/
185 bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface
* const pci
,
186 pkgCacheFile
&Cache
, std::string pattern
)
188 static const char * const isfnmatch
= ".?*[]!";
189 if (pattern
.find_first_of(isfnmatch
) == std::string::npos
)
192 bool const wasEmpty
= pci
->empty();
193 if (wasEmpty
== true)
194 pci
->setConstructor(CacheSetHelper::FNMATCH
);
196 size_t archfound
= pattern
.find_last_of(':');
197 std::string arch
= "native";
198 if (archfound
!= std::string::npos
) {
199 arch
= pattern
.substr(archfound
+1);
200 if (arch
.find_first_of(isfnmatch
) == std::string::npos
)
201 pattern
.erase(archfound
);
206 if (unlikely(Cache
.GetPkgCache() == 0))
209 APT::CacheFilter::PackageNameMatchesFnmatch
filter(pattern
);
212 for (pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->GrpBegin(); Grp
.end() == false; ++Grp
) {
213 if (filter(Grp
) == false)
215 pkgCache::PkgIterator Pkg
= Grp
.FindPkg(arch
);
216 if (Pkg
.end() == true) {
217 if (archfound
== std::string::npos
) {
218 std::vector
<std::string
> archs
= APT::Configuration::getArchitectures();
219 for (std::vector
<std::string
>::const_iterator a
= archs
.begin();
220 a
!= archs
.end() && Pkg
.end() != true; ++a
)
221 Pkg
= Grp
.FindPkg(*a
);
223 if (Pkg
.end() == true)
228 showPackageSelection(Pkg
, CacheSetHelper::FNMATCH
, pattern
);
232 if (found
== false) {
233 canNotFindPackage(CacheSetHelper::FNMATCH
, pci
, Cache
, pattern
);
234 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
238 if (wasEmpty
== false && pci
->getConstructor() != CacheSetHelper::UNKNOWN
)
239 pci
->setConstructor(CacheSetHelper::UNKNOWN
);
244 // PackageFromName - Returns the package defined by this string /*{{{*/
245 pkgCache::PkgIterator
CacheSetHelper::PackageFromName(pkgCacheFile
&Cache
,
246 std::string
const &str
) {
247 std::string pkg
= str
;
248 size_t archfound
= pkg
.find_last_of(':');
250 if (archfound
!= std::string::npos
) {
251 arch
= pkg
.substr(archfound
+1);
252 pkg
.erase(archfound
);
255 if (Cache
.GetPkgCache() == 0)
256 return pkgCache::PkgIterator(Cache
, 0);
258 pkgCache::PkgIterator
Pkg(Cache
, 0);
259 if (arch
.empty() == true) {
260 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
261 if (Grp
.end() == false)
262 Pkg
= Grp
.FindPreferredPkg();
264 Pkg
= Cache
.GetPkgCache()->FindPkg(pkg
, arch
);
266 if (Pkg
.end() == true)
267 return canNotFindPkgName(Cache
, str
);
271 // PackageFromPackageName - Returns the package defined by this string /*{{{*/
272 bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
274 if (unlikely(Cache
.GetPkgCache() == 0))
277 size_t const archfound
= pkg
.find_last_of(':');
279 if (archfound
!= std::string::npos
) {
280 arch
= pkg
.substr(archfound
+1);
281 pkg
.erase(archfound
);
282 if (arch
== "all" || arch
== "native")
283 arch
= _config
->Find("APT::Architecture");
286 pkgCache::GrpIterator Grp
= Cache
.GetPkgCache()->FindGrp(pkg
);
287 if (Grp
.end() == false) {
288 if (arch
.empty() == true) {
289 pkgCache::PkgIterator Pkg
= Grp
.FindPreferredPkg();
290 if (Pkg
.end() == false)
297 // for 'linux-any' return the first package matching, for 'linux-*' return all matches
298 bool const isGlobal
= arch
.find('*') != std::string::npos
;
299 APT::CacheFilter::PackageArchitectureMatchesSpecification
pams(arch
);
300 for (pkgCache::PkgIterator Pkg
= Grp
.PackageList(); Pkg
.end() == false; Pkg
= Grp
.NextPkg(Pkg
)) {
301 if (pams(Pkg
) == false)
305 if (isGlobal
== false)
313 pkgCache::PkgIterator Pkg
= canNotFindPkgName(Cache
, pkg
);
314 if (Pkg
.end() == true)
321 // PackageFromString - Return all packages matching a specific string /*{{{*/
322 bool CacheSetHelper::PackageFromString(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, std::string
const &str
) {
324 _error
->PushToStack();
326 if (PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
) == false &&
327 PackageFrom(CacheSetHelper::TASK
, pci
, Cache
, str
) == false &&
328 // FIXME: hm, hm, regexp/fnmatch incompatible?
329 PackageFrom(CacheSetHelper::FNMATCH
, pci
, Cache
, str
) == false &&
330 PackageFrom(CacheSetHelper::REGEX
, pci
, Cache
, str
) == false)
332 canNotFindPackage(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
337 _error
->RevertToStack();
339 _error
->MergeWithStack();
343 // PackageFromCommandLine - Return all packages specified on commandline /*{{{*/
344 bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
, const char **cmdline
) {
346 for (const char **I
= cmdline
; *I
!= 0; ++I
)
347 found
|= PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, *I
);
351 // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
352 bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID
, PackageContainerInterface
* const pci
,
353 pkgCacheFile
&Cache
, const char * cmdline
,
354 std::list
<PkgModifier
> const &mods
) {
355 std::string str
= cmdline
;
356 unsigned short fallback
= modID
;
357 bool modifierPresent
= false;
358 for (std::list
<PkgModifier
>::const_iterator mod
= mods
.begin();
359 mod
!= mods
.end(); ++mod
) {
360 size_t const alength
= strlen(mod
->Alias
);
362 case PkgModifier::POSTFIX
:
363 if (str
.compare(str
.length() - alength
, alength
,
364 mod
->Alias
, 0, alength
) != 0)
366 str
.erase(str
.length() - alength
);
369 case PkgModifier::PREFIX
:
371 case PkgModifier::NONE
:
374 modifierPresent
= true;
377 if (modifierPresent
== true) {
378 bool const errors
= showErrors(false);
379 bool const found
= PackageFrom(PACKAGENAME
, pci
, Cache
, cmdline
);
386 return PackageFrom(CacheSetHelper::PACKAGENAME
, pci
, Cache
, str
);
389 // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
390 bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID
,
391 VersionContainerInterface
* const vci
,
392 pkgCacheFile
&Cache
, const char * cmdline
,
393 std::list
<Modifier
> const &mods
,
394 CacheSetHelper
&helper
) {
395 CacheSetHelper::VerSelector select
= CacheSetHelper::NEWEST
;
396 std::string str
= cmdline
;
397 if (unlikely(str
.empty() == true))
399 bool modifierPresent
= false;
400 unsigned short fallback
= modID
;
401 for (std::list
<Modifier
>::const_iterator mod
= mods
.begin();
402 mod
!= mods
.end(); ++mod
) {
403 if (modID
== fallback
&& mod
->ID
== fallback
)
404 select
= mod
->SelectVersion
;
405 size_t const alength
= strlen(mod
->Alias
);
407 case Modifier::POSTFIX
:
408 if (str
.length() <= alength
||
409 str
.compare(str
.length() - alength
, alength
, mod
->Alias
, 0, alength
) != 0)
411 str
.erase(str
.length() - alength
);
413 select
= mod
->SelectVersion
;
415 case Modifier::PREFIX
:
420 modifierPresent
= true;
423 if (modifierPresent
== true) {
424 bool const errors
= helper
.showErrors(false);
425 bool const found
= VersionContainerInterface::FromString(vci
, Cache
, cmdline
, select
, helper
, true);
426 helper
.showErrors(errors
);
432 return FromString(vci
, Cache
, str
, select
, helper
);
435 // FromCommandLine - Return all versions specified on commandline /*{{{*/
436 bool VersionContainerInterface::FromCommandLine(VersionContainerInterface
* const vci
,
437 pkgCacheFile
&Cache
, const char **cmdline
,
438 CacheSetHelper::VerSelector
const fallback
,
439 CacheSetHelper
&helper
) {
441 for (const char **I
= cmdline
; *I
!= 0; ++I
)
442 found
|= VersionContainerInterface::FromString(vci
, Cache
, *I
, fallback
, helper
);
446 // FromString - Returns all versions spedcified by a string /*{{{*/
447 bool VersionContainerInterface::FromString(VersionContainerInterface
* const vci
,
448 pkgCacheFile
&Cache
, std::string pkg
,
449 CacheSetHelper::VerSelector
const fallback
,
450 CacheSetHelper
&helper
,
451 bool const onlyFromName
) {
453 if(FileExists(pkg
)) {
454 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
455 if(pkgset
.empty() == true)
457 return VersionContainerInterface::FromPackage(vci
, Cache
, pkgset
.begin(), fallback
, helper
);
461 bool verIsRel
= false;
462 size_t const vertag
= pkg
.find_last_of("/=");
463 if (vertag
!= std::string::npos
) {
464 ver
= pkg
.substr(vertag
+1);
465 verIsRel
= (pkg
[vertag
] == '/');
468 if (onlyFromName
== false)
469 helper
.PackageFrom(CacheSetHelper::STRING
, &pkgset
, Cache
, pkg
);
471 helper
.PackageFrom(CacheSetHelper::PACKAGENAME
, &pkgset
, Cache
, pkg
);
475 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
476 errors
= helper
.showErrors(false);
479 for (PackageSet::const_iterator P
= pkgset
.begin();
480 P
!= pkgset
.end(); ++P
) {
481 if (vertag
== std::string::npos
) {
482 found
|= VersionContainerInterface::FromPackage(vci
, Cache
, P
, fallback
, helper
);
485 pkgCache::VerIterator V
;
486 if (ver
== "installed")
487 V
= getInstalledVer(Cache
, P
, helper
);
488 else if (ver
== "candidate")
489 V
= getCandidateVer(Cache
, P
, helper
);
490 else if (ver
== "newest") {
491 if (P
->VersionList
!= 0)
494 V
= helper
.canNotGetVersion(CacheSetHelper::NEWEST
, Cache
, P
);
496 pkgVersionMatch
Match(ver
, (verIsRel
== true ? pkgVersionMatch::Release
:
497 pkgVersionMatch::Version
));
499 if (V
.end() == true) {
500 if (verIsRel
== true)
501 _error
->Error(_("Release '%s' for '%s' was not found"),
502 ver
.c_str(), P
.FullName(true).c_str());
504 _error
->Error(_("Version '%s' for '%s' was not found"),
505 ver
.c_str(), P
.FullName(true).c_str());
511 if (verIsRel
== true)
512 helper
.showVersionSelection(P
, V
, CacheSetHelper::RELEASE
, ver
);
514 helper
.showVersionSelection(P
, V
, CacheSetHelper::VERSIONNUMBER
, ver
);
518 if (pkgset
.getConstructor() != CacheSetHelper::UNKNOWN
)
519 helper
.showErrors(errors
);
523 // FromPackage - versions from package based on fallback /*{{{*/
524 bool VersionContainerInterface::FromPackage(VersionContainerInterface
* const vci
,
526 pkgCache::PkgIterator
const &P
,
527 CacheSetHelper::VerSelector
const fallback
,
528 CacheSetHelper
&helper
) {
529 pkgCache::VerIterator V
;
533 case CacheSetHelper::ALL
:
534 if (P
->VersionList
!= 0)
535 for (V
= P
.VersionList(); V
.end() != true; ++V
)
536 found
|= vci
->insert(V
);
538 helper
.canNotFindVersion(CacheSetHelper::ALL
, vci
, Cache
, P
);
540 case CacheSetHelper::CANDANDINST
:
541 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
542 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
544 case CacheSetHelper::CANDIDATE
:
545 found
|= vci
->insert(getCandidateVer(Cache
, P
, helper
));
547 case CacheSetHelper::INSTALLED
:
548 found
|= vci
->insert(getInstalledVer(Cache
, P
, helper
));
550 case CacheSetHelper::CANDINST
:
551 showErrors
= helper
.showErrors(false);
552 V
= getCandidateVer(Cache
, P
, helper
);
554 V
= getInstalledVer(Cache
, P
, helper
);
555 helper
.showErrors(showErrors
);
556 if (V
.end() == false)
557 found
|= vci
->insert(V
);
559 helper
.canNotFindVersion(CacheSetHelper::CANDINST
, vci
, Cache
, P
);
561 case CacheSetHelper::INSTCAND
:
562 showErrors
= helper
.showErrors(false);
563 V
= getInstalledVer(Cache
, P
, helper
);
565 V
= getCandidateVer(Cache
, P
, helper
);
566 helper
.showErrors(showErrors
);
567 if (V
.end() == false)
568 found
|= vci
->insert(V
);
570 helper
.canNotFindVersion(CacheSetHelper::INSTCAND
, vci
, Cache
, P
);
572 case CacheSetHelper::NEWEST
:
573 if (P
->VersionList
!= 0)
574 found
|= vci
->insert(P
.VersionList());
576 helper
.canNotFindVersion(CacheSetHelper::NEWEST
, vci
, Cache
, P
);
578 case CacheSetHelper::RELEASE
:
579 case CacheSetHelper::VERSIONNUMBER
:
580 // both make no sense here, so always false
586 // getCandidateVer - Returns the candidate version of the given package /*{{{*/
587 pkgCache::VerIterator
VersionContainerInterface::getCandidateVer(pkgCacheFile
&Cache
,
588 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
589 pkgCache::VerIterator Cand
;
590 if (Cache
.IsPolicyBuilt() == true || Cache
.IsDepCacheBuilt() == false) {
591 if (unlikely(Cache
.GetPolicy() == 0))
592 return pkgCache::VerIterator(Cache
);
593 Cand
= Cache
.GetPolicy()->GetCandidateVer(Pkg
);
595 Cand
= Cache
[Pkg
].CandidateVerIter(Cache
);
597 if (Cand
.end() == true)
598 return helper
.canNotGetVersion(CacheSetHelper::CANDIDATE
, Cache
, Pkg
);
602 // getInstalledVer - Returns the installed version of the given package /*{{{*/
603 pkgCache::VerIterator
VersionContainerInterface::getInstalledVer(pkgCacheFile
&Cache
,
604 pkgCache::PkgIterator
const &Pkg
, CacheSetHelper
&helper
) {
605 if (Pkg
->CurrentVer
== 0)
606 return helper
.canNotGetVersion(CacheSetHelper::INSTALLED
, Cache
, Pkg
);
607 return Pkg
.CurrentVer();
611 // canNotFindPackage - with the given selector and pattern /*{{{*/
612 void CacheSetHelper::canNotFindPackage(enum PkgSelector
const select
,
613 PackageContainerInterface
* const pci
, pkgCacheFile
&Cache
,
614 std::string
const &pattern
) {
617 #pragma GCC diagnostic push
618 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
620 case REGEX
: canNotFindRegEx(pci
, Cache
, pattern
); break;
621 case TASK
: canNotFindTask(pci
, Cache
, pattern
); break;
622 case FNMATCH
: canNotFindFnmatch(pci
, Cache
, pattern
); break;
623 case PACKAGENAME
: canNotFindPackage(pci
, Cache
, pattern
); break;
624 case STRING
: canNotFindPackage(pci
, Cache
, pattern
); break;
627 #pragma GCC diagnostic pop
631 // canNotFindTask - handle the case no package is found for a task /*{{{*/
632 void CacheSetHelper::canNotFindTask(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
633 if (ShowError
== true)
634 _error
->Insert(ErrorType
, _("Couldn't find task '%s'"), pattern
.c_str());
637 // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
638 void CacheSetHelper::canNotFindRegEx(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
639 if (ShowError
== true)
640 _error
->Insert(ErrorType
, _("Couldn't find any package by regex '%s'"), pattern
.c_str());
643 // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
644 void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string pattern
) {
645 if (ShowError
== true)
646 _error
->Insert(ErrorType
, _("Couldn't find any package by glob '%s'"), pattern
.c_str());
649 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
650 APT_CONST
void CacheSetHelper::canNotFindPackage(PackageContainerInterface
* const /*pci*/, pkgCacheFile
&/*Cache*/, std::string
const &/*str*/) {
654 // canNotFindPkgName - handle the case no package has this name /*{{{*/
655 pkgCache::PkgIterator
CacheSetHelper::canNotFindPkgName(pkgCacheFile
&Cache
,
656 std::string
const &str
) {
657 if (ShowError
== true)
658 _error
->Insert(ErrorType
, _("Unable to locate package %s"), str
.c_str());
659 return pkgCache::PkgIterator(Cache
, 0);
662 // canNotFindVersion - for package by selector /*{{{*/
663 void CacheSetHelper::canNotFindVersion(enum VerSelector
const select
, VersionContainerInterface
* const vci
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
)
667 #pragma GCC diagnostic push
668 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
670 case ALL
: canNotFindAllVer(vci
, Cache
, Pkg
); break;
671 case INSTCAND
: canNotFindInstCandVer(vci
, Cache
, Pkg
); break;
672 case CANDINST
: canNotFindCandInstVer(vci
, Cache
, Pkg
); break;
673 case NEWEST
: canNotFindNewestVer(Cache
, Pkg
); break;
674 case CANDIDATE
: canNotFindCandidateVer(Cache
, Pkg
); break;
675 case INSTALLED
: canNotFindInstalledVer(Cache
, Pkg
); break;
677 #pragma GCC diagnostic pop
679 case CANDANDINST
: canNotGetCandInstVer(Cache
, Pkg
); break;
682 // invalid in this branch
686 // canNotFindAllVer /*{{{*/
687 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&/*Cache*/,
688 pkgCache::PkgIterator
const &Pkg
) {
689 if (ShowError
== true)
690 _error
->Insert(ErrorType
, _("Can't select versions from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
693 // canNotFindInstCandVer /*{{{*/
694 void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
695 pkgCache::PkgIterator
const &Pkg
) {
696 canNotGetInstCandVer(Cache
, Pkg
);
699 // canNotFindInstCandVer /*{{{*/
700 void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface
* const /*vci*/, pkgCacheFile
&Cache
,
701 pkgCache::PkgIterator
const &Pkg
) {
702 canNotGetCandInstVer(Cache
, Pkg
);
706 // canNotGetVersion - for package by selector /*{{{*/
707 pkgCache::VerIterator
CacheSetHelper::canNotGetVersion(enum VerSelector
const select
, pkgCacheFile
&Cache
, pkgCache::PkgIterator
const &Pkg
) {
710 #pragma GCC diagnostic push
711 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
713 case NEWEST
: return canNotFindNewestVer(Cache
, Pkg
);
714 case CANDIDATE
: return canNotFindCandidateVer(Cache
, Pkg
);
715 case INSTALLED
: return canNotFindInstalledVer(Cache
, Pkg
);
717 #pragma GCC diagnostic pop
719 case CANDINST
: return canNotGetCandInstVer(Cache
, Pkg
);
720 case INSTCAND
: return canNotGetInstCandVer(Cache
, Pkg
);
725 // invalid in this branch
726 return pkgCache::VerIterator(Cache
, 0);
728 return pkgCache::VerIterator(Cache
, 0);
730 // canNotFindNewestVer /*{{{*/
731 pkgCache::VerIterator
CacheSetHelper::canNotFindNewestVer(pkgCacheFile
&Cache
,
732 pkgCache::PkgIterator
const &Pkg
) {
733 if (ShowError
== true)
734 _error
->Insert(ErrorType
, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg
.FullName(true).c_str());
735 return pkgCache::VerIterator(Cache
, 0);
738 // canNotFindCandidateVer /*{{{*/
739 pkgCache::VerIterator
CacheSetHelper::canNotFindCandidateVer(pkgCacheFile
&Cache
,
740 pkgCache::PkgIterator
const &Pkg
) {
741 if (ShowError
== true)
742 _error
->Insert(ErrorType
, _("Can't select candidate version from package %s as it has no candidate"), Pkg
.FullName(true).c_str());
743 return pkgCache::VerIterator(Cache
, 0);
746 // canNotFindInstalledVer /*{{{*/
747 pkgCache::VerIterator
CacheSetHelper::canNotFindInstalledVer(pkgCacheFile
&Cache
,
748 pkgCache::PkgIterator
const &Pkg
) {
749 if (ShowError
== true)
750 _error
->Insert(ErrorType
, _("Can't select installed version from package %s as it is not installed"), Pkg
.FullName(true).c_str());
751 return pkgCache::VerIterator(Cache
, 0);
754 // canNotFindInstCandVer /*{{{*/
755 pkgCache::VerIterator
CacheSetHelper::canNotGetInstCandVer(pkgCacheFile
&Cache
,
756 pkgCache::PkgIterator
const &Pkg
) {
757 if (ShowError
== true)
758 _error
->Insert(ErrorType
, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg
.FullName(true).c_str());
759 return pkgCache::VerIterator(Cache
, 0);
762 // canNotFindInstCandVer /*{{{*/
763 pkgCache::VerIterator
CacheSetHelper::canNotGetCandInstVer(pkgCacheFile
&Cache
,
764 pkgCache::PkgIterator
const &Pkg
) {
765 if (ShowError
== true)
766 _error
->Insert(ErrorType
, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg
.FullName(true).c_str());
767 return pkgCache::VerIterator(Cache
, 0);
771 // showPackageSelection - by selector and given pattern /*{{{*/
772 APT_CONST
void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator
const &pkg
, enum PkgSelector
const select
,
773 std::string
const &pattern
) {
776 #pragma GCC diagnostic push
777 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
779 case REGEX
: showRegExSelection(pkg
, pattern
); break;
780 case TASK
: showTaskSelection(pkg
, pattern
); break;
781 case FNMATCH
: showFnmatchSelection(pkg
, pattern
); break;
783 #pragma GCC diagnostic pop
785 case PACKAGENAME
: /* no suprises here */ break;
786 case STRING
: /* handled by the special cases */ break;
790 // showTaskSelection /*{{{*/
791 APT_CONST
void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator
const &/*pkg*/,
792 std::string
const &/*pattern*/) {
795 // showRegExSelection /*{{{*/
796 APT_CONST
void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator
const &/*pkg*/,
797 std::string
const &/*pattern*/) {
800 // showFnmatchSelection /*{{{*/
801 APT_CONST
void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator
const &/*pkg*/,
802 std::string
const &/*pattern*/) {
806 // showVersionSelection /*{{{*/
807 APT_CONST
void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator
const &Pkg
,
808 pkgCache::VerIterator
const &Ver
, enum VerSelector
const select
, std::string
const &pattern
) {
811 #pragma GCC diagnostic push
812 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
815 showSelectedVersion(Pkg
, Ver
, pattern
, true);
818 showSelectedVersion(Pkg
, Ver
, pattern
, false);
821 #pragma GCC diagnostic pop
822 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
831 // not really suprises, but in fact: just not implemented
835 APT_CONST
void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator
const &/*Pkg*/,
836 pkgCache::VerIterator
const /*Ver*/,
837 std::string
const &/*ver*/,
838 bool const /*verIsRel*/) {