]>
Commit | Line | Data |
---|---|---|
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 | /*}}}*/ |
30 | namespace APT { | |
dc0f01f7 | 31 | // FromTask - Return all packages in the cache from a specific task /*{{{*/ |
15fc8636 | 32 | bool 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 | 101 | bool 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 | ||
152 | if (wasEmpty == false && pci->getConstructor() != UNKNOWN) | |
153 | pci->setConstructor(UNKNOWN); | |
70e706ad | 154 | |
15fc8636 | 155 | return true; |
78c32596 DK |
156 | } |
157 | /*}}}*/ | |
bd631595 | 158 | // FromName - Returns the package defined by this string /*{{{*/ |
15fc8636 | 159 | pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache, |
bd631595 DK |
160 | std::string const &str, CacheSetHelper &helper) { |
161 | std::string pkg = str; | |
162 | size_t archfound = pkg.find_last_of(':'); | |
163 | std::string arch; | |
164 | if (archfound != std::string::npos) { | |
165 | arch = pkg.substr(archfound+1); | |
166 | pkg.erase(archfound); | |
167 | } | |
168 | ||
169 | if (Cache.GetPkgCache() == 0) | |
170 | return pkgCache::PkgIterator(Cache, 0); | |
171 | ||
172 | pkgCache::PkgIterator Pkg(Cache, 0); | |
173 | if (arch.empty() == true) { | |
174 | pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); | |
175 | if (Grp.end() == false) | |
176 | Pkg = Grp.FindPreferredPkg(); | |
177 | } else | |
178 | Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); | |
179 | ||
180 | if (Pkg.end() == true) | |
181 | return helper.canNotFindPkgName(Cache, str); | |
182 | return Pkg; | |
183 | } | |
184 | /*}}}*/ | |
2f0d4029 DK |
185 | // FromGroup - Returns the package defined by this string /*{{{*/ |
186 | bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, | |
187 | std::string pkg, CacheSetHelper &helper) { | |
188 | if (unlikely(Cache.GetPkgCache() == 0)) | |
189 | return false; | |
190 | ||
191 | size_t const archfound = pkg.find_last_of(':'); | |
192 | std::string arch; | |
193 | if (archfound != std::string::npos) { | |
194 | arch = pkg.substr(archfound+1); | |
195 | pkg.erase(archfound); | |
196 | } | |
197 | ||
198 | pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); | |
199 | if (Grp.end() == false) { | |
200 | if (arch.empty() == true) { | |
201 | pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg(); | |
202 | if (Pkg.end() == false) | |
203 | { | |
204 | pci->insert(Pkg); | |
205 | return true; | |
206 | } | |
207 | } else { | |
208 | bool found = false; | |
209 | // for 'linux-any' return the first package matching, for 'linux-*' return all matches | |
210 | bool const isGlobal = arch.find('*') != std::string::npos; | |
211 | APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch); | |
212 | for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) { | |
213 | if (pams(Pkg) == false) | |
214 | continue; | |
215 | pci->insert(Pkg); | |
216 | found = true; | |
217 | if (isGlobal == false) | |
218 | break; | |
219 | } | |
220 | if (found == true) | |
221 | return true; | |
222 | } | |
223 | } | |
224 | ||
225 | pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg); | |
226 | if (Pkg.end() == true) | |
227 | return false; | |
228 | ||
229 | pci->insert(Pkg); | |
230 | return true; | |
231 | } | |
232 | /*}}}*/ | |
856d3b06 | 233 | // FromString - Return all packages matching a specific string /*{{{*/ |
15fc8636 DK |
234 | bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { |
235 | bool found = true; | |
48c39e32 DK |
236 | _error->PushToStack(); |
237 | ||
2f0d4029 DK |
238 | if (FromGroup(pci, Cache, str, helper) == false && |
239 | FromTask(pci, Cache, str, helper) == false && | |
15fc8636 DK |
240 | FromRegEx(pci, Cache, str, helper) == false) |
241 | { | |
242 | helper.canNotFindPackage(pci, Cache, str); | |
243 | found = false; | |
48c39e32 | 244 | } |
dc0f01f7 | 245 | |
15fc8636 | 246 | if (found == true) |
48c39e32 DK |
247 | _error->RevertToStack(); |
248 | else | |
249 | _error->MergeWithStack(); | |
15fc8636 | 250 | return found; |
856d3b06 DK |
251 | } |
252 | /*}}}*/ | |
15fc8636 DK |
253 | // FromCommandLine - Return all packages specified on commandline /*{{{*/ |
254 | bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) { | |
255 | bool found = false; | |
256 | for (const char **I = cmdline; *I != 0; ++I) | |
257 | found |= PackageContainerInterface::FromString(pci, Cache, *I, helper); | |
258 | return found; | |
259 | } | |
260 | /*}}}*/ | |
261 | // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/ | |
262 | bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, | |
263 | pkgCacheFile &Cache, const char * cmdline, | |
264 | std::list<Modifier> const &mods, CacheSetHelper &helper) { | |
265 | std::string str = cmdline; | |
e6a12579 | 266 | unsigned short fallback = modID; |
15fc8636 DK |
267 | bool modifierPresent = false; |
268 | for (std::list<Modifier>::const_iterator mod = mods.begin(); | |
269 | mod != mods.end(); ++mod) { | |
270 | size_t const alength = strlen(mod->Alias); | |
271 | switch(mod->Pos) { | |
272 | case Modifier::POSTFIX: | |
273 | if (str.compare(str.length() - alength, alength, | |
274 | mod->Alias, 0, alength) != 0) | |
55c59998 | 275 | continue; |
15fc8636 DK |
276 | str.erase(str.length() - alength); |
277 | modID = mod->ID; | |
55c59998 | 278 | break; |
15fc8636 DK |
279 | case Modifier::PREFIX: |
280 | continue; | |
281 | case Modifier::NONE: | |
282 | continue; | |
55c59998 | 283 | } |
15fc8636 DK |
284 | modifierPresent = true; |
285 | break; | |
286 | } | |
287 | if (modifierPresent == true) { | |
288 | bool const errors = helper.showErrors(false); | |
289 | pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper); | |
290 | helper.showErrors(errors); | |
291 | if (Pkg.end() == false) { | |
292 | pci->insert(Pkg); | |
e6a12579 | 293 | modID = fallback; |
15fc8636 DK |
294 | return true; |
295 | } | |
296 | } | |
297 | return FromString(pci, Cache, str, helper); | |
298 | } | |
299 | /*}}}*/ | |
300 | // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/ | |
301 | bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID, | |
302 | VersionContainerInterface * const vci, | |
303 | pkgCacheFile &Cache, const char * cmdline, | |
304 | std::list<Modifier> const &mods, | |
305 | CacheSetHelper &helper) { | |
306 | Version select = NEWEST; | |
307 | std::string str = cmdline; | |
308 | bool modifierPresent = false; | |
309 | unsigned short fallback = modID; | |
310 | for (std::list<Modifier>::const_iterator mod = mods.begin(); | |
311 | mod != mods.end(); ++mod) { | |
312 | if (modID == fallback && mod->ID == fallback) | |
313 | select = mod->SelectVersion; | |
314 | size_t const alength = strlen(mod->Alias); | |
315 | switch(mod->Pos) { | |
316 | case Modifier::POSTFIX: | |
317 | if (str.compare(str.length() - alength, alength, | |
318 | mod->Alias, 0, alength) != 0) | |
bd631595 | 319 | continue; |
15fc8636 DK |
320 | str.erase(str.length() - alength); |
321 | modID = mod->ID; | |
322 | select = mod->SelectVersion; | |
323 | break; | |
324 | case Modifier::PREFIX: | |
325 | continue; | |
326 | case Modifier::NONE: | |
327 | continue; | |
bd631595 | 328 | } |
15fc8636 DK |
329 | modifierPresent = true; |
330 | break; | |
55c59998 | 331 | } |
15fc8636 DK |
332 | if (modifierPresent == true) { |
333 | bool const errors = helper.showErrors(false); | |
334 | bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true); | |
335 | helper.showErrors(errors); | |
e6a12579 DK |
336 | if (found == true) { |
337 | modID = fallback; | |
15fc8636 | 338 | return true; |
e6a12579 | 339 | } |
15fc8636 DK |
340 | } |
341 | return FromString(vci, Cache, str, select, helper); | |
55c59998 DK |
342 | } |
343 | /*}}}*/ | |
856d3b06 | 344 | // FromCommandLine - Return all versions specified on commandline /*{{{*/ |
15fc8636 DK |
345 | bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci, |
346 | pkgCacheFile &Cache, const char **cmdline, | |
347 | Version const &fallback, CacheSetHelper &helper) { | |
348 | bool found = false; | |
bd631595 | 349 | for (const char **I = cmdline; *I != 0; ++I) |
15fc8636 DK |
350 | found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper); |
351 | return found; | |
55c59998 DK |
352 | } |
353 | /*}}}*/ | |
354 | // FromString - Returns all versions spedcified by a string /*{{{*/ | |
15fc8636 DK |
355 | bool VersionContainerInterface::FromString(VersionContainerInterface * const vci, |
356 | pkgCacheFile &Cache, std::string pkg, | |
357 | Version const &fallback, CacheSetHelper &helper, | |
358 | bool const onlyFromName) { | |
55c59998 DK |
359 | std::string ver; |
360 | bool verIsRel = false; | |
361 | size_t const vertag = pkg.find_last_of("/="); | |
472ff00e | 362 | if (vertag != std::string::npos) { |
55c59998 DK |
363 | ver = pkg.substr(vertag+1); |
364 | verIsRel = (pkg[vertag] == '/'); | |
365 | pkg.erase(vertag); | |
366 | } | |
bd631595 DK |
367 | PackageSet pkgset; |
368 | if (onlyFromName == false) | |
15fc8636 | 369 | PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper); |
bd631595 | 370 | else { |
15fc8636 | 371 | pkgset.insert(PackageContainerInterface::FromName(Cache, pkg, helper)); |
bd631595 DK |
372 | } |
373 | ||
c8db3fff DK |
374 | bool errors = true; |
375 | if (pkgset.getConstructor() != PackageSet::UNKNOWN) | |
376 | errors = helper.showErrors(false); | |
15fc8636 DK |
377 | |
378 | bool found = false; | |
55c59998 DK |
379 | for (PackageSet::const_iterator P = pkgset.begin(); |
380 | P != pkgset.end(); ++P) { | |
472ff00e | 381 | if (vertag == std::string::npos) { |
15fc8636 | 382 | found |= VersionContainerInterface::FromPackage(vci, Cache, P, fallback, helper); |
55c59998 | 383 | continue; |
856d3b06 | 384 | } |
55c59998 DK |
385 | pkgCache::VerIterator V; |
386 | if (ver == "installed") | |
70e706ad | 387 | V = getInstalledVer(Cache, P, helper); |
55c59998 | 388 | else if (ver == "candidate") |
70e706ad | 389 | V = getCandidateVer(Cache, P, helper); |
f1a58ff8 DK |
390 | else if (ver == "newest") { |
391 | if (P->VersionList != 0) | |
392 | V = P.VersionList(); | |
393 | else | |
394 | V = helper.canNotFindNewestVer(Cache, P); | |
395 | } else { | |
55c59998 DK |
396 | pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : |
397 | pkgVersionMatch::Version)); | |
398 | V = Match.Find(P); | |
399 | if (V.end() == true) { | |
400 | if (verIsRel == true) | |
401 | _error->Error(_("Release '%s' for '%s' was not found"), | |
402 | ver.c_str(), P.FullName(true).c_str()); | |
403 | else | |
404 | _error->Error(_("Version '%s' for '%s' was not found"), | |
405 | ver.c_str(), P.FullName(true).c_str()); | |
84910ad5 DK |
406 | continue; |
407 | } | |
78c32596 | 408 | } |
55c59998 DK |
409 | if (V.end() == true) |
410 | continue; | |
70e706ad | 411 | helper.showSelectedVersion(P, V, ver, verIsRel); |
15fc8636 DK |
412 | vci->insert(V); |
413 | found = true; | |
78c32596 | 414 | } |
c8db3fff DK |
415 | if (pkgset.getConstructor() != PackageSet::UNKNOWN) |
416 | helper.showErrors(errors); | |
15fc8636 | 417 | return found; |
856d3b06 DK |
418 | } |
419 | /*}}}*/ | |
fb83c1d0 | 420 | // FromPackage - versions from package based on fallback /*{{{*/ |
15fc8636 DK |
421 | bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci, |
422 | pkgCacheFile &Cache, | |
423 | pkgCache::PkgIterator const &P, | |
424 | Version const &fallback, | |
425 | CacheSetHelper &helper) { | |
84910ad5 | 426 | pkgCache::VerIterator V; |
70e706ad | 427 | bool showErrors; |
15fc8636 | 428 | bool found = false; |
84910ad5 | 429 | switch(fallback) { |
15fc8636 | 430 | case ALL: |
84910ad5 DK |
431 | if (P->VersionList != 0) |
432 | for (V = P.VersionList(); V.end() != true; ++V) | |
15fc8636 | 433 | found |= vci->insert(V); |
84910ad5 | 434 | else |
15fc8636 | 435 | helper.canNotFindAllVer(vci, Cache, P); |
84910ad5 | 436 | break; |
15fc8636 DK |
437 | case CANDANDINST: |
438 | found |= vci->insert(getInstalledVer(Cache, P, helper)); | |
439 | found |= vci->insert(getCandidateVer(Cache, P, helper)); | |
84910ad5 | 440 | break; |
15fc8636 DK |
441 | case CANDIDATE: |
442 | found |= vci->insert(getCandidateVer(Cache, P, helper)); | |
84910ad5 | 443 | break; |
15fc8636 DK |
444 | case INSTALLED: |
445 | found |= vci->insert(getInstalledVer(Cache, P, helper)); | |
84910ad5 | 446 | break; |
15fc8636 | 447 | case CANDINST: |
70e706ad DK |
448 | showErrors = helper.showErrors(false); |
449 | V = getCandidateVer(Cache, P, helper); | |
84910ad5 | 450 | if (V.end() == true) |
70e706ad DK |
451 | V = getInstalledVer(Cache, P, helper); |
452 | helper.showErrors(showErrors); | |
84910ad5 | 453 | if (V.end() == false) |
15fc8636 | 454 | found |= vci->insert(V); |
84910ad5 | 455 | else |
15fc8636 | 456 | helper.canNotFindInstCandVer(vci, Cache, P); |
84910ad5 | 457 | break; |
15fc8636 | 458 | case INSTCAND: |
70e706ad DK |
459 | showErrors = helper.showErrors(false); |
460 | V = getInstalledVer(Cache, P, helper); | |
84910ad5 | 461 | if (V.end() == true) |
70e706ad DK |
462 | V = getCandidateVer(Cache, P, helper); |
463 | helper.showErrors(showErrors); | |
84910ad5 | 464 | if (V.end() == false) |
15fc8636 | 465 | found |= vci->insert(V); |
84910ad5 | 466 | else |
15fc8636 | 467 | helper.canNotFindInstCandVer(vci, Cache, P); |
84910ad5 | 468 | break; |
15fc8636 | 469 | case NEWEST: |
84910ad5 | 470 | if (P->VersionList != 0) |
15fc8636 | 471 | found |= vci->insert(P.VersionList()); |
84910ad5 | 472 | else |
15fc8636 | 473 | helper.canNotFindNewestVer(Cache, P); |
84910ad5 DK |
474 | break; |
475 | } | |
15fc8636 | 476 | return found; |
84910ad5 DK |
477 | } |
478 | /*}}}*/ | |
856d3b06 | 479 | // getCandidateVer - Returns the candidate version of the given package /*{{{*/ |
15fc8636 | 480 | pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache, |
70e706ad | 481 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { |
a8ef7efd | 482 | pkgCache::VerIterator Cand; |
15fc8636 | 483 | if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) { |
bd631595 DK |
484 | if (unlikely(Cache.GetPolicy() == 0)) |
485 | return pkgCache::VerIterator(Cache); | |
a8ef7efd | 486 | Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); |
2fbfb111 DK |
487 | } else { |
488 | Cand = Cache[Pkg].CandidateVerIter(Cache); | |
a8ef7efd | 489 | } |
70e706ad DK |
490 | if (Cand.end() == true) |
491 | return helper.canNotFindCandidateVer(Cache, Pkg); | |
856d3b06 DK |
492 | return Cand; |
493 | } | |
494 | /*}}}*/ | |
495 | // getInstalledVer - Returns the installed version of the given package /*{{{*/ | |
15fc8636 | 496 | pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache, |
70e706ad DK |
497 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { |
498 | if (Pkg->CurrentVer == 0) | |
499 | return helper.canNotFindInstalledVer(Cache, Pkg); | |
856d3b06 | 500 | return Pkg.CurrentVer(); |
ffee1c2b DK |
501 | } |
502 | /*}}}*/ | |
15fc8636 | 503 | |
bd631595 DK |
504 | // canNotFindPkgName - handle the case no package has this name /*{{{*/ |
505 | pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, | |
506 | std::string const &str) { | |
507 | if (ShowError == true) | |
cd7bbc47 | 508 | _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str()); |
bd631595 DK |
509 | return pkgCache::PkgIterator(Cache, 0); |
510 | } | |
511 | /*}}}*/ | |
70e706ad | 512 | // canNotFindTask - handle the case no package is found for a task /*{{{*/ |
15fc8636 | 513 | void CacheSetHelper::canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { |
70e706ad | 514 | if (ShowError == true) |
cd7bbc47 | 515 | _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str()); |
70e706ad DK |
516 | } |
517 | /*}}}*/ | |
518 | // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ | |
15fc8636 | 519 | void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { |
70e706ad | 520 | if (ShowError == true) |
cd7bbc47 | 521 | _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str()); |
70e706ad DK |
522 | } |
523 | /*}}}*/ | |
524 | // canNotFindPackage - handle the case no package is found from a string/*{{{*/ | |
15fc8636 | 525 | void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) { |
70e706ad DK |
526 | } |
527 | /*}}}*/ | |
528 | // canNotFindAllVer /*{{{*/ | |
15fc8636 | 529 | void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, |
70e706ad DK |
530 | pkgCache::PkgIterator const &Pkg) { |
531 | if (ShowError == true) | |
edc0ef10 | 532 | _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); |
70e706ad DK |
533 | } |
534 | /*}}}*/ | |
535 | // canNotFindInstCandVer /*{{{*/ | |
15fc8636 | 536 | void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, |
70e706ad DK |
537 | pkgCache::PkgIterator const &Pkg) { |
538 | if (ShowError == true) | |
cd7bbc47 | 539 | _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 |
540 | } |
541 | /*}}}*/ | |
cf28bcad | 542 | // canNotFindInstCandVer /*{{{*/ |
15fc8636 | 543 | void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache, |
cf28bcad DK |
544 | pkgCache::PkgIterator const &Pkg) { |
545 | if (ShowError == true) | |
cd7bbc47 | 546 | _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 |
547 | } |
548 | /*}}}*/ | |
70e706ad DK |
549 | // canNotFindNewestVer /*{{{*/ |
550 | pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, | |
551 | pkgCache::PkgIterator const &Pkg) { | |
552 | if (ShowError == true) | |
cd7bbc47 | 553 | _error->Insert(ErrorType, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); |
c8db3fff | 554 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
555 | } |
556 | /*}}}*/ | |
557 | // canNotFindCandidateVer /*{{{*/ | |
558 | pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, | |
559 | pkgCache::PkgIterator const &Pkg) { | |
560 | if (ShowError == true) | |
cd7bbc47 | 561 | _error->Insert(ErrorType, _("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); |
c8db3fff | 562 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
563 | } |
564 | /*}}}*/ | |
565 | // canNotFindInstalledVer /*{{{*/ | |
566 | pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, | |
567 | pkgCache::PkgIterator const &Pkg) { | |
568 | if (ShowError == true) | |
cd7bbc47 | 569 | _error->Insert(ErrorType, _("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); |
c8db3fff | 570 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
571 | } |
572 | /*}}}*/ | |
15fc8636 DK |
573 | // showTaskSelection /*{{{*/ |
574 | void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &pkg, | |
575 | std::string const &pattern) { | |
576 | } | |
577 | /*}}}*/ | |
578 | // showRegExSelection /*{{{*/ | |
579 | void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &pkg, | |
580 | std::string const &pattern) { | |
581 | } | |
582 | /*}}}*/ | |
583 | // showSelectedVersion /*{{{*/ | |
584 | void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &Pkg, | |
585 | pkgCache::VerIterator const Ver, | |
586 | std::string const &ver, | |
587 | bool const verIsRel) { | |
588 | } | |
589 | /*}}}*/ | |
ffee1c2b | 590 | } |