]>
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 { | |
1e064088 DK |
40 | // PackageFrom - selecting the appropriate method for package selection /*{{{*/ |
41 | bool CacheSetHelper::PackageFrom(enum PkgSelector const select, PackageContainerInterface * const pci, | |
42 | pkgCacheFile &Cache, std::string const &pattern) { | |
43 | switch (select) { | |
44 | case UNKNOWN: return false; | |
45 | case REGEX: return PackageFromRegEx(pci, Cache, pattern); | |
46 | case TASK: return PackageFromTask(pci, Cache, pattern); | |
47 | case FNMATCH: return PackageFromFnmatch(pci, Cache, pattern); | |
48 | case PACKAGENAME: return PackageFromPackageName(pci, Cache, pattern); | |
49 | case STRING: return PackageFromString(pci, Cache, pattern); | |
50 | } | |
51 | return false; | |
52 | } | |
53 | /*}}}*/ | |
54 | // PackageFromTask - Return all packages in the cache from a specific task /*{{{*/ | |
55 | bool CacheSetHelper::PackageFromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { | |
bd631595 | 56 | size_t const archfound = pattern.find_last_of(':'); |
dc0f01f7 DK |
57 | std::string arch = "native"; |
58 | if (archfound != std::string::npos) { | |
59 | arch = pattern.substr(archfound+1); | |
60 | pattern.erase(archfound); | |
61 | } | |
62 | ||
63 | if (pattern[pattern.length() -1] != '^') | |
15fc8636 | 64 | return false; |
dc0f01f7 DK |
65 | pattern.erase(pattern.length()-1); |
66 | ||
bd631595 | 67 | if (unlikely(Cache.GetPkgCache() == 0 || Cache.GetDepCache() == 0)) |
15fc8636 DK |
68 | return false; |
69 | ||
70 | bool const wasEmpty = pci->empty(); | |
71 | if (wasEmpty == true) | |
fdba4d53 | 72 | pci->setConstructor(CacheSetHelper::TASK); |
bd631595 | 73 | |
dc0f01f7 DK |
74 | // get the records |
75 | pkgRecords Recs(Cache); | |
76 | ||
77 | // build regexp for the task | |
78 | regex_t Pattern; | |
79 | char S[300]; | |
80 | snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", pattern.c_str()); | |
81 | if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0) { | |
82 | _error->Error("Failed to compile task regexp"); | |
15fc8636 | 83 | return false; |
dc0f01f7 DK |
84 | } |
85 | ||
15fc8636 | 86 | bool found = false; |
dc0f01f7 DK |
87 | for (pkgCache::GrpIterator Grp = Cache->GrpBegin(); Grp.end() == false; ++Grp) { |
88 | pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); | |
89 | if (Pkg.end() == true) | |
90 | continue; | |
91 | pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); | |
92 | if(ver.end() == true) | |
93 | continue; | |
94 | ||
95 | pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); | |
96 | const char *start, *end; | |
97 | parser.GetRec(start,end); | |
98 | unsigned int const length = end - start; | |
62d8a765 DK |
99 | if (unlikely(length == 0)) |
100 | continue; | |
dc0f01f7 DK |
101 | char buf[length]; |
102 | strncpy(buf, start, length); | |
103 | buf[length-1] = '\0'; | |
70e706ad DK |
104 | if (regexec(&Pattern, buf, 0, 0, 0) != 0) |
105 | continue; | |
106 | ||
15fc8636 | 107 | pci->insert(Pkg); |
1e064088 | 108 | showPackageSelection(Pkg, CacheSetHelper::TASK, pattern); |
15fc8636 | 109 | found = true; |
dc0f01f7 | 110 | } |
70e706ad | 111 | regfree(&Pattern); |
dc0f01f7 | 112 | |
15fc8636 | 113 | if (found == false) { |
1e064088 | 114 | canNotFindPackage(CacheSetHelper::TASK, pci, Cache, pattern); |
fdba4d53 | 115 | pci->setConstructor(CacheSetHelper::UNKNOWN); |
15fc8636 DK |
116 | return false; |
117 | } | |
118 | ||
fdba4d53 DK |
119 | if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) |
120 | pci->setConstructor(CacheSetHelper::UNKNOWN); | |
dc0f01f7 | 121 | |
15fc8636 | 122 | return true; |
dc0f01f7 DK |
123 | } |
124 | /*}}}*/ | |
1e064088 DK |
125 | // PackageFromRegEx - Return all packages in the cache matching a pattern /*{{{*/ |
126 | bool CacheSetHelper::PackageFromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) { | |
6e235c66 | 127 | static const char * const isregex = ".?+*|[^$"; |
6e235c66 | 128 | if (pattern.find_first_of(isregex) == std::string::npos) |
15fc8636 DK |
129 | return false; |
130 | ||
131 | bool const wasEmpty = pci->empty(); | |
132 | if (wasEmpty == true) | |
fdba4d53 | 133 | pci->setConstructor(CacheSetHelper::REGEX); |
ffee1c2b | 134 | |
6e235c66 | 135 | size_t archfound = pattern.find_last_of(':'); |
dc0f01f7 | 136 | std::string arch = "native"; |
6e235c66 DK |
137 | if (archfound != std::string::npos) { |
138 | arch = pattern.substr(archfound+1); | |
139 | if (arch.find_first_of(isregex) == std::string::npos) | |
140 | pattern.erase(archfound); | |
141 | else | |
142 | arch = "native"; | |
143 | } | |
144 | ||
bd631595 | 145 | if (unlikely(Cache.GetPkgCache() == 0)) |
15fc8636 | 146 | return false; |
bd631595 | 147 | |
9ba5aa3b DK |
148 | APT::CacheFilter::PackageNameMatchesRegEx regexfilter(pattern); |
149 | ||
15fc8636 | 150 | bool found = false; |
9ba5aa3b DK |
151 | for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { |
152 | if (regexfilter(Grp) == false) | |
ffee1c2b | 153 | continue; |
6e235c66 | 154 | pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); |
78c32596 | 155 | if (Pkg.end() == true) { |
8dd562a8 DK |
156 | if (archfound == std::string::npos) |
157 | Pkg = Grp.FindPreferredPkg(true); | |
78c32596 DK |
158 | if (Pkg.end() == true) |
159 | continue; | |
160 | } | |
ffee1c2b | 161 | |
15fc8636 | 162 | pci->insert(Pkg); |
1e064088 | 163 | showPackageSelection(Pkg, CacheSetHelper::REGEX, pattern); |
15fc8636 | 164 | found = true; |
ffee1c2b | 165 | } |
ffee1c2b | 166 | |
15fc8636 | 167 | if (found == false) { |
1e064088 | 168 | canNotFindPackage(CacheSetHelper::REGEX, pci, Cache, pattern); |
fdba4d53 | 169 | pci->setConstructor(CacheSetHelper::UNKNOWN); |
15fc8636 DK |
170 | return false; |
171 | } | |
172 | ||
fdba4d53 DK |
173 | if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) |
174 | pci->setConstructor(CacheSetHelper::UNKNOWN); | |
b9179170 MV |
175 | |
176 | return true; | |
177 | } | |
178 | /*}}}*/ | |
1e064088 DK |
179 | // PackageFromFnmatch - Returns the package defined by this fnmatch /*{{{*/ |
180 | bool CacheSetHelper::PackageFromFnmatch(PackageContainerInterface * const pci, | |
181 | pkgCacheFile &Cache, std::string pattern) | |
b9179170 MV |
182 | { |
183 | static const char * const isfnmatch = ".?*[]!"; | |
184 | if (pattern.find_first_of(isfnmatch) == std::string::npos) | |
185 | return false; | |
186 | ||
187 | bool const wasEmpty = pci->empty(); | |
188 | if (wasEmpty == true) | |
fdba4d53 | 189 | pci->setConstructor(CacheSetHelper::FNMATCH); |
b9179170 MV |
190 | |
191 | size_t archfound = pattern.find_last_of(':'); | |
192 | std::string arch = "native"; | |
193 | if (archfound != std::string::npos) { | |
194 | arch = pattern.substr(archfound+1); | |
195 | if (arch.find_first_of(isfnmatch) == std::string::npos) | |
196 | pattern.erase(archfound); | |
197 | else | |
198 | arch = "native"; | |
199 | } | |
200 | ||
201 | if (unlikely(Cache.GetPkgCache() == 0)) | |
202 | return false; | |
203 | ||
204 | APT::CacheFilter::PackageNameMatchesFnmatch filter(pattern); | |
205 | ||
206 | bool found = false; | |
207 | for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { | |
208 | if (filter(Grp) == false) | |
209 | continue; | |
210 | pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); | |
211 | if (Pkg.end() == true) { | |
8dd562a8 DK |
212 | if (archfound == std::string::npos) |
213 | Pkg = Grp.FindPreferredPkg(true); | |
b9179170 MV |
214 | if (Pkg.end() == true) |
215 | continue; | |
216 | } | |
217 | ||
218 | pci->insert(Pkg); | |
1e064088 | 219 | showPackageSelection(Pkg, CacheSetHelper::FNMATCH, pattern); |
b9179170 MV |
220 | found = true; |
221 | } | |
222 | ||
223 | if (found == false) { | |
1e064088 | 224 | canNotFindPackage(CacheSetHelper::FNMATCH, pci, Cache, pattern); |
fdba4d53 | 225 | pci->setConstructor(CacheSetHelper::UNKNOWN); |
b9179170 MV |
226 | return false; |
227 | } | |
228 | ||
fdba4d53 DK |
229 | if (wasEmpty == false && pci->getConstructor() != CacheSetHelper::UNKNOWN) |
230 | pci->setConstructor(CacheSetHelper::UNKNOWN); | |
70e706ad | 231 | |
15fc8636 | 232 | return true; |
78c32596 DK |
233 | } |
234 | /*}}}*/ | |
1e064088 DK |
235 | // PackageFromName - Returns the package defined by this string /*{{{*/ |
236 | pkgCache::PkgIterator CacheSetHelper::PackageFromName(pkgCacheFile &Cache, | |
237 | std::string const &str) { | |
bd631595 DK |
238 | std::string pkg = str; |
239 | size_t archfound = pkg.find_last_of(':'); | |
240 | std::string arch; | |
241 | if (archfound != std::string::npos) { | |
242 | arch = pkg.substr(archfound+1); | |
243 | pkg.erase(archfound); | |
244 | } | |
245 | ||
246 | if (Cache.GetPkgCache() == 0) | |
247 | return pkgCache::PkgIterator(Cache, 0); | |
248 | ||
249 | pkgCache::PkgIterator Pkg(Cache, 0); | |
250 | if (arch.empty() == true) { | |
251 | pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); | |
252 | if (Grp.end() == false) | |
253 | Pkg = Grp.FindPreferredPkg(); | |
254 | } else | |
255 | Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch); | |
256 | ||
257 | if (Pkg.end() == true) | |
1e064088 | 258 | return canNotFindPkgName(Cache, str); |
bd631595 DK |
259 | return Pkg; |
260 | } | |
261 | /*}}}*/ | |
1e064088 DK |
262 | // PackageFromPackageName - Returns the package defined by this string /*{{{*/ |
263 | bool CacheSetHelper::PackageFromPackageName(PackageContainerInterface * const pci, pkgCacheFile &Cache, | |
264 | std::string pkg) { | |
2f0d4029 DK |
265 | if (unlikely(Cache.GetPkgCache() == 0)) |
266 | return false; | |
267 | ||
268 | size_t const archfound = pkg.find_last_of(':'); | |
269 | std::string arch; | |
270 | if (archfound != std::string::npos) { | |
271 | arch = pkg.substr(archfound+1); | |
272 | pkg.erase(archfound); | |
f1d86c0e DK |
273 | if (arch == "all" || arch == "native") |
274 | arch = _config->Find("APT::Architecture"); | |
2f0d4029 DK |
275 | } |
276 | ||
277 | pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg); | |
278 | if (Grp.end() == false) { | |
279 | if (arch.empty() == true) { | |
280 | pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg(); | |
281 | if (Pkg.end() == false) | |
282 | { | |
283 | pci->insert(Pkg); | |
284 | return true; | |
285 | } | |
286 | } else { | |
287 | bool found = false; | |
288 | // for 'linux-any' return the first package matching, for 'linux-*' return all matches | |
289 | bool const isGlobal = arch.find('*') != std::string::npos; | |
290 | APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch); | |
291 | for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) { | |
292 | if (pams(Pkg) == false) | |
293 | continue; | |
294 | pci->insert(Pkg); | |
295 | found = true; | |
296 | if (isGlobal == false) | |
297 | break; | |
298 | } | |
299 | if (found == true) | |
300 | return true; | |
301 | } | |
302 | } | |
303 | ||
1e064088 | 304 | pkgCache::PkgIterator Pkg = canNotFindPkgName(Cache, pkg); |
2f0d4029 DK |
305 | if (Pkg.end() == true) |
306 | return false; | |
307 | ||
308 | pci->insert(Pkg); | |
309 | return true; | |
310 | } | |
311 | /*}}}*/ | |
1e064088 DK |
312 | // PackageFromString - Return all packages matching a specific string /*{{{*/ |
313 | bool CacheSetHelper::PackageFromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) { | |
15fc8636 | 314 | bool found = true; |
48c39e32 DK |
315 | _error->PushToStack(); |
316 | ||
1e064088 DK |
317 | if (PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str) == false && |
318 | PackageFrom(CacheSetHelper::TASK, pci, Cache, str) == false && | |
fdba4d53 | 319 | // FIXME: hm, hm, regexp/fnmatch incompatible? |
1e064088 DK |
320 | PackageFrom(CacheSetHelper::FNMATCH, pci, Cache, str) == false && |
321 | PackageFrom(CacheSetHelper::REGEX, pci, Cache, str) == false) | |
15fc8636 | 322 | { |
1e064088 | 323 | canNotFindPackage(CacheSetHelper::PACKAGENAME, pci, Cache, str); |
15fc8636 | 324 | found = false; |
48c39e32 | 325 | } |
dc0f01f7 | 326 | |
15fc8636 | 327 | if (found == true) |
48c39e32 DK |
328 | _error->RevertToStack(); |
329 | else | |
330 | _error->MergeWithStack(); | |
15fc8636 | 331 | return found; |
856d3b06 DK |
332 | } |
333 | /*}}}*/ | |
1e064088 DK |
334 | // PackageFromCommandLine - Return all packages specified on commandline /*{{{*/ |
335 | bool CacheSetHelper::PackageFromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline) { | |
15fc8636 DK |
336 | bool found = false; |
337 | for (const char **I = cmdline; *I != 0; ++I) | |
1e064088 | 338 | found |= PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, *I); |
15fc8636 DK |
339 | return found; |
340 | } | |
341 | /*}}}*/ | |
342 | // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/ | |
1e064088 | 343 | bool CacheSetHelper::PackageFromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci, |
15fc8636 | 344 | pkgCacheFile &Cache, const char * cmdline, |
1e064088 | 345 | std::list<PkgModifier> const &mods) { |
15fc8636 | 346 | std::string str = cmdline; |
e6a12579 | 347 | unsigned short fallback = modID; |
15fc8636 | 348 | bool modifierPresent = false; |
1e064088 | 349 | for (std::list<PkgModifier>::const_iterator mod = mods.begin(); |
15fc8636 DK |
350 | mod != mods.end(); ++mod) { |
351 | size_t const alength = strlen(mod->Alias); | |
352 | switch(mod->Pos) { | |
1e064088 | 353 | case PkgModifier::POSTFIX: |
15fc8636 DK |
354 | if (str.compare(str.length() - alength, alength, |
355 | mod->Alias, 0, alength) != 0) | |
55c59998 | 356 | continue; |
15fc8636 DK |
357 | str.erase(str.length() - alength); |
358 | modID = mod->ID; | |
55c59998 | 359 | break; |
1e064088 | 360 | case PkgModifier::PREFIX: |
15fc8636 | 361 | continue; |
1e064088 | 362 | case PkgModifier::NONE: |
15fc8636 | 363 | continue; |
55c59998 | 364 | } |
15fc8636 DK |
365 | modifierPresent = true; |
366 | break; | |
367 | } | |
368 | if (modifierPresent == true) { | |
1e064088 DK |
369 | bool const errors = showErrors(false); |
370 | bool const found = PackageFrom(PACKAGENAME, pci, Cache, cmdline); | |
371 | showErrors(errors); | |
372 | if (found == true) { | |
e6a12579 | 373 | modID = fallback; |
15fc8636 DK |
374 | return true; |
375 | } | |
376 | } | |
1e064088 | 377 | return PackageFrom(CacheSetHelper::PACKAGENAME, pci, Cache, str); |
15fc8636 DK |
378 | } |
379 | /*}}}*/ | |
380 | // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/ | |
381 | bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID, | |
382 | VersionContainerInterface * const vci, | |
383 | pkgCacheFile &Cache, const char * cmdline, | |
384 | std::list<Modifier> const &mods, | |
385 | CacheSetHelper &helper) { | |
fdba4d53 | 386 | CacheSetHelper::VerSelector select = CacheSetHelper::NEWEST; |
15fc8636 | 387 | std::string str = cmdline; |
d99854ca DK |
388 | if (unlikely(str.empty() == true)) |
389 | return false; | |
15fc8636 DK |
390 | bool modifierPresent = false; |
391 | unsigned short fallback = modID; | |
392 | for (std::list<Modifier>::const_iterator mod = mods.begin(); | |
393 | mod != mods.end(); ++mod) { | |
394 | if (modID == fallback && mod->ID == fallback) | |
395 | select = mod->SelectVersion; | |
396 | size_t const alength = strlen(mod->Alias); | |
397 | switch(mod->Pos) { | |
398 | case Modifier::POSTFIX: | |
d99854ca DK |
399 | if (str.length() <= alength || |
400 | str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0) | |
bd631595 | 401 | continue; |
15fc8636 DK |
402 | str.erase(str.length() - alength); |
403 | modID = mod->ID; | |
404 | select = mod->SelectVersion; | |
405 | break; | |
406 | case Modifier::PREFIX: | |
407 | continue; | |
408 | case Modifier::NONE: | |
409 | continue; | |
bd631595 | 410 | } |
15fc8636 DK |
411 | modifierPresent = true; |
412 | break; | |
55c59998 | 413 | } |
15fc8636 DK |
414 | if (modifierPresent == true) { |
415 | bool const errors = helper.showErrors(false); | |
416 | bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true); | |
417 | helper.showErrors(errors); | |
e6a12579 DK |
418 | if (found == true) { |
419 | modID = fallback; | |
15fc8636 | 420 | return true; |
e6a12579 | 421 | } |
15fc8636 DK |
422 | } |
423 | return FromString(vci, Cache, str, select, helper); | |
55c59998 DK |
424 | } |
425 | /*}}}*/ | |
856d3b06 | 426 | // FromCommandLine - Return all versions specified on commandline /*{{{*/ |
15fc8636 DK |
427 | bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci, |
428 | pkgCacheFile &Cache, const char **cmdline, | |
fdba4d53 DK |
429 | CacheSetHelper::VerSelector const fallback, |
430 | CacheSetHelper &helper) { | |
15fc8636 | 431 | bool found = false; |
bd631595 | 432 | for (const char **I = cmdline; *I != 0; ++I) |
15fc8636 DK |
433 | found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper); |
434 | return found; | |
55c59998 DK |
435 | } |
436 | /*}}}*/ | |
437 | // FromString - Returns all versions spedcified by a string /*{{{*/ | |
15fc8636 DK |
438 | bool VersionContainerInterface::FromString(VersionContainerInterface * const vci, |
439 | pkgCacheFile &Cache, std::string pkg, | |
fdba4d53 DK |
440 | CacheSetHelper::VerSelector const fallback, |
441 | CacheSetHelper &helper, | |
15fc8636 | 442 | bool const onlyFromName) { |
1e064088 DK |
443 | PackageSet pkgset; |
444 | if(FileExists(pkg)) { | |
445 | helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg); | |
446 | if(pkgset.empty() == true) | |
447 | return false; | |
448 | return VersionContainerInterface::FromPackage(vci, Cache, pkgset.begin(), fallback, helper); | |
449 | } | |
fdff5b03 | 450 | |
55c59998 DK |
451 | std::string ver; |
452 | bool verIsRel = false; | |
453 | size_t const vertag = pkg.find_last_of("/="); | |
472ff00e | 454 | if (vertag != std::string::npos) { |
55c59998 DK |
455 | ver = pkg.substr(vertag+1); |
456 | verIsRel = (pkg[vertag] == '/'); | |
457 | pkg.erase(vertag); | |
458 | } | |
bd631595 | 459 | if (onlyFromName == false) |
1e064088 | 460 | helper.PackageFrom(CacheSetHelper::STRING, &pkgset, Cache, pkg); |
bd631595 | 461 | else { |
1e064088 | 462 | helper.PackageFrom(CacheSetHelper::PACKAGENAME, &pkgset, Cache, pkg); |
bd631595 DK |
463 | } |
464 | ||
c8db3fff | 465 | bool errors = true; |
fdba4d53 | 466 | if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN) |
c8db3fff | 467 | errors = helper.showErrors(false); |
15fc8636 DK |
468 | |
469 | bool found = false; | |
55c59998 DK |
470 | for (PackageSet::const_iterator P = pkgset.begin(); |
471 | P != pkgset.end(); ++P) { | |
472ff00e | 472 | if (vertag == std::string::npos) { |
15fc8636 | 473 | found |= VersionContainerInterface::FromPackage(vci, Cache, P, fallback, helper); |
55c59998 | 474 | continue; |
856d3b06 | 475 | } |
55c59998 DK |
476 | pkgCache::VerIterator V; |
477 | if (ver == "installed") | |
70e706ad | 478 | V = getInstalledVer(Cache, P, helper); |
55c59998 | 479 | else if (ver == "candidate") |
70e706ad | 480 | V = getCandidateVer(Cache, P, helper); |
f1a58ff8 DK |
481 | else if (ver == "newest") { |
482 | if (P->VersionList != 0) | |
483 | V = P.VersionList(); | |
484 | else | |
fdba4d53 | 485 | V = helper.canNotGetVersion(CacheSetHelper::NEWEST, Cache, P); |
f1a58ff8 | 486 | } else { |
55c59998 DK |
487 | pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release : |
488 | pkgVersionMatch::Version)); | |
489 | V = Match.Find(P); | |
490 | if (V.end() == true) { | |
491 | if (verIsRel == true) | |
492 | _error->Error(_("Release '%s' for '%s' was not found"), | |
493 | ver.c_str(), P.FullName(true).c_str()); | |
494 | else | |
495 | _error->Error(_("Version '%s' for '%s' was not found"), | |
496 | ver.c_str(), P.FullName(true).c_str()); | |
84910ad5 DK |
497 | continue; |
498 | } | |
78c32596 | 499 | } |
55c59998 DK |
500 | if (V.end() == true) |
501 | continue; | |
fdba4d53 DK |
502 | if (verIsRel == true) |
503 | helper.showVersionSelection(P, V, CacheSetHelper::RELEASE, ver); | |
504 | else | |
505 | helper.showVersionSelection(P, V, CacheSetHelper::VERSIONNUMBER, ver); | |
15fc8636 DK |
506 | vci->insert(V); |
507 | found = true; | |
78c32596 | 508 | } |
fdba4d53 | 509 | if (pkgset.getConstructor() != CacheSetHelper::UNKNOWN) |
c8db3fff | 510 | helper.showErrors(errors); |
15fc8636 | 511 | return found; |
856d3b06 DK |
512 | } |
513 | /*}}}*/ | |
fb83c1d0 | 514 | // FromPackage - versions from package based on fallback /*{{{*/ |
15fc8636 DK |
515 | bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci, |
516 | pkgCacheFile &Cache, | |
517 | pkgCache::PkgIterator const &P, | |
fdba4d53 | 518 | CacheSetHelper::VerSelector const fallback, |
15fc8636 | 519 | CacheSetHelper &helper) { |
84910ad5 | 520 | pkgCache::VerIterator V; |
70e706ad | 521 | bool showErrors; |
15fc8636 | 522 | bool found = false; |
84910ad5 | 523 | switch(fallback) { |
fdba4d53 | 524 | case CacheSetHelper::ALL: |
84910ad5 DK |
525 | if (P->VersionList != 0) |
526 | for (V = P.VersionList(); V.end() != true; ++V) | |
15fc8636 | 527 | found |= vci->insert(V); |
84910ad5 | 528 | else |
fdba4d53 | 529 | helper.canNotFindVersion(CacheSetHelper::ALL, vci, Cache, P); |
84910ad5 | 530 | break; |
fdba4d53 | 531 | case CacheSetHelper::CANDANDINST: |
15fc8636 DK |
532 | found |= vci->insert(getInstalledVer(Cache, P, helper)); |
533 | found |= vci->insert(getCandidateVer(Cache, P, helper)); | |
84910ad5 | 534 | break; |
fdba4d53 | 535 | case CacheSetHelper::CANDIDATE: |
15fc8636 | 536 | found |= vci->insert(getCandidateVer(Cache, P, helper)); |
84910ad5 | 537 | break; |
fdba4d53 | 538 | case CacheSetHelper::INSTALLED: |
15fc8636 | 539 | found |= vci->insert(getInstalledVer(Cache, P, helper)); |
84910ad5 | 540 | break; |
fdba4d53 | 541 | case CacheSetHelper::CANDINST: |
70e706ad DK |
542 | showErrors = helper.showErrors(false); |
543 | V = getCandidateVer(Cache, P, helper); | |
84910ad5 | 544 | if (V.end() == true) |
70e706ad DK |
545 | V = getInstalledVer(Cache, P, helper); |
546 | helper.showErrors(showErrors); | |
84910ad5 | 547 | if (V.end() == false) |
15fc8636 | 548 | found |= vci->insert(V); |
84910ad5 | 549 | else |
fdba4d53 | 550 | helper.canNotFindVersion(CacheSetHelper::CANDINST, vci, Cache, P); |
84910ad5 | 551 | break; |
fdba4d53 | 552 | case CacheSetHelper::INSTCAND: |
70e706ad DK |
553 | showErrors = helper.showErrors(false); |
554 | V = getInstalledVer(Cache, P, helper); | |
84910ad5 | 555 | if (V.end() == true) |
70e706ad DK |
556 | V = getCandidateVer(Cache, P, helper); |
557 | helper.showErrors(showErrors); | |
84910ad5 | 558 | if (V.end() == false) |
15fc8636 | 559 | found |= vci->insert(V); |
84910ad5 | 560 | else |
fdba4d53 | 561 | helper.canNotFindVersion(CacheSetHelper::INSTCAND, vci, Cache, P); |
84910ad5 | 562 | break; |
fdba4d53 | 563 | case CacheSetHelper::NEWEST: |
84910ad5 | 564 | if (P->VersionList != 0) |
15fc8636 | 565 | found |= vci->insert(P.VersionList()); |
84910ad5 | 566 | else |
fdba4d53 | 567 | helper.canNotFindVersion(CacheSetHelper::NEWEST, vci, Cache, P); |
84910ad5 | 568 | break; |
fdba4d53 DK |
569 | case CacheSetHelper::RELEASE: |
570 | case CacheSetHelper::VERSIONNUMBER: | |
571 | // both make no sense here, so always false | |
572 | return false; | |
84910ad5 | 573 | } |
15fc8636 | 574 | return found; |
84910ad5 DK |
575 | } |
576 | /*}}}*/ | |
9112f777 DK |
577 | // FromDependency - versions satisfying a given dependency /*{{{*/ |
578 | bool VersionContainerInterface::FromDependency(VersionContainerInterface * const vci, | |
579 | pkgCacheFile &Cache, | |
580 | pkgCache::DepIterator const &D, | |
581 | CacheSetHelper::VerSelector const selector, | |
582 | CacheSetHelper &helper) | |
583 | { | |
584 | bool found = false; | |
585 | switch(selector) { | |
586 | case CacheSetHelper::ALL: | |
587 | { | |
588 | pkgCache::PkgIterator const T = D.TargetPkg(); | |
589 | for (pkgCache::VerIterator Ver = T.VersionList(); Ver.end() == false; ++Ver) | |
590 | { | |
591 | if (D.IsSatisfied(Ver) == true) | |
592 | { | |
593 | vci->insert(Ver); | |
594 | found = true; | |
595 | } | |
596 | for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) | |
597 | { | |
598 | pkgCache::VerIterator const V = Prv.OwnerVer(); | |
599 | if (unlikely(V.end() == true) || D.IsSatisfied(Prv) == false) | |
600 | continue; | |
601 | vci->insert(V); | |
602 | found = true; | |
603 | } | |
604 | } | |
605 | return found; | |
606 | } | |
607 | case CacheSetHelper::CANDANDINST: | |
608 | { | |
609 | found = FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper); | |
610 | found &= FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper); | |
611 | return found; | |
612 | } | |
613 | case CacheSetHelper::CANDIDATE: | |
614 | { | |
615 | pkgCache::PkgIterator const T = D.TargetPkg(); | |
616 | pkgCache::VerIterator const Cand = Cache[T].CandidateVerIter(Cache); | |
617 | if (Cand.end() == false && D.IsSatisfied(Cand) == true) | |
618 | { | |
619 | vci->insert(Cand); | |
620 | found = true; | |
621 | } | |
622 | for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) | |
623 | { | |
624 | pkgCache::VerIterator const V = Prv.OwnerVer(); | |
625 | pkgCache::VerIterator const Cand = Cache[Prv.OwnerPkg()].CandidateVerIter(Cache); | |
626 | if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) | |
627 | continue; | |
628 | vci->insert(Cand); | |
629 | found = true; | |
630 | } | |
631 | return found; | |
632 | } | |
633 | case CacheSetHelper::INSTALLED: | |
634 | { | |
635 | pkgCache::PkgIterator const T = D.TargetPkg(); | |
636 | pkgCache::VerIterator const Cand = T.CurrentVer(); | |
637 | if (Cand.end() == false && D.IsSatisfied(Cand) == true) | |
638 | { | |
639 | vci->insert(Cand); | |
640 | found = true; | |
641 | } | |
642 | for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) | |
643 | { | |
644 | pkgCache::VerIterator const V = Prv.OwnerVer(); | |
645 | pkgCache::VerIterator const Cand = Prv.OwnerPkg().CurrentVer(); | |
646 | if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) | |
647 | continue; | |
648 | vci->insert(Cand); | |
649 | found = true; | |
650 | } | |
651 | return found; | |
652 | } | |
653 | case CacheSetHelper::CANDINST: | |
654 | return FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper) || | |
655 | FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper); | |
656 | case CacheSetHelper::INSTCAND: | |
657 | return FromDependency(vci, Cache, D, CacheSetHelper::INSTALLED, helper) || | |
658 | FromDependency(vci, Cache, D, CacheSetHelper::CANDIDATE, helper); | |
659 | case CacheSetHelper::NEWEST: | |
660 | { | |
661 | pkgCache::PkgIterator const T = D.TargetPkg(); | |
662 | pkgCache::VerIterator const Cand = T.VersionList(); | |
663 | if (Cand.end() == false && D.IsSatisfied(Cand) == true) | |
664 | { | |
665 | vci->insert(Cand); | |
666 | found = true; | |
667 | } | |
668 | for (pkgCache::PrvIterator Prv = T.ProvidesList(); Prv.end() != true; ++Prv) | |
669 | { | |
670 | pkgCache::VerIterator const V = Prv.OwnerVer(); | |
671 | pkgCache::VerIterator const Cand = Prv.OwnerPkg().VersionList(); | |
672 | if (Cand.end() == true || V != Cand || D.IsSatisfied(Prv) == false) | |
673 | continue; | |
674 | vci->insert(Cand); | |
675 | found = true; | |
676 | } | |
677 | return found; | |
678 | } | |
679 | case CacheSetHelper::RELEASE: | |
680 | case CacheSetHelper::VERSIONNUMBER: | |
681 | // both make no sense here, so always false | |
682 | return false; | |
683 | } | |
684 | return found; | |
685 | } | |
686 | /*}}}*/ | |
856d3b06 | 687 | // getCandidateVer - Returns the candidate version of the given package /*{{{*/ |
15fc8636 | 688 | pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache, |
70e706ad | 689 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { |
a8ef7efd | 690 | pkgCache::VerIterator Cand; |
b6192267 | 691 | if (Cache.IsDepCacheBuilt() == true) { |
2fbfb111 | 692 | Cand = Cache[Pkg].CandidateVerIter(Cache); |
b6192267 JAK |
693 | } else if (unlikely(Cache.GetPolicy() == nullptr)) { |
694 | return pkgCache::VerIterator(Cache); | |
695 | } else { | |
696 | Cand = Cache.GetPolicy()->GetCandidateVer(Pkg); | |
a8ef7efd | 697 | } |
70e706ad | 698 | if (Cand.end() == true) |
fdba4d53 | 699 | return helper.canNotGetVersion(CacheSetHelper::CANDIDATE, Cache, Pkg); |
856d3b06 DK |
700 | return Cand; |
701 | } | |
702 | /*}}}*/ | |
703 | // getInstalledVer - Returns the installed version of the given package /*{{{*/ | |
15fc8636 | 704 | pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache, |
70e706ad DK |
705 | pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) { |
706 | if (Pkg->CurrentVer == 0) | |
fdba4d53 | 707 | return helper.canNotGetVersion(CacheSetHelper::INSTALLED, Cache, Pkg); |
856d3b06 | 708 | return Pkg.CurrentVer(); |
ffee1c2b DK |
709 | } |
710 | /*}}}*/ | |
15fc8636 | 711 | |
fdba4d53 DK |
712 | // canNotFindPackage - with the given selector and pattern /*{{{*/ |
713 | void CacheSetHelper::canNotFindPackage(enum PkgSelector const select, | |
714 | PackageContainerInterface * const pci, pkgCacheFile &Cache, | |
715 | std::string const &pattern) { | |
716 | switch (select) { | |
586d8704 | 717 | APT_IGNORE_DEPRECATED_PUSH |
fdba4d53 DK |
718 | case REGEX: canNotFindRegEx(pci, Cache, pattern); break; |
719 | case TASK: canNotFindTask(pci, Cache, pattern); break; | |
720 | case FNMATCH: canNotFindFnmatch(pci, Cache, pattern); break; | |
721 | case PACKAGENAME: canNotFindPackage(pci, Cache, pattern); break; | |
1e064088 | 722 | case STRING: canNotFindPackage(pci, Cache, pattern); break; |
fdba4d53 | 723 | case UNKNOWN: break; |
586d8704 | 724 | APT_IGNORE_DEPRECATED_POP |
fdba4d53 | 725 | } |
bd631595 | 726 | } |
70e706ad | 727 | // canNotFindTask - handle the case no package is found for a task /*{{{*/ |
65512241 | 728 | void CacheSetHelper::canNotFindTask(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) { |
70e706ad | 729 | if (ShowError == true) |
cd7bbc47 | 730 | _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str()); |
70e706ad DK |
731 | } |
732 | /*}}}*/ | |
733 | // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/ | |
65512241 | 734 | void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) { |
70e706ad | 735 | if (ShowError == true) |
cd7bbc47 | 736 | _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str()); |
70e706ad | 737 | } |
fdba4d53 | 738 | /*}}}*/ |
16724b66 | 739 | // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/ |
b58f28d4 | 740 | void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string pattern) { |
16724b66 MV |
741 | if (ShowError == true) |
742 | _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str()); | |
743 | } | |
fdba4d53 | 744 | /*}}}*/ |
70e706ad | 745 | // canNotFindPackage - handle the case no package is found from a string/*{{{*/ |
a02db58f | 746 | APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) { |
70e706ad DK |
747 | } |
748 | /*}}}*/ | |
fdba4d53 DK |
749 | /*}}}*/ |
750 | // canNotFindPkgName - handle the case no package has this name /*{{{*/ | |
751 | pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache, | |
752 | std::string const &str) { | |
753 | if (ShowError == true) | |
754 | _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str()); | |
755 | return pkgCache::PkgIterator(Cache, 0); | |
756 | } | |
757 | /*}}}*/ | |
758 | // canNotFindVersion - for package by selector /*{{{*/ | |
759 | void CacheSetHelper::canNotFindVersion(enum VerSelector const select, VersionContainerInterface * const vci, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) | |
760 | { | |
761 | switch (select) { | |
586d8704 | 762 | APT_IGNORE_DEPRECATED_PUSH |
fdba4d53 DK |
763 | case ALL: canNotFindAllVer(vci, Cache, Pkg); break; |
764 | case INSTCAND: canNotFindInstCandVer(vci, Cache, Pkg); break; | |
765 | case CANDINST: canNotFindCandInstVer(vci, Cache, Pkg); break; | |
766 | case NEWEST: canNotFindNewestVer(Cache, Pkg); break; | |
767 | case CANDIDATE: canNotFindCandidateVer(Cache, Pkg); break; | |
768 | case INSTALLED: canNotFindInstalledVer(Cache, Pkg); break; | |
586d8704 | 769 | APT_IGNORE_DEPRECATED_POP |
fdba4d53 DK |
770 | case CANDANDINST: canNotGetCandInstVer(Cache, Pkg); break; |
771 | case RELEASE: | |
772 | case VERSIONNUMBER: | |
773 | // invalid in this branch | |
774 | break; | |
775 | } | |
776 | } | |
70e706ad | 777 | // canNotFindAllVer /*{{{*/ |
65512241 | 778 | void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &/*Cache*/, |
70e706ad DK |
779 | pkgCache::PkgIterator const &Pkg) { |
780 | if (ShowError == true) | |
edc0ef10 | 781 | _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); |
70e706ad DK |
782 | } |
783 | /*}}}*/ | |
784 | // canNotFindInstCandVer /*{{{*/ | |
fdba4d53 | 785 | void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache, |
70e706ad | 786 | pkgCache::PkgIterator const &Pkg) { |
fdba4d53 | 787 | canNotGetInstCandVer(Cache, Pkg); |
70e706ad DK |
788 | } |
789 | /*}}}*/ | |
cf28bcad | 790 | // canNotFindInstCandVer /*{{{*/ |
fdba4d53 | 791 | void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const /*vci*/, pkgCacheFile &Cache, |
cf28bcad | 792 | pkgCache::PkgIterator const &Pkg) { |
fdba4d53 | 793 | canNotGetCandInstVer(Cache, Pkg); |
cf28bcad DK |
794 | } |
795 | /*}}}*/ | |
fdba4d53 DK |
796 | /*}}}*/ |
797 | // canNotGetVersion - for package by selector /*{{{*/ | |
798 | pkgCache::VerIterator CacheSetHelper::canNotGetVersion(enum VerSelector const select, pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) { | |
799 | switch (select) { | |
586d8704 | 800 | APT_IGNORE_DEPRECATED_PUSH |
fdba4d53 DK |
801 | case NEWEST: return canNotFindNewestVer(Cache, Pkg); |
802 | case CANDIDATE: return canNotFindCandidateVer(Cache, Pkg); | |
803 | case INSTALLED: return canNotFindInstalledVer(Cache, Pkg); | |
586d8704 | 804 | APT_IGNORE_DEPRECATED_POP |
fdba4d53 DK |
805 | case CANDINST: return canNotGetCandInstVer(Cache, Pkg); |
806 | case INSTCAND: return canNotGetInstCandVer(Cache, Pkg); | |
807 | case ALL: | |
808 | case CANDANDINST: | |
809 | case RELEASE: | |
810 | case VERSIONNUMBER: | |
811 | // invalid in this branch | |
812 | return pkgCache::VerIterator(Cache, 0); | |
813 | } | |
814 | return pkgCache::VerIterator(Cache, 0); | |
815 | } | |
70e706ad DK |
816 | // canNotFindNewestVer /*{{{*/ |
817 | pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache, | |
818 | pkgCache::PkgIterator const &Pkg) { | |
819 | if (ShowError == true) | |
cd7bbc47 | 820 | _error->Insert(ErrorType, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str()); |
c8db3fff | 821 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
822 | } |
823 | /*}}}*/ | |
824 | // canNotFindCandidateVer /*{{{*/ | |
825 | pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache, | |
826 | pkgCache::PkgIterator const &Pkg) { | |
827 | if (ShowError == true) | |
cd7bbc47 | 828 | _error->Insert(ErrorType, _("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str()); |
c8db3fff | 829 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
830 | } |
831 | /*}}}*/ | |
832 | // canNotFindInstalledVer /*{{{*/ | |
833 | pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache, | |
834 | pkgCache::PkgIterator const &Pkg) { | |
835 | if (ShowError == true) | |
cd7bbc47 | 836 | _error->Insert(ErrorType, _("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str()); |
c8db3fff | 837 | return pkgCache::VerIterator(Cache, 0); |
70e706ad DK |
838 | } |
839 | /*}}}*/ | |
fdba4d53 DK |
840 | // canNotFindInstCandVer /*{{{*/ |
841 | pkgCache::VerIterator CacheSetHelper::canNotGetInstCandVer(pkgCacheFile &Cache, | |
842 | pkgCache::PkgIterator const &Pkg) { | |
843 | if (ShowError == true) | |
844 | _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); | |
845 | return pkgCache::VerIterator(Cache, 0); | |
846 | } | |
847 | /*}}}*/ | |
848 | // canNotFindInstCandVer /*{{{*/ | |
849 | pkgCache::VerIterator CacheSetHelper::canNotGetCandInstVer(pkgCacheFile &Cache, | |
850 | pkgCache::PkgIterator const &Pkg) { | |
851 | if (ShowError == true) | |
852 | _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str()); | |
853 | return pkgCache::VerIterator(Cache, 0); | |
854 | } | |
855 | /*}}}*/ | |
856 | /*}}}*/ | |
857 | // showPackageSelection - by selector and given pattern /*{{{*/ | |
2b4cead3 | 858 | void CacheSetHelper::showPackageSelection(pkgCache::PkgIterator const &pkg, enum PkgSelector const select, |
fdba4d53 DK |
859 | std::string const &pattern) { |
860 | switch (select) { | |
586d8704 | 861 | APT_IGNORE_DEPRECATED_PUSH |
fdba4d53 DK |
862 | case REGEX: showRegExSelection(pkg, pattern); break; |
863 | case TASK: showTaskSelection(pkg, pattern); break; | |
864 | case FNMATCH: showFnmatchSelection(pkg, pattern); break; | |
586d8704 | 865 | APT_IGNORE_DEPRECATED_POP |
fdba4d53 | 866 | case PACKAGENAME: /* no suprises here */ break; |
1e064088 | 867 | case STRING: /* handled by the special cases */ break; |
fdba4d53 DK |
868 | case UNKNOWN: break; |
869 | } | |
870 | } | |
15fc8636 | 871 | // showTaskSelection /*{{{*/ |
a02db58f | 872 | APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/, |
65512241 | 873 | std::string const &/*pattern*/) { |
15fc8636 DK |
874 | } |
875 | /*}}}*/ | |
876 | // showRegExSelection /*{{{*/ | |
a02db58f | 877 | APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/, |
65512241 | 878 | std::string const &/*pattern*/) { |
15fc8636 DK |
879 | } |
880 | /*}}}*/ | |
16724b66 | 881 | // showFnmatchSelection /*{{{*/ |
b58f28d4 MV |
882 | APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &/*pkg*/, |
883 | std::string const &/*pattern*/) { | |
16724b66 MV |
884 | } |
885 | /*}}}*/ | |
fdba4d53 DK |
886 | /*}}}*/ |
887 | // showVersionSelection /*{{{*/ | |
2b4cead3 | 888 | void CacheSetHelper::showVersionSelection(pkgCache::PkgIterator const &Pkg, |
fdba4d53 DK |
889 | pkgCache::VerIterator const &Ver, enum VerSelector const select, std::string const &pattern) { |
890 | switch (select) { | |
586d8704 | 891 | APT_IGNORE_DEPRECATED_PUSH |
fdba4d53 DK |
892 | case RELEASE: |
893 | showSelectedVersion(Pkg, Ver, pattern, true); | |
894 | break; | |
895 | case VERSIONNUMBER: | |
896 | showSelectedVersion(Pkg, Ver, pattern, false); | |
897 | break; | |
586d8704 | 898 | APT_IGNORE_DEPRECATED_POP |
fdba4d53 DK |
899 | case NEWEST: |
900 | case CANDIDATE: | |
901 | case INSTALLED: | |
902 | case CANDINST: | |
903 | case INSTCAND: | |
904 | case ALL: | |
905 | case CANDANDINST: | |
906 | // not really suprises, but in fact: just not implemented | |
907 | break; | |
908 | } | |
909 | } | |
a02db58f | 910 | APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/, |
65512241 DK |
911 | pkgCache::VerIterator const /*Ver*/, |
912 | std::string const &/*ver*/, | |
913 | bool const /*verIsRel*/) { | |
15fc8636 DK |
914 | } |
915 | /*}}}*/ | |
c8a4ce6c DK |
916 | |
917 | CacheSetHelper::CacheSetHelper(bool const ShowError, GlobalError::MsgType ErrorType) : | |
6c55f07a | 918 | ShowError(ShowError), ErrorType(ErrorType), d(NULL) {} |
c8a4ce6c DK |
919 | CacheSetHelper::~CacheSetHelper() {} |
920 | ||
6c55f07a DK |
921 | PackageContainerInterface::PackageContainerInterface() : ConstructedBy(CacheSetHelper::UNKNOWN), d(NULL) {} |
922 | PackageContainerInterface::PackageContainerInterface(CacheSetHelper::PkgSelector const by) : ConstructedBy(by), d(NULL) {} | |
923 | PackageContainerInterface& PackageContainerInterface::operator=(PackageContainerInterface const &other) { | |
924 | if (this != &other) | |
925 | this->ConstructedBy = other.ConstructedBy; | |
926 | return *this; | |
927 | } | |
c8a4ce6c DK |
928 | PackageContainerInterface::~PackageContainerInterface() {} |
929 | ||
3707fd4f DK |
930 | PackageUniverse::PackageUniverse(pkgCache * const Owner) : _cont(Owner), d(NULL) {} |
931 | PackageUniverse::PackageUniverse(pkgCacheFile * const Owner) : _cont(Owner->GetPkgCache()), d(NULL) {} | |
c8a4ce6c DK |
932 | PackageUniverse::~PackageUniverse() {} |
933 | ||
6c55f07a DK |
934 | VersionContainerInterface::VersionContainerInterface() : d(NULL) {} |
935 | VersionContainerInterface& VersionContainerInterface::operator=(VersionContainerInterface const &) { | |
936 | return *this; | |
937 | } | |
938 | ||
c8a4ce6c | 939 | VersionContainerInterface::~VersionContainerInterface() {} |
ffee1c2b | 940 | } |