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