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