cacheset.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
  273. FromFnmatch(pci, Cache, str, helper) == false)
  274. #endif
  275. FromRegEx(pci, Cache, str, helper) == false)
  276. {
  277. helper.canNotFindPackage(pci, Cache, str);
  278. found = false;
  279. }
  280. if (found == true)
  281. _error->RevertToStack();
  282. else
  283. _error->MergeWithStack();
  284. return found;
  285. }
  286. /*}}}*/
  287. // FromCommandLine - Return all packages specified on commandline /*{{{*/
  288. bool PackageContainerInterface::FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper) {
  289. bool found = false;
  290. for (const char **I = cmdline; *I != 0; ++I)
  291. found |= PackageContainerInterface::FromString(pci, Cache, *I, helper);
  292. return found;
  293. }
  294. /*}}}*/
  295. // FromModifierCommandLine - helper doing the work for PKG:GroupedFromCommandLine /*{{{*/
  296. bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, PackageContainerInterface * const pci,
  297. pkgCacheFile &Cache, const char * cmdline,
  298. std::list<Modifier> const &mods, CacheSetHelper &helper) {
  299. std::string str = cmdline;
  300. unsigned short fallback = modID;
  301. bool modifierPresent = false;
  302. for (std::list<Modifier>::const_iterator mod = mods.begin();
  303. mod != mods.end(); ++mod) {
  304. size_t const alength = strlen(mod->Alias);
  305. switch(mod->Pos) {
  306. case Modifier::POSTFIX:
  307. if (str.compare(str.length() - alength, alength,
  308. mod->Alias, 0, alength) != 0)
  309. continue;
  310. str.erase(str.length() - alength);
  311. modID = mod->ID;
  312. break;
  313. case Modifier::PREFIX:
  314. continue;
  315. case Modifier::NONE:
  316. continue;
  317. }
  318. modifierPresent = true;
  319. break;
  320. }
  321. if (modifierPresent == true) {
  322. bool const errors = helper.showErrors(false);
  323. pkgCache::PkgIterator Pkg = FromName(Cache, cmdline, helper);
  324. helper.showErrors(errors);
  325. if (Pkg.end() == false) {
  326. pci->insert(Pkg);
  327. modID = fallback;
  328. return true;
  329. }
  330. }
  331. return FromString(pci, Cache, str, helper);
  332. }
  333. /*}}}*/
  334. // FromModifierCommandLine - helper doing the work for VER:GroupedFromCommandLine /*{{{*/
  335. bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
  336. VersionContainerInterface * const vci,
  337. pkgCacheFile &Cache, const char * cmdline,
  338. std::list<Modifier> const &mods,
  339. CacheSetHelper &helper) {
  340. Version select = NEWEST;
  341. std::string str = cmdline;
  342. bool modifierPresent = false;
  343. unsigned short fallback = modID;
  344. for (std::list<Modifier>::const_iterator mod = mods.begin();
  345. mod != mods.end(); ++mod) {
  346. if (modID == fallback && mod->ID == fallback)
  347. select = mod->SelectVersion;
  348. size_t const alength = strlen(mod->Alias);
  349. switch(mod->Pos) {
  350. case Modifier::POSTFIX:
  351. if (str.compare(str.length() - alength, alength,
  352. mod->Alias, 0, alength) != 0)
  353. continue;
  354. str.erase(str.length() - alength);
  355. modID = mod->ID;
  356. select = mod->SelectVersion;
  357. break;
  358. case Modifier::PREFIX:
  359. continue;
  360. case Modifier::NONE:
  361. continue;
  362. }
  363. modifierPresent = true;
  364. break;
  365. }
  366. if (modifierPresent == true) {
  367. bool const errors = helper.showErrors(false);
  368. bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true);
  369. helper.showErrors(errors);
  370. if (found == true) {
  371. modID = fallback;
  372. return true;
  373. }
  374. }
  375. return FromString(vci, Cache, str, select, helper);
  376. }
  377. /*}}}*/
  378. // FromCommandLine - Return all versions specified on commandline /*{{{*/
  379. bool VersionContainerInterface::FromCommandLine(VersionContainerInterface * const vci,
  380. pkgCacheFile &Cache, const char **cmdline,
  381. Version const &fallback, CacheSetHelper &helper) {
  382. bool found = false;
  383. for (const char **I = cmdline; *I != 0; ++I)
  384. found |= VersionContainerInterface::FromString(vci, Cache, *I, fallback, helper);
  385. return found;
  386. }
  387. /*}}}*/
  388. // FromString - Returns all versions spedcified by a string /*{{{*/
  389. bool VersionContainerInterface::FromString(VersionContainerInterface * const vci,
  390. pkgCacheFile &Cache, std::string pkg,
  391. Version const &fallback, CacheSetHelper &helper,
  392. bool const onlyFromName) {
  393. std::string ver;
  394. bool verIsRel = false;
  395. size_t const vertag = pkg.find_last_of("/=");
  396. if (vertag != std::string::npos) {
  397. ver = pkg.substr(vertag+1);
  398. verIsRel = (pkg[vertag] == '/');
  399. pkg.erase(vertag);
  400. }
  401. PackageSet pkgset;
  402. if (onlyFromName == false)
  403. PackageContainerInterface::FromString(&pkgset, Cache, pkg, helper);
  404. else {
  405. pkgset.insert(PackageContainerInterface::FromName(Cache, pkg, helper));
  406. }
  407. bool errors = true;
  408. if (pkgset.getConstructor() != PackageSet::UNKNOWN)
  409. errors = helper.showErrors(false);
  410. bool found = false;
  411. for (PackageSet::const_iterator P = pkgset.begin();
  412. P != pkgset.end(); ++P) {
  413. if (vertag == std::string::npos) {
  414. found |= VersionContainerInterface::FromPackage(vci, Cache, P, fallback, helper);
  415. continue;
  416. }
  417. pkgCache::VerIterator V;
  418. if (ver == "installed")
  419. V = getInstalledVer(Cache, P, helper);
  420. else if (ver == "candidate")
  421. V = getCandidateVer(Cache, P, helper);
  422. else if (ver == "newest") {
  423. if (P->VersionList != 0)
  424. V = P.VersionList();
  425. else
  426. V = helper.canNotFindNewestVer(Cache, P);
  427. } else {
  428. pkgVersionMatch Match(ver, (verIsRel == true ? pkgVersionMatch::Release :
  429. pkgVersionMatch::Version));
  430. V = Match.Find(P);
  431. if (V.end() == true) {
  432. if (verIsRel == true)
  433. _error->Error(_("Release '%s' for '%s' was not found"),
  434. ver.c_str(), P.FullName(true).c_str());
  435. else
  436. _error->Error(_("Version '%s' for '%s' was not found"),
  437. ver.c_str(), P.FullName(true).c_str());
  438. continue;
  439. }
  440. }
  441. if (V.end() == true)
  442. continue;
  443. helper.showSelectedVersion(P, V, ver, verIsRel);
  444. vci->insert(V);
  445. found = true;
  446. }
  447. if (pkgset.getConstructor() != PackageSet::UNKNOWN)
  448. helper.showErrors(errors);
  449. return found;
  450. }
  451. /*}}}*/
  452. // FromPackage - versions from package based on fallback /*{{{*/
  453. bool VersionContainerInterface::FromPackage(VersionContainerInterface * const vci,
  454. pkgCacheFile &Cache,
  455. pkgCache::PkgIterator const &P,
  456. Version const &fallback,
  457. CacheSetHelper &helper) {
  458. pkgCache::VerIterator V;
  459. bool showErrors;
  460. bool found = false;
  461. switch(fallback) {
  462. case ALL:
  463. if (P->VersionList != 0)
  464. for (V = P.VersionList(); V.end() != true; ++V)
  465. found |= vci->insert(V);
  466. else
  467. helper.canNotFindAllVer(vci, Cache, P);
  468. break;
  469. case CANDANDINST:
  470. found |= vci->insert(getInstalledVer(Cache, P, helper));
  471. found |= vci->insert(getCandidateVer(Cache, P, helper));
  472. break;
  473. case CANDIDATE:
  474. found |= vci->insert(getCandidateVer(Cache, P, helper));
  475. break;
  476. case INSTALLED:
  477. found |= vci->insert(getInstalledVer(Cache, P, helper));
  478. break;
  479. case CANDINST:
  480. showErrors = helper.showErrors(false);
  481. V = getCandidateVer(Cache, P, helper);
  482. if (V.end() == true)
  483. V = getInstalledVer(Cache, P, helper);
  484. helper.showErrors(showErrors);
  485. if (V.end() == false)
  486. found |= vci->insert(V);
  487. else
  488. helper.canNotFindInstCandVer(vci, Cache, P);
  489. break;
  490. case INSTCAND:
  491. showErrors = helper.showErrors(false);
  492. V = getInstalledVer(Cache, P, helper);
  493. if (V.end() == true)
  494. V = getCandidateVer(Cache, P, helper);
  495. helper.showErrors(showErrors);
  496. if (V.end() == false)
  497. found |= vci->insert(V);
  498. else
  499. helper.canNotFindInstCandVer(vci, Cache, P);
  500. break;
  501. case NEWEST:
  502. if (P->VersionList != 0)
  503. found |= vci->insert(P.VersionList());
  504. else
  505. helper.canNotFindNewestVer(Cache, P);
  506. break;
  507. }
  508. return found;
  509. }
  510. /*}}}*/
  511. // getCandidateVer - Returns the candidate version of the given package /*{{{*/
  512. pkgCache::VerIterator VersionContainerInterface::getCandidateVer(pkgCacheFile &Cache,
  513. pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
  514. pkgCache::VerIterator Cand;
  515. if (Cache.IsPolicyBuilt() == true || Cache.IsDepCacheBuilt() == false) {
  516. if (unlikely(Cache.GetPolicy() == 0))
  517. return pkgCache::VerIterator(Cache);
  518. Cand = Cache.GetPolicy()->GetCandidateVer(Pkg);
  519. } else {
  520. Cand = Cache[Pkg].CandidateVerIter(Cache);
  521. }
  522. if (Cand.end() == true)
  523. return helper.canNotFindCandidateVer(Cache, Pkg);
  524. return Cand;
  525. }
  526. /*}}}*/
  527. // getInstalledVer - Returns the installed version of the given package /*{{{*/
  528. pkgCache::VerIterator VersionContainerInterface::getInstalledVer(pkgCacheFile &Cache,
  529. pkgCache::PkgIterator const &Pkg, CacheSetHelper &helper) {
  530. if (Pkg->CurrentVer == 0)
  531. return helper.canNotFindInstalledVer(Cache, Pkg);
  532. return Pkg.CurrentVer();
  533. }
  534. /*}}}*/
  535. // canNotFindPkgName - handle the case no package has this name /*{{{*/
  536. pkgCache::PkgIterator CacheSetHelper::canNotFindPkgName(pkgCacheFile &Cache,
  537. std::string const &str) {
  538. if (ShowError == true)
  539. _error->Insert(ErrorType, _("Unable to locate package %s"), str.c_str());
  540. return pkgCache::PkgIterator(Cache, 0);
  541. }
  542. /*}}}*/
  543. // canNotFindTask - handle the case no package is found for a task /*{{{*/
  544. void CacheSetHelper::canNotFindTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
  545. if (ShowError == true)
  546. _error->Insert(ErrorType, _("Couldn't find task '%s'"), pattern.c_str());
  547. }
  548. /*}}}*/
  549. // canNotFindRegEx - handle the case no package is found by a regex /*{{{*/
  550. void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
  551. if (ShowError == true)
  552. _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
  553. }
  554. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
  555. // canNotFindFnmatch - handle the case no package is found by a fnmatch /*{{{*/
  556. void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
  557. if (ShowError == true)
  558. _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
  559. }
  560. #endif /*}}}*/
  561. // canNotFindPackage - handle the case no package is found from a string/*{{{*/
  562. void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
  563. }
  564. /*}}}*/
  565. // canNotFindAllVer /*{{{*/
  566. void CacheSetHelper::canNotFindAllVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
  567. pkgCache::PkgIterator const &Pkg) {
  568. if (ShowError == true)
  569. _error->Insert(ErrorType, _("Can't select versions from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
  570. }
  571. /*}}}*/
  572. // canNotFindInstCandVer /*{{{*/
  573. void CacheSetHelper::canNotFindInstCandVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
  574. pkgCache::PkgIterator const &Pkg) {
  575. if (ShowError == true)
  576. _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
  577. }
  578. /*}}}*/
  579. // canNotFindInstCandVer /*{{{*/
  580. void CacheSetHelper::canNotFindCandInstVer(VersionContainerInterface * const vci, pkgCacheFile &Cache,
  581. pkgCache::PkgIterator const &Pkg) {
  582. if (ShowError == true)
  583. _error->Insert(ErrorType, _("Can't select installed nor candidate version from package '%s' as it has neither of them"), Pkg.FullName(true).c_str());
  584. }
  585. /*}}}*/
  586. // canNotFindNewestVer /*{{{*/
  587. pkgCache::VerIterator CacheSetHelper::canNotFindNewestVer(pkgCacheFile &Cache,
  588. pkgCache::PkgIterator const &Pkg) {
  589. if (ShowError == true)
  590. _error->Insert(ErrorType, _("Can't select newest version from package '%s' as it is purely virtual"), Pkg.FullName(true).c_str());
  591. return pkgCache::VerIterator(Cache, 0);
  592. }
  593. /*}}}*/
  594. // canNotFindCandidateVer /*{{{*/
  595. pkgCache::VerIterator CacheSetHelper::canNotFindCandidateVer(pkgCacheFile &Cache,
  596. pkgCache::PkgIterator const &Pkg) {
  597. if (ShowError == true)
  598. _error->Insert(ErrorType, _("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str());
  599. return pkgCache::VerIterator(Cache, 0);
  600. }
  601. /*}}}*/
  602. // canNotFindInstalledVer /*{{{*/
  603. pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache,
  604. pkgCache::PkgIterator const &Pkg) {
  605. if (ShowError == true)
  606. _error->Insert(ErrorType, _("Can't select installed version from package %s as it is not installed"), Pkg.FullName(true).c_str());
  607. return pkgCache::VerIterator(Cache, 0);
  608. }
  609. /*}}}*/
  610. // showTaskSelection /*{{{*/
  611. void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &pkg,
  612. std::string const &pattern) {
  613. }
  614. /*}}}*/
  615. // showRegExSelection /*{{{*/
  616. void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &pkg,
  617. std::string const &pattern) {
  618. }
  619. /*}}}*/
  620. #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
  621. // showFnmatchSelection /*{{{*/
  622. void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
  623. std::string const &pattern) {
  624. }
  625. /*}}}*/
  626. #endif
  627. // showSelectedVersion /*{{{*/
  628. void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &Pkg,
  629. pkgCache::VerIterator const Ver,
  630. std::string const &ver,
  631. bool const verIsRel) {
  632. }
  633. /*}}}*/
  634. }