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