]> git.saurik.com Git - apt.git/blob - apt-pkg/cacheset.cc
Merge branch 'debian/sid' 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 APT_IGNORE_DEPRECATED_PUSH
617 case REGEX: canNotFindRegEx(pci, Cache, pattern); break;
618 case TASK: canNotFindTask(pci, Cache, pattern); break;
619 case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break;
620 case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break;
621 case STRING: canNotFindPackage(pci, Cache, pattern); break;
622 case UNKNOWN: break;
623 APT_IGNORE_DEPRECATED_POP
624 }
625 }
626 // canNotFindTask - handle the case no package is found for a task /*{{{*/
627 void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
628 if (ShowError == true)
629 _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
630 }
631 /*}}}*/
632 // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
633 void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
634 if (ShowError == true)
635 _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
636 }
637 /*}}}*/
638 // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
639 void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) {
640 if (ShowError == true)
641 _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
642 }
643 /*}}}*/
644 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
645 APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
646 }
647 /*}}}*/
648 /*}}}*/
649 // canNotFindPkgName - handle the case no package has this name /*{{{*/
650 pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
651 std::string const &str) {
652 if (ShowError == true)
653 _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
654 return pkgCache::PkgIterator(Cache, 0);
655 }
656 /*}}}*/
657 // canNotFindVersion - for package by selector /*{{{*/
658 void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg)
659 {
660 switch (select) {
661 APT_IGNORE_DEPRECATED_PUSH
662 case ALL: canNotFindAllVer(vci, Cache, Pkg); break;
663 case INSTCAND: canNotFindInstCandVer(vci, Cache, Pkg); break;
664 case CANDINST: canNotFindCandInstVer(vci, Cache, Pkg); break;
665 case NEWEST: canNotFindNewestVer(Cache, Pkg); break;
666 case CANDIDATE: canNotFindCandidateVer(Cache, Pkg); break;
667 case INSTALLED: canNotFindInstalledVer(Cache, Pkg); break;
668 APT_IGNORE_DEPRECATED_POP
669 case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break;
670 case RELEASE:
671 case VERSIONNUMBER:
672 // invalid in this branch
673 break;
674 }
675 }
676 // canNotFindAllVer /*{{{*/
677 void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/,
678 pkgCache::PkgIterator const &Pkg) {
679 if (ShowError == true)
680 _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
681 }
682 /*}}}*/
683 // canNotFindInstCandVer /*{{{*/
684 void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
685 pkgCache::PkgIterator const &Pkg) {
686 canNotGetInstCandVer(Cache, Pkg);
687 }
688 /*}}}*/
689 // canNotFindInstCandVer /*{{{*/
690 void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache,
691 pkgCache::PkgIterator const &Pkg) {
692 canNotGetCandInstVer(Cache, Pkg);
693 }
694 /*}}}*/
695 /*}}}*/
696 // canNotGetVersion - for package by selector /*{{{*/
697 pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
698 switch (select) {
699 APT_IGNORE_DEPRECATED_PUSH
700 case NEWEST: return canNotFindNewestVer(Cache, Pkg);
701 case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg);
702 case INSTALLED: return canNotFindInstalledVer(Cache, Pkg);
703 APT_IGNORE_DEPRECATED_POP
704 case CANDINST: return canNotGetCandInstVer(Cache, Pkg);
705 case INSTCAND: return canNotGetInstCandVer(Cache, Pkg);
706 case ALL:
707 case CANDANDINST:
708 case RELEASE:
709 case VERSIONNUMBER:
710 // invalid in this branch
711 return pkgCache::VerIterator(Cache, 0);
712 }
713 return pkgCache::VerIterator(Cache, 0);
714 }
715 // canNotFindNewestVer /*{{{*/
716 pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
717 pkgCache::PkgIterator const &Pkg) {
718 if (ShowError == true)
719 _error->Insert(ErrorType, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
720 return pkgCache::VerIterator(Cache, 0);
721 }
722 /*}}}*/
723 // canNotFindCandidateVer /*{{{*/
724 pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache,
725 pkgCache::PkgIterator const &Pkg) {
726 if (ShowError == true)
727 _error->Insert(ErrorType, _("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str());
728 return pkgCache::VerIterator(Cache, 0);
729 }
730 /*}}}*/
731 // canNotFindInstalledVer /*{{{*/
732 pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache,
733 pkgCache::PkgIterator const &Pkg) {
734 if (ShowError == true)
735 _error->Insert(ErrorType, _("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str());
736 return pkgCache::VerIterator(Cache, 0);
737 }
738 /*}}}*/
739 // canNotFindInstCandVer /*{{{*/
740 pkgCache::VerIterator CacheSetHelper::canNotGetInstCandVer(pkgCacheFile &Cache,
741 pkgCache::PkgIterator const &Pkg) {
742 if (ShowError == true)
743 _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
744 return pkgCache::VerIterator(Cache, 0);
745 }
746 /*}}}*/
747 // canNotFindInstCandVer /*{{{*/
748 pkgCache::VerIterator CacheSetHelper::canNotGetCandInstVer(pkgCacheFile &Cache,
749 pkgCache::PkgIterator const &Pkg) {
750 if (ShowError == true)
751 _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
752 return pkgCache::VerIterator(Cache, 0);
753 }
754 /*}}}*/
755 /*}}}*/
756 // showPackageSelection - by selector and given pattern /*{{{*/
757 void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const &pkg, enum PkgSelector const select,
758 std::string const &pattern) {
759 switch (select) {
760 APT_IGNORE_DEPRECATED_PUSH
761 case REGEX: showRegExSelection(pkg, pattern); break;
762 case TASK: showTaskSelection(pkg, pattern); break;
763 case FNMATCH: showFnmatchSelection(pkg, pattern); break;
764 APT_IGNORE_DEPRECATED_POP
765 case PACKAGENAME: /* no suprises here */ break;
766 case STRING: /* handled by the special cases */ break;
767 case UNKNOWN: break;
768 }
769 }
770 // showTaskSelection /*{{{*/
771 APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
772 std::string const &/*pattern*/) {
773 }
774 /*}}}*/
775 // showRegExSelection /*{{{*/
776 APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
777 std::string const &/*pattern*/) {
778 }
779 /*}}}*/
780 // showFnmatchSelection /*{{{*/
781 APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/,
782 std::string const &/*pattern*/) {
783 }
784 /*}}}*/
785 /*}}}*/
786 // showVersionSelection /*{{{*/
787 void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator const &Pkg,
788 pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern) {
789 switch (select) {
790 APT_IGNORE_DEPRECATED_PUSH
791 case RELEASE:
792 showSelectedVersion(Pkg, Ver, pattern, true);
793 break;
794 case VERSIONNUMBER:
795 showSelectedVersion(Pkg, Ver, pattern, false);
796 break;
797 APT_IGNORE_DEPRECATED_POP
798 case NEWEST:
799 case CANDIDATE:
800 case INSTALLED:
801 case CANDINST:
802 case INSTCAND:
803 case ALL:
804 case CANDANDINST:
805 // not really suprises, but in fact: just not implemented
806 break;
807 }
808 }
809 APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
810 pkgCache::VerIterator const /*Ver*/,
811 std::string const &/*ver*/,
812 bool const /*verIsRel*/) {
813 }
814 /*}}}*/
815 }