]> git.saurik.com Git - apt.git/blob - apt-pkg/cacheset.cc
Merge remote-tracking branch 'mvo/feature/acq-trans' into debian/experimental
[apt.git] / apt-pkg / cacheset.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4
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.
8
9 ##################################################################### */
10 /*}}}*/
11 // Include Files /*{{{*/
12 #include <config.h>
13
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>
28
29 #include <stddef.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <regex.h>
33 #include <list>
34 #include <string>
35 #include <vector>
36
37 #include <apti18n.h>
38 /*}}}*/
39 namespace APT {
40
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) {
44 switch (select) {
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);
51 }
52 return false;
53 }
54 /*}}}*/
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);
62 }
63
64 if (pattern[pattern.length() -1] != '^')
65 return false;
66 pattern.erase(pattern.length()-1);
67
68 if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0))
69 return false;
70
71 bool const wasEmpty = pci->empty();
72 if (wasEmpty == true)
73 pci->setConstructor(CacheSetHelper::TASK);
74
75 // get the records
76 pkgRecords Recs(Cache);
77
78 // build regexp for the task
79 regex_t Pattern;
80 char S[300];
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");
84 return false;
85 }
86
87 bool found = false;
88 for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) {
89 pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
90 if (Pkg.end() == true)
91 continue;
92 pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache);
93 if(ver.end() == true)
94 continue;
95
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))
101 continue;
102 char buf[length];
103 strncpy(buf, start, length);
104 buf[length-1] = '\0';
105 if (regexec(&Pattern, buf, 0, 0, 0) != 0)
106 continue;
107
108 pci->insert(Pkg);
109 showPackageSelection(Pkg, CacheSetHelper::TASK, pattern);
110 found = true;
111 }
112 regfree(&Pattern);
113
114 if (found == false) {
115 canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern);
116 pci->setConstructor(CacheSetHelper::UNKNOWN);
117 return false;
118 }
119
120 if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
121 pci->setConstructor(CacheSetHelper::UNKNOWN);
122
123 return true;
124 }
125 /*}}}*/
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)
130 return false;
131
132 bool const wasEmpty = pci->empty();
133 if (wasEmpty == true)
134 pci->setConstructor(CacheSetHelper::REGEX);
135
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);
142 else
143 arch = "native";
144 }
145
146 if (unlikely(Cache.GetPkgCache() == 0))
147 return false;
148
149 APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern);
150
151 bool found = false;
152 for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) {
153 if (regexfilter(Grp) == false)
154 continue;
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);
162 }
163 if (Pkg.end() == true)
164 continue;
165 }
166
167 pci->insert(Pkg);
168 showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern);
169 found = true;
170 }
171
172 if (found == false) {
173 canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern);
174 pci->setConstructor(CacheSetHelper::UNKNOWN);
175 return false;
176 }
177
178 if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
179 pci->setConstructor(CacheSetHelper::UNKNOWN);
180
181 return true;
182 }
183 /*}}}*/
184 // PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/
185 bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci,
186 pkgCacheFile &Cache, std::string pattern)
187 {
188 static const char * const isfnmatch = ".?*[]!";
189 if (pattern.find_first_of(isfnmatch) == std::string::npos)
190 return false;
191
192 bool const wasEmpty = pci->empty();
193 if (wasEmpty == true)
194 pci->setConstructor(CacheSetHelper::FNMATCH);
195
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);
202 else
203 arch = "native";
204 }
205
206 if (unlikely(Cache.GetPkgCache() == 0))
207 return false;
208
209 APT::CacheFilter::PackageNameMatchesFnmatch filter(pattern);
210
211 bool found = false;
212 for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) {
213 if (filter(Grp) == false)
214 continue;
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);
222 }
223 if (Pkg.end() == true)
224 continue;
225 }
226
227 pci->insert(Pkg);
228 showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern);
229 found = true;
230 }
231
232 if (found == false) {
233 canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern);
234 pci->setConstructor(CacheSetHelper::UNKNOWN);
235 return false;
236 }
237
238 if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN)
239 pci->setConstructor(CacheSetHelper::UNKNOWN);
240
241 return true;
242 }
243 /*}}}*/
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(':');
249 std::string arch;
250 if (archfound != std::string::npos) {
251 arch = pkg.substr(archfound+1);
252 pkg.erase(archfound);
253 }
254
255 if (Cache.GetPkgCache() == 0)
256 return pkgCache::PkgIterator(Cache, 0);
257
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();
263 } else
264 Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch);
265
266 if (Pkg.end() == true)
267 return canNotFindPkgName(Cache, str);
268 return Pkg;
269 }
270 /*}}}*/
271 // PackageFromPackageName - Returns the package defined by this string /*{{{*/
272 bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache,
273 std::string pkg) {
274 if (unlikely(Cache.GetPkgCache() == 0))
275 return false;
276
277 size_t const archfound = pkg.find_last_of(':');
278 std::string arch;
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");
284 }
285
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)
291 {
292 pci->insert(Pkg);
293 return true;
294 }
295 } else {
296 bool found = 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)
302 continue;
303 pci->insert(Pkg);
304 found = true;
305 if (isGlobal == false)
306 break;
307 }
308 if (found == true)
309 return true;
310 }
311 }
312
313 pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkg);
314 if (Pkg.end() == true)
315 return false;
316
317 pci->insert(Pkg);
318 return true;
319 }
320 /*}}}*/
321 // PackageFromString - Return all packages matching a specific string /*{{{*/
322 bool CacheSetHelper::PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
323 bool found = true;
324 _error->PushToStack();
325
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)
331 {
332 canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str);
333 found = false;
334 }
335
336 if (found == true)
337 _error->RevertToStack();
338 else
339 _error->MergeWithStack();
340 return found;
341 }
342 /*}}}*/
343 // PackageFromCommandLine - Return all packages specified on commandline /*{{{*/
344 bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline) {
345 bool found = false;
346 for (const char **I = cmdline; *I != 0; ++I)
347 found |= PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, *I);
348 return found;
349 }
350 /*}}}*/
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);
361 switch(mod->Pos) {
362 case PkgModifier::POSTFIX:
363 if (str.compare(str.length() - alength, alength,
364 mod->Alias, 0, alength) != 0)
365 continue;
366 str.erase(str.length() - alength);
367 modID = mod->ID;
368 break;
369 case PkgModifier::PREFIX:
370 continue;
371 case PkgModifier::NONE:
372 continue;
373 }
374 modifierPresent = true;
375 break;
376 }
377 if (modifierPresent == true) {
378 bool const errors = showErrors(false);
379 bool const found = PackageFrom(PACKAGENAME, pci, Cache, cmdline);
380 showErrors(errors);
381 if (found == true) {
382 modID = fallback;
383 return true;
384 }
385 }
386 return PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str);
387 }
388 /*}}}*/
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))
398 return false;
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);
406 switch(mod->Pos) {
407 case Modifier::POSTFIX:
408 if (str.length() <= alength ||
409 str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
410 continue;
411 str.erase(str.length() - alength);
412 modID = mod->ID;
413 select = mod->SelectVersion;
414 break;
415 case Modifier::PREFIX:
416 continue;
417 case Modifier::NONE:
418 continue;
419 }
420 modifierPresent = true;
421 break;
422 }
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);
427 if (found == true) {
428 modID = fallback;
429 return true;
430 }
431 }
432 return FromString(vci, Cache, str, select, helper);
433 }
434 /*}}}*/
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) {
440 bool found = false;
441 for (const char **I = cmdline; *I != 0; ++I)
442 found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
443 return found;
444 }
445 /*}}}*/
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) {
452 PackageSet pkgset;
453 if(FileExists(pkg)) {
454 helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg);
455 if(pkgset.empty() == true)
456 return false;
457 return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper);
458 }
459
460 std::string ver;
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] == '/');
466 pkg.erase(vertag);
467 }
468 if (onlyFromName == false)
469 helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg);
470 else {
471 helper.PackageFrom(CacheSetHelper::PACKAGENAME, &pkgset, Cache, pkg);
472 }
473
474 bool errors = true;
475 if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
476 errors = helper.showErrors(false);
477
478 bool found = 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);
483 continue;
484 }
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)
492 V = P.VersionList();
493 else
494 V = helper.canNotGetVersion(CacheSetHelper::NEWEST, Cache, P);
495 } else {
496 pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
497 pkgVersionMatch::Version));
498 V = Match.Find(P);
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());
503 else
504 _error->Error(_("Version '%s' for '%s' was not found"),
505 ver.c_str(), P.FullName(true).c_str());
506 continue;
507 }
508 }
509 if (V.end() == true)
510 continue;
511 if (verIsRel == true)
512 helper.showVersionSelection(P, V, CacheSetHelper::RELEASE, ver);
513 else
514 helper.showVersionSelection(P, V, CacheSetHelper::VERSIONNUMBER, ver);
515 vci->insert(V);
516 found = true;
517 }
518 if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN)
519 helper.showErrors(errors);
520 return found;
521 }
522 /*}}}*/
523 // FromPackage - versions from package based on fallback /*{{{*/
524 bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
525 pkgCacheFile &Cache,
526 pkgCache::PkgIterator const &P,
527 CacheSetHelper::VerSelector const fallback,
528 CacheSetHelper &helper) {
529 pkgCache::VerIterator V;
530 bool showErrors;
531 bool found = false;
532 switch(fallback) {
533 case CacheSetHelper::ALL:
534 if (P->VersionList != 0)
535 for (V = P.VersionList(); V.end() != true; ++V)
536 found |= vci->insert(V);
537 else
538 helper.canNotFindVersion(CacheSetHelper::ALL, vci, Cache, P);
539 break;
540 case CacheSetHelper::CANDANDINST:
541 found |= vci->insert(getInstalledVer(Cache, P, helper));
542 found |= vci->insert(getCandidateVer(Cache, P, helper));
543 break;
544 case CacheSetHelper::CANDIDATE:
545 found |= vci->insert(getCandidateVer(Cache, P, helper));
546 break;
547 case CacheSetHelper::INSTALLED:
548 found |= vci->insert(getInstalledVer(Cache, P, helper));
549 break;
550 case CacheSetHelper::CANDINST:
551 showErrors = helper.showErrors(false);
552 V = getCandidateVer(Cache, P, helper);
553 if (V.end() == true)
554 V = getInstalledVer(Cache, P, helper);
555 helper.showErrors(showErrors);
556 if (V.end() == false)
557 found |= vci->insert(V);
558 else
559 helper.canNotFindVersion(CacheSetHelper::CANDINST, vci, Cache, P);
560 break;
561 case CacheSetHelper::INSTCAND:
562 showErrors = helper.showErrors(false);
563 V = getInstalledVer(Cache, P, helper);
564 if (V.end() == true)
565 V = getCandidateVer(Cache, P, helper);
566 helper.showErrors(showErrors);
567 if (V.end() == false)
568 found |= vci->insert(V);
569 else
570 helper.canNotFindVersion(CacheSetHelper::INSTCAND, vci, Cache, P);
571 break;
572 case CacheSetHelper::NEWEST:
573 if (P->VersionList != 0)
574 found |= vci->insert(P.VersionList());
575 else
576 helper.canNotFindVersion(CacheSetHelper::NEWEST, vci, Cache, P);
577 break;
578 case CacheSetHelper::RELEASE:
579 case CacheSetHelper::VERSIONNUMBER:
580 // both make no sense here, so always false
581 return false;
582 }
583 return found;
584 }
585 /*}}}*/
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);
594 } else {
595 Cand = Cache[Pkg].CandidateVerIter(Cache);
596 }
597 if (Cand.end() == true)
598 return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg);
599 return Cand;
600 }
601 /*}}}*/
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();
608 }
609 /*}}}*/
610
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) {
615 switch (select) {
616 #if __GNUC__ >= 4
617 #pragma GCC diagnostic push
618 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
619 #endif
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;
625 case UNKNOWN: break;
626 #if __GNUC__ >= 4
627 #pragma GCC diagnostic pop
628 #endif
629 }
630 }
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());
635 }
636 /*}}}*/
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());
641 }
642 /*}}}*/
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());
647 }
648 /*}}}*/
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*/) {
651 }
652 /*}}}*/
653 /*}}}*/
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);
660 }
661 /*}}}*/
662 // canNotFindVersion - for package by selector /*{{{*/
663 void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg)
664 {
665 switch (select) {
666 #if __GNUC__ >= 4
667 #pragma GCC diagnostic push
668 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
669 #endif
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;
676 #if __GNUC__ >= 4
677 #pragma GCC diagnostic pop
678 #endif
679 case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break;
680 case RELEASE:
681 case VERSIONNUMBER:
682 // invalid in this branch
683 break;
684 }
685 }
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());
691 }
692 /*}}}*/
693 // canNotFindInstCandVer /*{{{*/
694 void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
695 pkgCache::PkgIterator const &Pkg) {
696 canNotGetInstCandVer(Cache, Pkg);
697 }
698 /*}}}*/
699 // canNotFindInstCandVer /*{{{*/
700 void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
701 pkgCache::PkgIterator const &Pkg) {
702 canNotGetCandInstVer(Cache, Pkg);
703 }
704 /*}}}*/
705 /*}}}*/
706 // canNotGetVersion - for package by selector /*{{{*/
707 pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
708 switch (select) {
709 #if __GNUC__ >= 4
710 #pragma GCC diagnostic push
711 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
712 #endif
713 case NEWEST: return canNotFindNewestVer(Cache, Pkg);
714 case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg);
715 case INSTALLED: return canNotFindInstalledVer(Cache, Pkg);
716 #if __GNUC__ >= 4
717 #pragma GCC diagnostic pop
718 #endif
719 case CANDINST: return canNotGetCandInstVer(Cache, Pkg);
720 case INSTCAND: return canNotGetInstCandVer(Cache, Pkg);
721 case ALL:
722 case CANDANDINST:
723 case RELEASE:
724 case VERSIONNUMBER:
725 // invalid in this branch
726 return pkgCache::VerIterator(Cache, 0);
727 }
728 return pkgCache::VerIterator(Cache, 0);
729 }
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);
736 }
737 /*}}}*/
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);
744 }
745 /*}}}*/
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);
752 }
753 /*}}}*/
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);
760 }
761 /*}}}*/
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);
768 }
769 /*}}}*/
770 /*}}}*/
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) {
774 switch (select) {
775 #if __GNUC__ >= 4
776 #pragma GCC diagnostic push
777 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
778 #endif
779 case REGEX: showRegExSelection(pkg, pattern); break;
780 case TASK: showTaskSelection(pkg, pattern); break;
781 case FNMATCH: showFnmatchSelection(pkg, pattern); break;
782 #if __GNUC__ >= 4
783 #pragma GCC diagnostic pop
784 #endif
785 case PACKAGENAME: /* no suprises here */ break;
786 case STRING: /* handled by the special cases */ break;
787 case UNKNOWN: break;
788 }
789 }
790 // showTaskSelection /*{{{*/
791 APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
792 std::string const &/*pattern*/) {
793 }
794 /*}}}*/
795 // showRegExSelection /*{{{*/
796 APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
797 std::string const &/*pattern*/) {
798 }
799 /*}}}*/
800 // showFnmatchSelection /*{{{*/
801 APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
802 std::string const &/*pattern*/) {
803 }
804 /*}}}*/
805 /*}}}*/
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) {
809 switch (select) {
810 #if __GNUC__ >= 4
811 #pragma GCC diagnostic push
812 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
813 #endif
814 case RELEASE:
815 showSelectedVersion(Pkg, Ver, pattern, true);
816 break;
817 case VERSIONNUMBER:
818 showSelectedVersion(Pkg, Ver, pattern, false);
819 break;
820 #if __GNUC__ >= 4
821 #pragma GCC diagnostic pop
822 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
823 #endif
824 case NEWEST:
825 case CANDIDATE:
826 case INSTALLED:
827 case CANDINST:
828 case INSTCAND:
829 case ALL:
830 case CANDANDINST:
831 // not really suprises, but in fact: just not implemented
832 break;
833 }
834 }
835 APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
836 pkgCache::VerIterator const /*Ver*/,
837 std::string const &/*ver*/,
838 bool const /*verIsRel*/) {
839 }
840 /*}}}*/
841 }