]> git.saurik.com Git - apt.git/blame - apt-pkg/cacheset.cc
cleanup, fix test-apt-update-unauth as the behavior of apt changed
[apt.git] / apt-pkg / cacheset.cc
CommitLineData
ffee1c2b
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
5 Simple wrapper around a std::set to provide a similar interface to
7959c5ed
DK
6 a set of cache structures as to the complete set of all structures
7 in the pkgCache. Currently only Package is supported.
ffee1c2b
DK
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include <config.h>
13
78c32596 14#include <apt-pkg/aptconfiguration.h>
472ff00e 15#include <apt-pkg/cachefile.h>
9ba5aa3b 16#include <apt-pkg/cachefilter.h>
8fde7239 17#include <apt-pkg/cacheset.h>
ffee1c2b 18#include <apt-pkg/error.h>
856d3b06 19#include <apt-pkg/versionmatch.h>
472ff00e
DK
20#include <apt-pkg/pkgrecords.h>
21#include <apt-pkg/policy.h>
453b82a3
DK
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>
fdff5b03 27#include <apt-pkg/fileutl.h>
ffee1c2b 28
453b82a3
DK
29#include <stddef.h>
30#include <stdio.h>
31#include <string.h>
ffee1c2b 32#include <regex.h>
453b82a3
DK
33#include <list>
34#include <string>
35#include <vector>
ea542140
DK
36
37#include <apti18n.h>
ffee1c2b
DK
38 /*}}}*/
39namespace APT {
dc0f01f7 40// FromTask - Return all packages in the cache from a specific task /*{{{*/
15fc8636 41bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
bd631595 42 size_t const archfound = pattern.find_last_of(':');
dc0f01f7
DK
43 std::string arch = "native";
44 if (archfound != std::string::npos) {
45 arch = pattern.substr(archfound+1);
46 pattern.erase(archfound);
47 }
48
49 if (pattern[pattern.length() -1] != '^')
15fc8636 50 return false;
dc0f01f7
DK
51 pattern.erase(pattern.length()-1);
52
bd631595 53 if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0))
15fc8636
DK
54 return false;
55
56 bool const wasEmpty = pci->empty();
57 if (wasEmpty == true)
58 pci->setConstructor(TASK);
bd631595 59
dc0f01f7
DK
60 // get the records
61 pkgRecords Recs(Cache);
62
63 // build regexp for the task
64 regex_t Pattern;
65 char S[300];
66 snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str());
67 if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) {
68 _error->Error("Failed to compile task regexp");
15fc8636 69 return false;
dc0f01f7
DK
70 }
71
15fc8636 72 bool found = false;
dc0f01f7
DK
73 for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) {
74 pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
75 if (Pkg.end() == true)
76 continue;
77 pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache);
78 if(ver.end() == true)
79 continue;
80
81 pkgRecords::Parser &parser = Recs.Lookup(ver.FileList());
82 const char *start, *end;
83 parser.GetRec(start,end);
84 unsigned int const length = end - start;
62d8a765
DK
85 if (unlikely(length == 0))
86 continue;
dc0f01f7
DK
87 char buf[length];
88 strncpy(buf, start, length);
89 buf[length-1] = '\0';
70e706ad
DK
90 if (regexec(&Pattern, buf, 0, 0, 0) != 0)
91 continue;
92
15fc8636
DK
93 pci->insert(Pkg);
94 helper.showTaskSelection(Pkg, pattern);
95 found = true;
dc0f01f7 96 }
70e706ad 97 regfree(&Pattern);
dc0f01f7 98
15fc8636
DK
99 if (found == false) {
100 helper.canNotFindTask(pci, Cache, pattern);
101 pci->setConstructor(UNKNOWN);
102 return false;
103 }
104
105 if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
106 pci->setConstructor(UNKNOWN);
dc0f01f7 107
15fc8636 108 return true;
dc0f01f7
DK
109}
110 /*}}}*/
ffee1c2b 111// FromRegEx - Return all packages in the cache matching a pattern /*{{{*/
15fc8636 112bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) {
6e235c66 113 static const char * const isregex = ".?+*|[^$";
6e235c66 114 if (pattern.find_first_of(isregex) == std::string::npos)
15fc8636
DK
115 return false;
116
117 bool const wasEmpty = pci->empty();
118 if (wasEmpty == true)
119 pci->setConstructor(REGEX);
ffee1c2b 120
6e235c66 121 size_t archfound = pattern.find_last_of(':');
dc0f01f7 122 std::string arch = "native";
6e235c66
DK
123 if (archfound != std::string::npos) {
124 arch = pattern.substr(archfound+1);
125 if (arch.find_first_of(isregex) == std::string::npos)
126 pattern.erase(archfound);
127 else
128 arch = "native";
129 }
130
bd631595 131 if (unlikely(Cache.GetPkgCache() == 0))
15fc8636 132 return false;
bd631595 133
9ba5aa3b
DK
134 APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern);
135
15fc8636 136 bool found = false;
9ba5aa3b
DK
137 for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) {
138 if (regexfilter(Grp) == false)
ffee1c2b 139 continue;
6e235c66 140 pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
78c32596 141 if (Pkg.end() == true) {
6e235c66
DK
142 if (archfound == std::string::npos) {
143 std::vector<std::string> archs = APT::Configuration::getArchitectures();
144 for (std::vector<std::string>::const_iterator a = archs.begin();
145 a != archs.end() && Pkg.end() != true; ++a)
146 Pkg = Grp.FindPkg(*a);
78c32596
DK
147 }
148 if (Pkg.end() == true)
149 continue;
150 }
ffee1c2b 151
15fc8636
DK
152 pci->insert(Pkg);
153 helper.showRegExSelection(Pkg, pattern);
154 found = true;
ffee1c2b 155 }
ffee1c2b 156
15fc8636
DK
157 if (found == false) {
158 helper.canNotFindRegEx(pci, Cache, pattern);
159 pci->setConstructor(UNKNOWN);
160 return false;
161 }
162
b9179170
MV
163 if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
164 pci->setConstructor(UNKNOWN);
165
166 return true;
167}
168 /*}}}*/
169// FromFnmatch - Returns the package defined by this fnmatch /*{{{*/
170bool
171PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci,
172 pkgCacheFile &Cache,
173 std::string pattern,
174 CacheSetHelper &helper)
175{
176 static const char * const isfnmatch = ".?*[]!";
177 if (pattern.find_first_of(isfnmatch) == std::string::npos)
178 return false;
179
180 bool const wasEmpty = pci->empty();
181 if (wasEmpty == true)
182 pci->setConstructor(FNMATCH);
183
184 size_t archfound = pattern.find_last_of(':');
185 std::string arch = "native";
186 if (archfound != std::string::npos) {
187 arch = pattern.substr(archfound+1);
188 if (arch.find_first_of(isfnmatch) == std::string::npos)
189 pattern.erase(archfound);
190 else
191 arch = "native";
192 }
193
194 if (unlikely(Cache.GetPkgCache() == 0))
195 return false;
196
197 APT::CacheFilter::PackageNameMatchesFnmatch filter(pattern);
198
199 bool found = false;
200 for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) {
201 if (filter(Grp) == false)
202 continue;
203 pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
204 if (Pkg.end() == true) {
205 if (archfound == std::string::npos) {
206 std::vector<std::string> archs = APT::Configuration::getArchitectures();
207 for (std::vector<std::string>::const_iterator a = archs.begin();
208 a != archs.end() && Pkg.end() != true; ++a)
209 Pkg = Grp.FindPkg(*a);
210 }
211 if (Pkg.end() == true)
212 continue;
213 }
214
215 pci->insert(Pkg);
16724b66
MV
216#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
217 helper.showFnmatchSelection(Pkg, pattern);
218#else
b9179170 219 helper.showRegExSelection(Pkg, pattern);
16724b66 220#endif
b9179170
MV
221 found = true;
222 }
223
224 if (found == false) {
16724b66
MV
225#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
226 helper.canNotFindFnmatch(pci, Cache, pattern);
227#else
228 helper.canNotFindRegEx(pci, Cache, pattern);
229#endif
b9179170
MV
230 pci->setConstructor(UNKNOWN);
231 return false;
232 }
233
15fc8636
DK
234 if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
235 pci->setConstructor(UNKNOWN);
70e706ad 236
15fc8636 237 return true;
78c32596
DK
238}
239 /*}}}*/
bd631595 240// FromName - Returns the package defined by this string /*{{{*/
15fc8636 241pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache,
bd631595
DK
242 std::string const &str, CacheSetHelper &helper) {
243 std::string pkg = str;
244 size_t archfound = pkg.find_last_of(':');
245 std::string arch;
246 if (archfound != std::string::npos) {
247 arch = pkg.substr(archfound+1);
248 pkg.erase(archfound);
249 }
250
251 if (Cache.GetPkgCache() == 0)
252 return pkgCache::PkgIterator(Cache, 0);
253
254 pkgCache::PkgIterator Pkg(Cache, 0);
255 if (arch.empty() == true) {
256 pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
257 if (Grp.end() == false)
258 Pkg = Grp.FindPreferredPkg();
259 } else
260 Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch);
261
262 if (Pkg.end() == true)
263 return helper.canNotFindPkgName(Cache, str);
264 return Pkg;
265}
266 /*}}}*/
2f0d4029
DK
267// FromGroup - Returns the package defined by this string /*{{{*/
268bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache,
269 std::string pkg, CacheSetHelper &helper) {
270 if (unlikely(Cache.GetPkgCache() == 0))
271 return false;
272
273 size_t const archfound = pkg.find_last_of(':');
274 std::string arch;
275 if (archfound != std::string::npos) {
276 arch = pkg.substr(archfound+1);
277 pkg.erase(archfound);
f1d86c0e
DK
278 if (arch == "all" || arch == "native")
279 arch = _config->Find("APT::Architecture");
2f0d4029
DK
280 }
281
282 pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
283 if (Grp.end() == false) {
284 if (arch.empty() == true) {
285 pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg();
286 if (Pkg.end() == false)
287 {
288 pci->insert(Pkg);
289 return true;
290 }
291 } else {
292 bool found = false;
293 // for 'linux-any' return the first package matching, for 'linux-*' return all matches
294 bool const isGlobal = arch.find('*') != std::string::npos;
295 APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch);
296 for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) {
297 if (pams(Pkg) == false)
298 continue;
299 pci->insert(Pkg);
300 found = true;
301 if (isGlobal == false)
302 break;
303 }
304 if (found == true)
305 return true;
306 }
307 }
308
309 pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg);
310 if (Pkg.end() == true)
311 return false;
312
313 pci->insert(Pkg);
314 return true;
315}
316 /*}}}*/
856d3b06 317// FromString - Return all packages matching a specific string /*{{{*/
15fc8636
DK
318bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
319 bool found = true;
48c39e32
DK
320 _error->PushToStack();
321
2f0d4029
DK
322 if (FromGroup(pci, Cache, str, helper) == false &&
323 FromTask(pci, Cache, str, helper) == false &&
7e75a619 324#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
b58f28d4
MV
325 // FIXME: hm, hm, regexp/fnmatch incompatible?
326 FromFnmatch(pci, Cache, str, helper) == false &&
7e75a619 327#endif
15fc8636
DK
328 FromRegEx(pci, Cache, str, helper) == false)
329 {
330 helper.canNotFindPackage(pci, Cache, str);
331 found = false;
48c39e32 332 }
dc0f01f7 333
15fc8636 334 if (found == true)
48c39e32
DK
335 _error->RevertToStack();
336 else
337 _error->MergeWithStack();
15fc8636 338 return found;
856d3b06
DK
339}
340 /*}}}*/
15fc8636
DK
341// FromCommandLine - Return all packages specified on commandline /*{{{*/
342bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
343 bool found = false;
344 for (const char **I = cmdline; *I != 0; ++I)
345 found |= PackageContainerInterface::FromString(pci, Cache, *I, helper);
346 return found;
347}
348 /*}}}*/
349// FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
350bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
351 pkgCacheFile &Cache, const char * cmdline,
352 std::list<Modifier> const &mods, CacheSetHelper &helper) {
353 std::string str = cmdline;
e6a12579 354 unsigned short fallback = modID;
15fc8636
DK
355 bool modifierPresent = false;
356 for (std::list<Modifier>::const_iterator mod = mods.begin();
357 mod != mods.end(); ++mod) {
358 size_t const alength = strlen(mod->Alias);
359 switch(mod->Pos) {
360 case Modifier::POSTFIX:
361 if (str.compare(str.length() - alength, alength,
362 mod->Alias, 0, alength) != 0)
55c59998 363 continue;
15fc8636
DK
364 str.erase(str.length() - alength);
365 modID = mod->ID;
55c59998 366 break;
15fc8636
DK
367 case Modifier::PREFIX:
368 continue;
369 case Modifier::NONE:
370 continue;
55c59998 371 }
15fc8636
DK
372 modifierPresent = true;
373 break;
374 }
375 if (modifierPresent == true) {
376 bool const errors = helper.showErrors(false);
377 pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper);
378 helper.showErrors(errors);
379 if (Pkg.end() == false) {
380 pci->insert(Pkg);
e6a12579 381 modID = fallback;
15fc8636
DK
382 return true;
383 }
384 }
385 return FromString(pci, Cache, str, helper);
386}
387 /*}}}*/
388// FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
389bool 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 Version select = NEWEST;
395 std::string str = cmdline;
d99854ca
DK
396 if (unlikely(str.empty() == true))
397 return false;
15fc8636
DK
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);
405 switch(mod->Pos) {
406 case Modifier::POSTFIX:
d99854ca
DK
407 if (str.length() <= alength ||
408 str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
bd631595 409 continue;
15fc8636
DK
410 str.erase(str.length() - alength);
411 modID = mod->ID;
412 select = mod->SelectVersion;
413 break;
414 case Modifier::PREFIX:
415 continue;
416 case Modifier::NONE:
417 continue;
bd631595 418 }
15fc8636
DK
419 modifierPresent = true;
420 break;
55c59998 421 }
15fc8636
DK
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);
e6a12579
DK
426 if (found == true) {
427 modID = fallback;
15fc8636 428 return true;
e6a12579 429 }
15fc8636
DK
430 }
431 return FromString(vci, Cache, str, select, helper);
55c59998
DK
432}
433 /*}}}*/
856d3b06 434// FromCommandLine - Return all versions specified on commandline /*{{{*/
15fc8636
DK
435bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci,
436 pkgCacheFile &Cache, const char **cmdline,
437 Version const &fallback, CacheSetHelper &helper) {
438 bool found = false;
bd631595 439 for (const char **I = cmdline; *I != 0; ++I)
15fc8636
DK
440 found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
441 return found;
55c59998
DK
442}
443 /*}}}*/
444// FromString - Returns all versions spedcified by a string /*{{{*/
15fc8636
DK
445bool VersionContainerInterface::FromString(VersionContainerInterface * const vci,
446 pkgCacheFile &Cache, std::string pkg,
447 Version const &fallback, CacheSetHelper &helper,
448 bool const onlyFromName) {
fdff5b03
MV
449 PackageSet pkgset;
450 if(FileExists(pkg))
451 {
452 PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
9c3e15ab
MV
453 if(pkgset.size() == 0)
454 return false;
fdff5b03
MV
455 return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper);
456 }
457
55c59998
DK
458 std::string ver;
459 bool verIsRel = false;
460 size_t const vertag = pkg.find_last_of("/=");
472ff00e 461 if (vertag != std::string::npos) {
55c59998
DK
462 ver = pkg.substr(vertag+1);
463 verIsRel = (pkg[vertag] == '/');
464 pkg.erase(vertag);
465 }
bd631595 466 if (onlyFromName == false)
15fc8636 467 PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
bd631595 468 else {
15fc8636 469 pkgset.insert(PackageContainerInterface::FromName(Cache, pkg, helper));
bd631595
DK
470 }
471
c8db3fff
DK
472 bool errors = true;
473 if (pkgset.getConstructor() != PackageSet::UNKNOWN)
474 errors = helper.showErrors(false);
15fc8636
DK
475
476 bool found = false;
55c59998
DK
477 for (PackageSet::const_iterator P = pkgset.begin();
478 P != pkgset.end(); ++P) {
472ff00e 479 if (vertag == std::string::npos) {
15fc8636 480 found |= VersionContainerInterface::FromPackage(vci, Cache, P, fallback, helper);
55c59998 481 continue;
856d3b06 482 }
55c59998
DK
483 pkgCache::VerIterator V;
484 if (ver == "installed")
70e706ad 485 V = getInstalledVer(Cache, P, helper);
55c59998 486 else if (ver == "candidate")
70e706ad 487 V = getCandidateVer(Cache, P, helper);
f1a58ff8
DK
488 else if (ver == "newest") {
489 if (P->VersionList != 0)
490 V = P.VersionList();
491 else
492 V = helper.canNotFindNewestVer(Cache, P);
493 } else {
55c59998
DK
494 pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
495 pkgVersionMatch::Version));
496 V = Match.Find(P);
497 if (V.end() == true) {
498 if (verIsRel == true)
499 _error->Error(_("Release '%s' for '%s' was not found"),
500 ver.c_str(), P.FullName(true).c_str());
501 else
502 _error->Error(_("Version '%s' for '%s' was not found"),
503 ver.c_str(), P.FullName(true).c_str());
84910ad5
DK
504 continue;
505 }
78c32596 506 }
55c59998
DK
507 if (V.end() == true)
508 continue;
70e706ad 509 helper.showSelectedVersion(P, V, ver, verIsRel);
15fc8636
DK
510 vci->insert(V);
511 found = true;
78c32596 512 }
c8db3fff
DK
513 if (pkgset.getConstructor() != PackageSet::UNKNOWN)
514 helper.showErrors(errors);
15fc8636 515 return found;
856d3b06
DK
516}
517 /*}}}*/
fb83c1d0 518// FromPackage - versions from package based on fallback /*{{{*/
15fc8636
DK
519bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
520 pkgCacheFile &Cache,
521 pkgCache::PkgIterator const &P,
522 Version const &fallback,
523 CacheSetHelper &helper) {
84910ad5 524 pkgCache::VerIterator V;
70e706ad 525 bool showErrors;
15fc8636 526 bool found = false;
84910ad5 527 switch(fallback) {
15fc8636 528 case ALL:
84910ad5
DK
529 if (P->VersionList != 0)
530 for (V = P.VersionList(); V.end() != true; ++V)
15fc8636 531 found |= vci->insert(V);
84910ad5 532 else
15fc8636 533 helper.canNotFindAllVer(vci, Cache, P);
84910ad5 534 break;
15fc8636
DK
535 case CANDANDINST:
536 found |= vci->insert(getInstalledVer(Cache, P, helper));
537 found |= vci->insert(getCandidateVer(Cache, P, helper));
84910ad5 538 break;
15fc8636
DK
539 case CANDIDATE:
540 found |= vci->insert(getCandidateVer(Cache, P, helper));
84910ad5 541 break;
15fc8636
DK
542 case INSTALLED:
543 found |= vci->insert(getInstalledVer(Cache, P, helper));
84910ad5 544 break;
15fc8636 545 case CANDINST:
70e706ad
DK
546 showErrors = helper.showErrors(false);
547 V = getCandidateVer(Cache, P, helper);
84910ad5 548 if (V.end() == true)
70e706ad
DK
549 V = getInstalledVer(Cache, P, helper);
550 helper.showErrors(showErrors);
84910ad5 551 if (V.end() == false)
15fc8636 552 found |= vci->insert(V);
84910ad5 553 else
15fc8636 554 helper.canNotFindInstCandVer(vci, Cache, P);
84910ad5 555 break;
15fc8636 556 case INSTCAND:
70e706ad
DK
557 showErrors = helper.showErrors(false);
558 V = getInstalledVer(Cache, P, helper);
84910ad5 559 if (V.end() == true)
70e706ad
DK
560 V = getCandidateVer(Cache, P, helper);
561 helper.showErrors(showErrors);
84910ad5 562 if (V.end() == false)
15fc8636 563 found |= vci->insert(V);
84910ad5 564 else
15fc8636 565 helper.canNotFindInstCandVer(vci, Cache, P);
84910ad5 566 break;
15fc8636 567 case NEWEST:
84910ad5 568 if (P->VersionList != 0)
15fc8636 569 found |= vci->insert(P.VersionList());
84910ad5 570 else
15fc8636 571 helper.canNotFindNewestVer(Cache, P);
84910ad5
DK
572 break;
573 }
15fc8636 574 return found;
84910ad5
DK
575}
576 /*}}}*/
856d3b06 577// getCandidateVer - Returns the candidate version of the given package /*{{{*/
15fc8636 578pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache,
70e706ad 579 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
a8ef7efd 580 pkgCache::VerIterator Cand;
15fc8636 581 if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) {
bd631595
DK
582 if (unlikely(Cache.GetPolicy() == 0))
583 return pkgCache::VerIterator(Cache);
a8ef7efd 584 Cand = Cache.GetPolicy()->GetCandidateVer(Pkg);
2fbfb111
DK
585 } else {
586 Cand = Cache[Pkg].CandidateVerIter(Cache);
a8ef7efd 587 }
70e706ad
DK
588 if (Cand.end() == true)
589 return helper.canNotFindCandidateVer(Cache, Pkg);
856d3b06
DK
590 return Cand;
591}
592 /*}}}*/
593// getInstalledVer - Returns the installed version of the given package /*{{{*/
15fc8636 594pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache,
70e706ad
DK
595 pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
596 if (Pkg->CurrentVer == 0)
597 return helper.canNotFindInstalledVer(Cache, Pkg);
856d3b06 598 return Pkg.CurrentVer();
ffee1c2b
DK
599}
600 /*}}}*/
15fc8636 601
bd631595
DK
602// canNotFindPkgName - handle the case no package has this name /*{{{*/
603pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
604 std::string const &str) {
605 if (ShowError == true)
cd7bbc47 606 _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
bd631595
DK
607 return pkgCache::PkgIterator(Cache, 0);
608}
609 /*}}}*/
70e706ad 610// canNotFindTask - handle the case no package is found for a task /*{{{*/
65512241 611void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
70e706ad 612 if (ShowError == true)
cd7bbc47 613 _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
70e706ad
DK
614}
615 /*}}}*/
616// canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
65512241 617void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
70e706ad 618 if (ShowError == true)
cd7bbc47 619 _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
70e706ad 620}
16724b66
MV
621#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
622// canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
b58f28d4 623 void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
16724b66
MV
624 if (ShowError == true)
625 _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
626}
627#endif /*}}}*/
70e706ad 628// canNotFindPackage - handle the case no package is found from a string/*{{{*/
a02db58f 629APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
70e706ad
DK
630}
631 /*}}}*/
632// canNotFindAllVer /*{{{*/
65512241 633void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
70e706ad
DK
634 pkgCache::PkgIterator const &Pkg) {
635 if (ShowError == true)
edc0ef10 636 _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
70e706ad
DK
637}
638 /*}}}*/
639// canNotFindInstCandVer /*{{{*/
65512241 640void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
70e706ad
DK
641 pkgCache::PkgIterator const &Pkg) {
642 if (ShowError == true)
cd7bbc47 643 _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
70e706ad
DK
644}
645 /*}}}*/
cf28bcad 646// canNotFindInstCandVer /*{{{*/
65512241 647void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
cf28bcad
DK
648 pkgCache::PkgIterator const &Pkg) {
649 if (ShowError == true)
cd7bbc47 650 _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
cf28bcad
DK
651}
652 /*}}}*/
70e706ad
DK
653// canNotFindNewestVer /*{{{*/
654pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
655 pkgCache::PkgIterator const &Pkg) {
656 if (ShowError == true)
cd7bbc47 657 _error->Insert(ErrorType, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
c8db3fff 658 return pkgCache::VerIterator(Cache, 0);
70e706ad
DK
659}
660 /*}}}*/
661// canNotFindCandidateVer /*{{{*/
662pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache,
663 pkgCache::PkgIterator const &Pkg) {
664 if (ShowError == true)
cd7bbc47 665 _error->Insert(ErrorType, _("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str());
c8db3fff 666 return pkgCache::VerIterator(Cache, 0);
70e706ad
DK
667}
668 /*}}}*/
669// canNotFindInstalledVer /*{{{*/
670pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache,
671 pkgCache::PkgIterator const &Pkg) {
672 if (ShowError == true)
cd7bbc47 673 _error->Insert(ErrorType, _("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str());
c8db3fff 674 return pkgCache::VerIterator(Cache, 0);
70e706ad
DK
675}
676 /*}}}*/
15fc8636 677// showTaskSelection /*{{{*/
a02db58f 678APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
65512241 679 std::string const &/*pattern*/) {
15fc8636
DK
680}
681 /*}}}*/
682// showRegExSelection /*{{{*/
a02db58f 683APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
65512241 684 std::string const &/*pattern*/) {
15fc8636
DK
685}
686 /*}}}*/
16724b66
MV
687#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
688// showFnmatchSelection /*{{{*/
b58f28d4
MV
689APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
690 std::string const &/*pattern*/) {
16724b66
MV
691}
692 /*}}}*/
693#endif
15fc8636 694// showSelectedVersion /*{{{*/
a02db58f 695APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
65512241
DK
696 pkgCache::VerIterator const /*Ver*/,
697 std::string const &/*ver*/,
698 bool const /*verIsRel*/) {
15fc8636
DK
699}
700 /*}}}*/
ffee1c2b 701}