cacheset.cc 22 KB

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