deblistparser.cc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: deblistparser.cc,v 1.29.2.5 2004/01/06 01:43:44 mdz Exp $
  4. /* ######################################################################
  5. Package Cache Generator - Generator for the cache structure.
  6. This builds the cache structure from the abstract package list parser.
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <apt-pkg/deblistparser.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/configuration.h>
  13. #include <apt-pkg/aptconfiguration.h>
  14. #include <apt-pkg/strutl.h>
  15. #include <apt-pkg/crc-16.h>
  16. #include <apt-pkg/md5.h>
  17. #include <ctype.h>
  18. #include <system.h>
  19. /*}}}*/
  20. static debListParser::WordList PrioList[] = {{"important",pkgCache::State::Important},
  21. {"required",pkgCache::State::Required},
  22. {"standard",pkgCache::State::Standard},
  23. {"optional",pkgCache::State::Optional},
  24. {"extra",pkgCache::State::Extra},
  25. {}};
  26. // ListParser::debListParser - Constructor /*{{{*/
  27. // ---------------------------------------------------------------------
  28. /* Provide an architecture and only this one and "all" will be accepted
  29. in Step(), if no Architecture is given we will accept every arch
  30. we would accept in general with checkArchitecture() */
  31. debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
  32. Arch(Arch) {
  33. if (Arch == "native")
  34. this->Arch = _config->Find("APT::Architecture");
  35. }
  36. /*}}}*/
  37. // ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
  38. // ---------------------------------------------------------------------
  39. /* */
  40. unsigned long debListParser::UniqFindTagWrite(const char *Tag)
  41. {
  42. const char *Start;
  43. const char *Stop;
  44. if (Section.Find(Tag,Start,Stop) == false)
  45. return 0;
  46. return WriteUniqString(Start,Stop - Start);
  47. }
  48. /*}}}*/
  49. // ListParser::Package - Return the package name /*{{{*/
  50. // ---------------------------------------------------------------------
  51. /* This is to return the name of the package this section describes */
  52. string debListParser::Package() {
  53. string const Result = Section.FindS("Package");
  54. if(unlikely(Result.empty() == true))
  55. _error->Error("Encountered a section with no Package: header");
  56. return Result;
  57. }
  58. /*}}}*/
  59. // ListParser::Architecture - Return the package arch /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* This will return the Architecture of the package this section describes
  62. Note that architecture "all" packages will get the architecture of the
  63. Packages file parsed here. */
  64. string debListParser::Architecture() {
  65. string const Result = Section.FindS("Architecture");
  66. if (Result.empty() == true || Result == "all") {
  67. if (Arch.empty() == true)
  68. /* FIXME: this is a problem for installed arch all
  69. packages as we don't know from which arch this
  70. package was installed - and therefore which
  71. dependency this package resolves. */
  72. return _config->Find("APT::Architecture");
  73. else
  74. return Arch;
  75. }
  76. return Result;
  77. }
  78. /*}}}*/
  79. // ListParser::ArchitectureAll /*{{{*/
  80. // ---------------------------------------------------------------------
  81. /* */
  82. bool debListParser::ArchitectureAll() {
  83. return Section.FindS("Architecture") == "all";
  84. }
  85. /*}}}*/
  86. // ListParser::Version - Return the version string /*{{{*/
  87. // ---------------------------------------------------------------------
  88. /* This is to return the string describing the version in debian form,
  89. epoch:upstream-release. If this returns the blank string then the
  90. entry is assumed to only describe package properties */
  91. string debListParser::Version()
  92. {
  93. return Section.FindS("Version");
  94. }
  95. /*}}}*/
  96. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  97. // ---------------------------------------------------------------------
  98. /* */
  99. bool debListParser::NewVersion(pkgCache::VerIterator Ver)
  100. {
  101. // Parse the section
  102. Ver->Section = UniqFindTagWrite("Section");
  103. // Parse multi-arch
  104. if (Section.FindS("Architecture") == "all")
  105. /* Arch all packages can't have a Multi-Arch field,
  106. but we need a special treatment for them nonetheless */
  107. Ver->MultiArch = pkgCache::Version::All;
  108. else
  109. {
  110. string const MultiArch = Section.FindS("Multi-Arch");
  111. if (MultiArch.empty() == true)
  112. Ver->MultiArch = pkgCache::Version::None;
  113. else if (MultiArch == "same")
  114. Ver->MultiArch = pkgCache::Version::Same;
  115. else if (MultiArch == "foreign")
  116. Ver->MultiArch = pkgCache::Version::Foreign;
  117. else if (MultiArch == "allowed")
  118. Ver->MultiArch = pkgCache::Version::Allowed;
  119. else
  120. {
  121. _error->Warning("Unknown Multi-Arch type »%s« for package »%s«",
  122. MultiArch.c_str(), Section.FindS("Package").c_str());
  123. Ver->MultiArch = pkgCache::Version::None;
  124. }
  125. }
  126. // Archive Size
  127. Ver->Size = (unsigned)Section.FindI("Size");
  128. // Unpacked Size (in K)
  129. Ver->InstalledSize = (unsigned)Section.FindI("Installed-Size");
  130. Ver->InstalledSize *= 1024;
  131. // Priority
  132. const char *Start;
  133. const char *Stop;
  134. if (Section.Find("Priority",Start,Stop) == true)
  135. {
  136. if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false)
  137. Ver->Priority = pkgCache::State::Extra;
  138. }
  139. if (Ver->MultiArch == pkgCache::Version::All)
  140. {
  141. /* We maintain a "pseudo" arch=all package for architecture all versions
  142. on which these versions can depend on. This pseudo package is many used
  143. for downloading/installing: The other pseudo-packages will degenerate
  144. to a NOP in the download/install step - this package will ensure that
  145. it is downloaded only one time and installed only one time -- even if
  146. the architecture bound versions coming in and out on regular basis. */
  147. if (strcmp(Ver.Arch(true),"all") == 0)
  148. return true;
  149. else
  150. {
  151. // our pseudo packages have no size to not confuse the fetcher
  152. Ver->Size = 0;
  153. Ver->InstalledSize = 0;
  154. }
  155. }
  156. if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
  157. return false;
  158. if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
  159. return false;
  160. if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
  161. return false;
  162. if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
  163. return false;
  164. if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false)
  165. return false;
  166. if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false)
  167. return false;
  168. if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false)
  169. return false;
  170. if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false)
  171. return false;
  172. // Obsolete.
  173. if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false)
  174. return false;
  175. if (ParseProvides(Ver) == false)
  176. return false;
  177. return true;
  178. }
  179. /*}}}*/
  180. // ListParser::Description - Return the description string /*{{{*/
  181. // ---------------------------------------------------------------------
  182. /* This is to return the string describing the package in debian
  183. form. If this returns the blank string then the entry is assumed to
  184. only describe package properties */
  185. string debListParser::Description()
  186. {
  187. string const lang = DescriptionLanguage();
  188. if (lang.empty())
  189. return Section.FindS("Description");
  190. else
  191. return Section.FindS(string("Description-").append(lang).c_str());
  192. }
  193. /*}}}*/
  194. // ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
  195. // ---------------------------------------------------------------------
  196. /* This is to return the string describing the language of
  197. description. If this returns the blank string then the entry is
  198. assumed to describe original description. */
  199. string debListParser::DescriptionLanguage()
  200. {
  201. if (Section.FindS("Description").empty() == false)
  202. return "";
  203. std::vector<string> const lang = APT::Configuration::getLanguages();
  204. for (std::vector<string>::const_iterator l = lang.begin();
  205. l != lang.end(); l++)
  206. if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
  207. return *l;
  208. return "";
  209. }
  210. /*}}}*/
  211. // ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
  212. // ---------------------------------------------------------------------
  213. /* This is to return the md5 string to allow the check if it is the right
  214. description. If no Description-md5 is found in the section it will be
  215. calculated.
  216. */
  217. MD5SumValue debListParser::Description_md5()
  218. {
  219. string value = Section.FindS("Description-md5");
  220. if (value.empty())
  221. {
  222. MD5Summation md5;
  223. md5.Add((Description() + "\n").c_str());
  224. return md5.Result();
  225. } else
  226. return MD5SumValue(value);
  227. }
  228. /*}}}*/
  229. // ListParser::UsePackage - Update a package structure /*{{{*/
  230. // ---------------------------------------------------------------------
  231. /* This is called to update the package with any new information
  232. that might be found in the section */
  233. bool debListParser::UsePackage(pkgCache::PkgIterator Pkg,
  234. pkgCache::VerIterator Ver)
  235. {
  236. if (Pkg->Section == 0)
  237. Pkg->Section = UniqFindTagWrite("Section");
  238. // Packages which are not from "our" arch doesn't get the essential flag
  239. string const static myArch = _config->Find("APT::Architecture");
  240. if (Pkg->Arch != 0 && myArch == Pkg.Arch())
  241. if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
  242. return false;
  243. if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false)
  244. return false;
  245. if (strcmp(Pkg.Name(),"apt") == 0)
  246. Pkg->Flags |= pkgCache::Flag::Important;
  247. if (ParseStatus(Pkg,Ver) == false)
  248. return false;
  249. return true;
  250. }
  251. /*}}}*/
  252. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  253. // ---------------------------------------------------------------------
  254. /* */
  255. unsigned short debListParser::VersionHash()
  256. {
  257. const char *Sections[] ={"Installed-Size",
  258. "Depends",
  259. "Pre-Depends",
  260. // "Suggests",
  261. // "Recommends",
  262. "Conflicts",
  263. "Breaks",
  264. "Replaces",0};
  265. unsigned long Result = INIT_FCS;
  266. char S[1024];
  267. for (const char **I = Sections; *I != 0; I++)
  268. {
  269. const char *Start;
  270. const char *End;
  271. if (Section.Find(*I,Start,End) == false || End - Start >= (signed)sizeof(S))
  272. continue;
  273. /* Strip out any spaces from the text, this undoes dpkgs reformatting
  274. of certain fields. dpkg also has the rather interesting notion of
  275. reformatting depends operators < -> <= */
  276. char *I = S;
  277. for (; Start != End; Start++)
  278. {
  279. if (isspace(*Start) == 0)
  280. *I++ = tolower_ascii(*Start);
  281. if (*Start == '<' && Start[1] != '<' && Start[1] != '=')
  282. *I++ = '=';
  283. if (*Start == '>' && Start[1] != '>' && Start[1] != '=')
  284. *I++ = '=';
  285. }
  286. Result = AddCRC16(Result,S,I - S);
  287. }
  288. return Result;
  289. }
  290. /*}}}*/
  291. // ListParser::ParseStatus - Parse the status field /*{{{*/
  292. // ---------------------------------------------------------------------
  293. /* Status lines are of the form,
  294. Status: want flag status
  295. want = unknown, install, hold, deinstall, purge
  296. flag = ok, reinstreq, hold, hold-reinstreq
  297. status = not-installed, unpacked, half-configured,
  298. half-installed, config-files, post-inst-failed,
  299. removal-failed, installed
  300. Some of the above are obsolete (I think?) flag = hold-* and
  301. status = post-inst-failed, removal-failed at least.
  302. */
  303. bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg,
  304. pkgCache::VerIterator Ver)
  305. {
  306. const char *Start;
  307. const char *Stop;
  308. if (Section.Find("Status",Start,Stop) == false)
  309. return true;
  310. // Isolate the first word
  311. const char *I = Start;
  312. for(; I < Stop && *I != ' '; I++);
  313. if (I >= Stop || *I != ' ')
  314. return _error->Error("Malformed Status line");
  315. // Process the want field
  316. WordList WantList[] = {{"unknown",pkgCache::State::Unknown},
  317. {"install",pkgCache::State::Install},
  318. {"hold",pkgCache::State::Hold},
  319. {"deinstall",pkgCache::State::DeInstall},
  320. {"purge",pkgCache::State::Purge},
  321. {}};
  322. if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
  323. return _error->Error("Malformed 1st word in the Status line");
  324. // Isloate the next word
  325. I++;
  326. Start = I;
  327. for(; I < Stop && *I != ' '; I++);
  328. if (I >= Stop || *I != ' ')
  329. return _error->Error("Malformed status line, no 2nd word");
  330. // Process the flag field
  331. WordList FlagList[] = {{"ok",pkgCache::State::Ok},
  332. {"reinstreq",pkgCache::State::ReInstReq},
  333. {"hold",pkgCache::State::HoldInst},
  334. {"hold-reinstreq",pkgCache::State::HoldReInstReq},
  335. {}};
  336. if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
  337. return _error->Error("Malformed 2nd word in the Status line");
  338. // Isloate the last word
  339. I++;
  340. Start = I;
  341. for(; I < Stop && *I != ' '; I++);
  342. if (I != Stop)
  343. return _error->Error("Malformed Status line, no 3rd word");
  344. // Process the flag field
  345. WordList StatusList[] = {{"not-installed",pkgCache::State::NotInstalled},
  346. {"unpacked",pkgCache::State::UnPacked},
  347. {"half-configured",pkgCache::State::HalfConfigured},
  348. {"installed",pkgCache::State::Installed},
  349. {"half-installed",pkgCache::State::HalfInstalled},
  350. {"config-files",pkgCache::State::ConfigFiles},
  351. {"triggers-awaited",pkgCache::State::TriggersAwaited},
  352. {"triggers-pending",pkgCache::State::TriggersPending},
  353. {"post-inst-failed",pkgCache::State::HalfConfigured},
  354. {"removal-failed",pkgCache::State::HalfInstalled},
  355. {}};
  356. if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
  357. return _error->Error("Malformed 3rd word in the Status line");
  358. /* A Status line marks the package as indicating the current
  359. version as well. Only if it is actually installed.. Otherwise
  360. the interesting dpkg handling of the status file creates bogus
  361. entries. */
  362. if (!(Pkg->CurrentState == pkgCache::State::NotInstalled ||
  363. Pkg->CurrentState == pkgCache::State::ConfigFiles))
  364. {
  365. if (Ver.end() == true)
  366. _error->Warning("Encountered status field in a non-version description");
  367. else
  368. Pkg->CurrentVer = Ver.Index();
  369. }
  370. return true;
  371. }
  372. const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
  373. {
  374. // Determine the operator
  375. switch (*I)
  376. {
  377. case '<':
  378. I++;
  379. if (*I == '=')
  380. {
  381. I++;
  382. Op = pkgCache::Dep::LessEq;
  383. break;
  384. }
  385. if (*I == '<')
  386. {
  387. I++;
  388. Op = pkgCache::Dep::Less;
  389. break;
  390. }
  391. // < is the same as <= and << is really Cs < for some reason
  392. Op = pkgCache::Dep::LessEq;
  393. break;
  394. case '>':
  395. I++;
  396. if (*I == '=')
  397. {
  398. I++;
  399. Op = pkgCache::Dep::GreaterEq;
  400. break;
  401. }
  402. if (*I == '>')
  403. {
  404. I++;
  405. Op = pkgCache::Dep::Greater;
  406. break;
  407. }
  408. // > is the same as >= and >> is really Cs > for some reason
  409. Op = pkgCache::Dep::GreaterEq;
  410. break;
  411. case '=':
  412. Op = pkgCache::Dep::Equals;
  413. I++;
  414. break;
  415. // HACK around bad package definitions
  416. default:
  417. Op = pkgCache::Dep::Equals;
  418. break;
  419. }
  420. return I;
  421. }
  422. /*}}}*/
  423. // ListParser::ParseDepends - Parse a dependency element /*{{{*/
  424. // ---------------------------------------------------------------------
  425. /* This parses the dependency elements out of a standard string in place,
  426. bit by bit. */
  427. const char *debListParser::ParseDepends(const char *Start,const char *Stop,
  428. string &Package,string &Ver,
  429. unsigned int &Op, bool const &ParseArchFlags,
  430. bool const &StripMultiArch)
  431. {
  432. // Strip off leading space
  433. for (;Start != Stop && isspace(*Start) != 0; Start++);
  434. // Parse off the package name
  435. const char *I = Start;
  436. for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
  437. *I != ',' && *I != '|'; I++);
  438. // Malformed, no '('
  439. if (I != Stop && *I == ')')
  440. return 0;
  441. if (I == Start)
  442. return 0;
  443. // Stash the package name
  444. Package.assign(Start,I - Start);
  445. // We don't want to confuse library users which can't handle MultiArch
  446. if (StripMultiArch == true) {
  447. size_t const found = Package.rfind(':');
  448. if (found != string::npos)
  449. Package = Package.substr(0,found);
  450. }
  451. // Skip white space to the '('
  452. for (;I != Stop && isspace(*I) != 0 ; I++);
  453. // Parse a version
  454. if (I != Stop && *I == '(')
  455. {
  456. // Skip the '('
  457. for (I++; I != Stop && isspace(*I) != 0 ; I++);
  458. if (I + 3 >= Stop)
  459. return 0;
  460. I = ConvertRelation(I,Op);
  461. // Skip whitespace
  462. for (;I != Stop && isspace(*I) != 0; I++);
  463. Start = I;
  464. for (;I != Stop && *I != ')'; I++);
  465. if (I == Stop || Start == I)
  466. return 0;
  467. // Skip trailing whitespace
  468. const char *End = I;
  469. for (; End > Start && isspace(End[-1]); End--);
  470. Ver.assign(Start,End-Start);
  471. I++;
  472. }
  473. else
  474. {
  475. Ver.clear();
  476. Op = pkgCache::Dep::NoOp;
  477. }
  478. // Skip whitespace
  479. for (;I != Stop && isspace(*I) != 0; I++);
  480. if (ParseArchFlags == true)
  481. {
  482. string arch = _config->Find("APT::Architecture");
  483. // Parse an architecture
  484. if (I != Stop && *I == '[')
  485. {
  486. // malformed
  487. I++;
  488. if (I == Stop)
  489. return 0;
  490. const char *End = I;
  491. bool Found = false;
  492. bool NegArch = false;
  493. while (I != Stop)
  494. {
  495. // look for whitespace or ending ']'
  496. while (End != Stop && !isspace(*End) && *End != ']')
  497. End++;
  498. if (End == Stop)
  499. return 0;
  500. if (*I == '!')
  501. {
  502. NegArch = true;
  503. I++;
  504. }
  505. if (stringcmp(arch,I,End) == 0)
  506. Found = true;
  507. if (*End++ == ']') {
  508. I = End;
  509. break;
  510. }
  511. I = End;
  512. for (;I != Stop && isspace(*I) != 0; I++);
  513. }
  514. if (NegArch)
  515. Found = !Found;
  516. if (Found == false)
  517. Package = ""; /* not for this arch */
  518. }
  519. // Skip whitespace
  520. for (;I != Stop && isspace(*I) != 0; I++);
  521. }
  522. if (I != Stop && *I == '|')
  523. Op |= pkgCache::Dep::Or;
  524. if (I == Stop || *I == ',' || *I == '|')
  525. {
  526. if (I != Stop)
  527. for (I++; I != Stop && isspace(*I) != 0; I++);
  528. return I;
  529. }
  530. return 0;
  531. }
  532. /*}}}*/
  533. // ListParser::ParseDepends - Parse a dependency list /*{{{*/
  534. // ---------------------------------------------------------------------
  535. /* This is the higher level depends parser. It takes a tag and generates
  536. a complete depends tree for the given version. */
  537. bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
  538. const char *Tag,unsigned int Type)
  539. {
  540. const char *Start;
  541. const char *Stop;
  542. if (Section.Find(Tag,Start,Stop) == false)
  543. return true;
  544. string Package;
  545. string const pkgArch = Ver.Arch(true);
  546. string Version;
  547. unsigned int Op;
  548. while (1)
  549. {
  550. Start = ParseDepends(Start,Stop,Package,Version,Op);
  551. if (Start == 0)
  552. return _error->Error("Problem parsing dependency %s",Tag);
  553. if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
  554. return false;
  555. if (Start == Stop)
  556. break;
  557. }
  558. return true;
  559. }
  560. /*}}}*/
  561. // ListParser::ParseProvides - Parse the provides list /*{{{*/
  562. // ---------------------------------------------------------------------
  563. /* */
  564. bool debListParser::ParseProvides(pkgCache::VerIterator Ver)
  565. {
  566. const char *Start;
  567. const char *Stop;
  568. if (Section.Find("Provides",Start,Stop) == true)
  569. {
  570. string Package;
  571. string Version;
  572. string const Arch = Ver.Arch(true);
  573. unsigned int Op;
  574. while (1)
  575. {
  576. Start = ParseDepends(Start,Stop,Package,Version,Op);
  577. if (Start == 0)
  578. return _error->Error("Problem parsing Provides line");
  579. if (Op != pkgCache::Dep::NoOp) {
  580. _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
  581. } else {
  582. if (NewProvides(Ver, Package, Arch, Version) == false)
  583. return false;
  584. }
  585. if (Start == Stop)
  586. break;
  587. }
  588. }
  589. if (Ver->MultiArch == pkgCache::Version::Allowed)
  590. {
  591. string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
  592. NewProvides(Ver, Package, "any", Ver.VerStr());
  593. }
  594. if (Ver->MultiArch != pkgCache::Version::Foreign)
  595. return true;
  596. std::vector<string> const archs = APT::Configuration::getArchitectures();
  597. if (archs.size() <= 1)
  598. return true;
  599. string const Package = Ver.ParentPkg().Name();
  600. string const Version = Ver.VerStr();
  601. for (std::vector<string>::const_iterator a = archs.begin();
  602. a != archs.end(); ++a)
  603. {
  604. if (NewProvides(Ver, Package, *a, Version) == false)
  605. return false;
  606. }
  607. return true;
  608. }
  609. /*}}}*/
  610. // ListParser::GrabWord - Matches a word and returns /*{{{*/
  611. // ---------------------------------------------------------------------
  612. /* Looks for a word in a list of words - for ParseStatus */
  613. bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
  614. {
  615. for (unsigned int C = 0; List[C].Str != 0; C++)
  616. {
  617. if (strcasecmp(Word.c_str(),List[C].Str) == 0)
  618. {
  619. Out = List[C].Val;
  620. return true;
  621. }
  622. }
  623. return false;
  624. }
  625. /*}}}*/
  626. // ListParser::Step - Move to the next section in the file /*{{{*/
  627. // ---------------------------------------------------------------------
  628. /* This has to be carefull to only process the correct architecture */
  629. bool debListParser::Step()
  630. {
  631. iOffset = Tags.Offset();
  632. while (Tags.Step(Section) == true)
  633. {
  634. /* See if this is the correct Architecture, if it isn't then we
  635. drop the whole section. A missing arch tag only happens (in theory)
  636. inside the Status file, so that is a positive return */
  637. string const Architecture = Section.FindS("Architecture");
  638. if (Architecture.empty() == true)
  639. return true;
  640. if (Arch.empty() == true)
  641. {
  642. if (APT::Configuration::checkArchitecture(Architecture) == true)
  643. return true;
  644. }
  645. else
  646. {
  647. if (Architecture == Arch)
  648. return true;
  649. if (Architecture == "all")
  650. return true;
  651. }
  652. iOffset = Tags.Offset();
  653. }
  654. return false;
  655. }
  656. /*}}}*/
  657. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  658. // ---------------------------------------------------------------------
  659. /* */
  660. bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI,
  661. FileFd &File, string component)
  662. {
  663. pkgTagFile Tags(&File, File.Size() + 256); // XXX
  664. pkgTagSection Section;
  665. if (Tags.Step(Section) == false)
  666. return false;
  667. // FIXME: Do we need it now for multi-arch?
  668. // mvo: I don't think we need to fill that in (it's unused since apt-0.6)
  669. // FileI->Architecture = WriteUniqString(Arch);
  670. // apt-secure does no longer download individual (per-section) Release
  671. // file. to provide Component pinning we use the section name now
  672. FileI->Component = WriteUniqString(component);
  673. const char *Start;
  674. const char *Stop;
  675. if (Section.Find("Suite",Start,Stop) == true)
  676. FileI->Archive = WriteUniqString(Start,Stop - Start);
  677. if (Section.Find("Component",Start,Stop) == true)
  678. FileI->Component = WriteUniqString(Start,Stop - Start);
  679. if (Section.Find("Version",Start,Stop) == true)
  680. FileI->Version = WriteUniqString(Start,Stop - Start);
  681. if (Section.Find("Origin",Start,Stop) == true)
  682. FileI->Origin = WriteUniqString(Start,Stop - Start);
  683. if (Section.Find("Codename",Start,Stop) == true)
  684. FileI->Codename = WriteUniqString(Start,Stop - Start);
  685. if (Section.Find("Label",Start,Stop) == true)
  686. FileI->Label = WriteUniqString(Start,Stop - Start);
  687. if (Section.Find("Architecture",Start,Stop) == true)
  688. FileI->Architecture = WriteUniqString(Start,Stop - Start);
  689. if (Section.FindFlag("NotAutomatic",FileI->Flags,
  690. pkgCache::Flag::NotAutomatic) == false)
  691. _error->Warning("Bad NotAutomatic flag");
  692. return !_error->PendingError();
  693. }
  694. /*}}}*/
  695. // ListParser::GetPrio - Convert the priority from a string /*{{{*/
  696. // ---------------------------------------------------------------------
  697. /* */
  698. unsigned char debListParser::GetPrio(string Str)
  699. {
  700. unsigned char Out;
  701. if (GrabWord(Str,PrioList,Out) == false)
  702. Out = pkgCache::State::Extra;
  703. return Out;
  704. }
  705. /*}}}*/