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