cacheset.cc 22 KB

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