cacheset.cc 23 KB

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