deblistparser.cc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
  140. return false;
  141. if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
  142. return false;
  143. if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
  144. return false;
  145. if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
  146. return false;
  147. if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false)
  148. return false;
  149. if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false)
  150. return false;
  151. if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false)
  152. return false;
  153. if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false)
  154. return false;
  155. // Obsolete.
  156. if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false)
  157. return false;
  158. if (ParseProvides(Ver) == false)
  159. return false;
  160. return true;
  161. }
  162. /*}}}*/
  163. // ListParser::Description - Return the description string /*{{{*/
  164. // ---------------------------------------------------------------------
  165. /* This is to return the string describing the package in debian
  166. form. If this returns the blank string then the entry is assumed to
  167. only describe package properties */
  168. string debListParser::Description()
  169. {
  170. string const lang = DescriptionLanguage();
  171. if (lang.empty())
  172. return Section.FindS("Description");
  173. else
  174. return Section.FindS(string("Description-").append(lang).c_str());
  175. }
  176. /*}}}*/
  177. // ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
  178. // ---------------------------------------------------------------------
  179. /* This is to return the string describing the language of
  180. description. If this returns the blank string then the entry is
  181. assumed to describe original description. */
  182. string debListParser::DescriptionLanguage()
  183. {
  184. if (Section.FindS("Description").empty() == false)
  185. return "";
  186. std::vector<string> const lang = APT::Configuration::getLanguages();
  187. for (std::vector<string>::const_iterator l = lang.begin();
  188. l != lang.end(); l++)
  189. if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
  190. return *l;
  191. return "";
  192. }
  193. /*}}}*/
  194. // ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
  195. // ---------------------------------------------------------------------
  196. /* This is to return the md5 string to allow the check if it is the right
  197. description. If no Description-md5 is found in the section it will be
  198. calculated.
  199. */
  200. MD5SumValue debListParser::Description_md5()
  201. {
  202. string value = Section.FindS("Description-md5");
  203. if (value.empty())
  204. {
  205. MD5Summation md5;
  206. md5.Add((Description() + "\n").c_str());
  207. return md5.Result();
  208. } else
  209. return MD5SumValue(value);
  210. }
  211. /*}}}*/
  212. // ListParser::UsePackage - Update a package structure /*{{{*/
  213. // ---------------------------------------------------------------------
  214. /* This is called to update the package with any new information
  215. that might be found in the section */
  216. bool debListParser::UsePackage(pkgCache::PkgIterator Pkg,
  217. pkgCache::VerIterator Ver)
  218. {
  219. if (Pkg->Section == 0)
  220. Pkg->Section = UniqFindTagWrite("Section");
  221. // Packages which are not from "our" arch doesn't get the essential flag
  222. string const static myArch = _config->Find("APT::Architecture");
  223. if (Pkg->Arch != 0 && myArch == Pkg.Arch())
  224. if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
  225. return false;
  226. if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false)
  227. return false;
  228. if (strcmp(Pkg.Name(),"apt") == 0)
  229. Pkg->Flags |= pkgCache::Flag::Important;
  230. if (ParseStatus(Pkg,Ver) == false)
  231. return false;
  232. return true;
  233. }
  234. /*}}}*/
  235. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  236. // ---------------------------------------------------------------------
  237. /* */
  238. unsigned short debListParser::VersionHash()
  239. {
  240. const char *Sections[] ={"Installed-Size",
  241. "Depends",
  242. "Pre-Depends",
  243. // "Suggests",
  244. // "Recommends",
  245. "Conflicts",
  246. "Breaks",
  247. "Replaces",0};
  248. unsigned long Result = INIT_FCS;
  249. char S[1024];
  250. for (const char **I = Sections; *I != 0; I++)
  251. {
  252. const char *Start;
  253. const char *End;
  254. if (Section.Find(*I,Start,End) == false || End - Start >= (signed)sizeof(S))
  255. continue;
  256. /* Strip out any spaces from the text, this undoes dpkgs reformatting
  257. of certain fields. dpkg also has the rather interesting notion of
  258. reformatting depends operators < -> <= */
  259. char *I = S;
  260. for (; Start != End; Start++)
  261. {
  262. if (isspace(*Start) == 0)
  263. *I++ = tolower_ascii(*Start);
  264. if (*Start == '<' && Start[1] != '<' && Start[1] != '=')
  265. *I++ = '=';
  266. if (*Start == '>' && Start[1] != '>' && Start[1] != '=')
  267. *I++ = '=';
  268. }
  269. Result = AddCRC16(Result,S,I - S);
  270. }
  271. return Result;
  272. }
  273. /*}}}*/
  274. // ListParser::ParseStatus - Parse the status field /*{{{*/
  275. // ---------------------------------------------------------------------
  276. /* Status lines are of the form,
  277. Status: want flag status
  278. want = unknown, install, hold, deinstall, purge
  279. flag = ok, reinstreq, hold, hold-reinstreq
  280. status = not-installed, unpacked, half-configured,
  281. half-installed, config-files, post-inst-failed,
  282. removal-failed, installed
  283. Some of the above are obsolete (I think?) flag = hold-* and
  284. status = post-inst-failed, removal-failed at least.
  285. */
  286. bool debListParser::ParseStatus(pkgCache::PkgIterator Pkg,
  287. pkgCache::VerIterator Ver)
  288. {
  289. const char *Start;
  290. const char *Stop;
  291. if (Section.Find("Status",Start,Stop) == false)
  292. return true;
  293. // Isolate the first word
  294. const char *I = Start;
  295. for(; I < Stop && *I != ' '; I++);
  296. if (I >= Stop || *I != ' ')
  297. return _error->Error("Malformed Status line");
  298. // Process the want field
  299. WordList WantList[] = {{"unknown",pkgCache::State::Unknown},
  300. {"install",pkgCache::State::Install},
  301. {"hold",pkgCache::State::Hold},
  302. {"deinstall",pkgCache::State::DeInstall},
  303. {"purge",pkgCache::State::Purge},
  304. {}};
  305. if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
  306. return _error->Error("Malformed 1st word in the Status line");
  307. // Isloate the next word
  308. I++;
  309. Start = I;
  310. for(; I < Stop && *I != ' '; I++);
  311. if (I >= Stop || *I != ' ')
  312. return _error->Error("Malformed status line, no 2nd word");
  313. // Process the flag field
  314. WordList FlagList[] = {{"ok",pkgCache::State::Ok},
  315. {"reinstreq",pkgCache::State::ReInstReq},
  316. {"hold",pkgCache::State::HoldInst},
  317. {"hold-reinstreq",pkgCache::State::HoldReInstReq},
  318. {}};
  319. if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
  320. return _error->Error("Malformed 2nd word in the Status line");
  321. // Isloate the last word
  322. I++;
  323. Start = I;
  324. for(; I < Stop && *I != ' '; I++);
  325. if (I != Stop)
  326. return _error->Error("Malformed Status line, no 3rd word");
  327. // Process the flag field
  328. WordList StatusList[] = {{"not-installed",pkgCache::State::NotInstalled},
  329. {"unpacked",pkgCache::State::UnPacked},
  330. {"half-configured",pkgCache::State::HalfConfigured},
  331. {"installed",pkgCache::State::Installed},
  332. {"half-installed",pkgCache::State::HalfInstalled},
  333. {"config-files",pkgCache::State::ConfigFiles},
  334. {"triggers-awaited",pkgCache::State::TriggersAwaited},
  335. {"triggers-pending",pkgCache::State::TriggersPending},
  336. {"post-inst-failed",pkgCache::State::HalfConfigured},
  337. {"removal-failed",pkgCache::State::HalfInstalled},
  338. {}};
  339. if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
  340. return _error->Error("Malformed 3rd word in the Status line");
  341. /* A Status line marks the package as indicating the current
  342. version as well. Only if it is actually installed.. Otherwise
  343. the interesting dpkg handling of the status file creates bogus
  344. entries. */
  345. if (!(Pkg->CurrentState == pkgCache::State::NotInstalled ||
  346. Pkg->CurrentState == pkgCache::State::ConfigFiles))
  347. {
  348. if (Ver.end() == true)
  349. _error->Warning("Encountered status field in a non-version description");
  350. else
  351. Pkg->CurrentVer = Ver.Index();
  352. }
  353. return true;
  354. }
  355. const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
  356. {
  357. // Determine the operator
  358. switch (*I)
  359. {
  360. case '<':
  361. I++;
  362. if (*I == '=')
  363. {
  364. I++;
  365. Op = pkgCache::Dep::LessEq;
  366. break;
  367. }
  368. if (*I == '<')
  369. {
  370. I++;
  371. Op = pkgCache::Dep::Less;
  372. break;
  373. }
  374. // < is the same as <= and << is really Cs < for some reason
  375. Op = pkgCache::Dep::LessEq;
  376. break;
  377. case '>':
  378. I++;
  379. if (*I == '=')
  380. {
  381. I++;
  382. Op = pkgCache::Dep::GreaterEq;
  383. break;
  384. }
  385. if (*I == '>')
  386. {
  387. I++;
  388. Op = pkgCache::Dep::Greater;
  389. break;
  390. }
  391. // > is the same as >= and >> is really Cs > for some reason
  392. Op = pkgCache::Dep::GreaterEq;
  393. break;
  394. case '=':
  395. Op = pkgCache::Dep::Equals;
  396. I++;
  397. break;
  398. // HACK around bad package definitions
  399. default:
  400. Op = pkgCache::Dep::Equals;
  401. break;
  402. }
  403. return I;
  404. }
  405. /*}}}*/
  406. // ListParser::ParseDepends - Parse a dependency element /*{{{*/
  407. // ---------------------------------------------------------------------
  408. /* This parses the dependency elements out of a standard string in place,
  409. bit by bit. */
  410. const char *debListParser::ParseDepends(const char *Start,const char *Stop,
  411. string &Package,string &Ver,
  412. unsigned int &Op, bool const &ParseArchFlags,
  413. bool const &StripMultiArch)
  414. {
  415. // Strip off leading space
  416. for (;Start != Stop && isspace(*Start) != 0; Start++);
  417. // Parse off the package name
  418. const char *I = Start;
  419. for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
  420. *I != ',' && *I != '|'; I++);
  421. // Malformed, no '('
  422. if (I != Stop && *I == ')')
  423. return 0;
  424. if (I == Start)
  425. return 0;
  426. // Stash the package name
  427. Package.assign(Start,I - Start);
  428. // We don't want to confuse library users which can't handle MultiArch
  429. if (StripMultiArch == true) {
  430. size_t const found = Package.rfind(':');
  431. if (found != string::npos)
  432. Package = Package.substr(0,found);
  433. }
  434. // Skip white space to the '('
  435. for (;I != Stop && isspace(*I) != 0 ; I++);
  436. // Parse a version
  437. if (I != Stop && *I == '(')
  438. {
  439. // Skip the '('
  440. for (I++; I != Stop && isspace(*I) != 0 ; I++);
  441. if (I + 3 >= Stop)
  442. return 0;
  443. I = ConvertRelation(I,Op);
  444. // Skip whitespace
  445. for (;I != Stop && isspace(*I) != 0; I++);
  446. Start = I;
  447. for (;I != Stop && *I != ')'; I++);
  448. if (I == Stop || Start == I)
  449. return 0;
  450. // Skip trailing whitespace
  451. const char *End = I;
  452. for (; End > Start && isspace(End[-1]); End--);
  453. Ver.assign(Start,End-Start);
  454. I++;
  455. }
  456. else
  457. {
  458. Ver.clear();
  459. Op = pkgCache::Dep::NoOp;
  460. }
  461. // Skip whitespace
  462. for (;I != Stop && isspace(*I) != 0; I++);
  463. if (ParseArchFlags == true)
  464. {
  465. string arch = _config->Find("APT::Architecture");
  466. // Parse an architecture
  467. if (I != Stop && *I == '[')
  468. {
  469. // malformed
  470. I++;
  471. if (I == Stop)
  472. return 0;
  473. const char *End = I;
  474. bool Found = false;
  475. bool NegArch = false;
  476. while (I != Stop)
  477. {
  478. // look for whitespace or ending ']'
  479. while (End != Stop && !isspace(*End) && *End != ']')
  480. End++;
  481. if (End == Stop)
  482. return 0;
  483. if (*I == '!')
  484. {
  485. NegArch = true;
  486. I++;
  487. }
  488. if (stringcmp(arch,I,End) == 0)
  489. Found = true;
  490. if (*End++ == ']') {
  491. I = End;
  492. break;
  493. }
  494. I = End;
  495. for (;I != Stop && isspace(*I) != 0; I++);
  496. }
  497. if (NegArch)
  498. Found = !Found;
  499. if (Found == false)
  500. Package = ""; /* not for this arch */
  501. }
  502. // Skip whitespace
  503. for (;I != Stop && isspace(*I) != 0; I++);
  504. }
  505. if (I != Stop && *I == '|')
  506. Op |= pkgCache::Dep::Or;
  507. if (I == Stop || *I == ',' || *I == '|')
  508. {
  509. if (I != Stop)
  510. for (I++; I != Stop && isspace(*I) != 0; I++);
  511. return I;
  512. }
  513. return 0;
  514. }
  515. /*}}}*/
  516. // ListParser::ParseDepends - Parse a dependency list /*{{{*/
  517. // ---------------------------------------------------------------------
  518. /* This is the higher level depends parser. It takes a tag and generates
  519. a complete depends tree for the given version. */
  520. bool debListParser::ParseDepends(pkgCache::VerIterator Ver,
  521. const char *Tag,unsigned int Type)
  522. {
  523. const char *Start;
  524. const char *Stop;
  525. if (Section.Find(Tag,Start,Stop) == false)
  526. return true;
  527. string Package;
  528. string const pkgArch = Ver.Arch();
  529. string Version;
  530. unsigned int Op;
  531. while (1)
  532. {
  533. Start = ParseDepends(Start,Stop,Package,Version,Op);
  534. if (Start == 0)
  535. return _error->Error("Problem parsing dependency %s",Tag);
  536. if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
  537. return false;
  538. if (Start == Stop)
  539. break;
  540. }
  541. return true;
  542. }
  543. /*}}}*/
  544. // ListParser::ParseProvides - Parse the provides list /*{{{*/
  545. // ---------------------------------------------------------------------
  546. /* */
  547. bool debListParser::ParseProvides(pkgCache::VerIterator Ver)
  548. {
  549. const char *Start;
  550. const char *Stop;
  551. if (Section.Find("Provides",Start,Stop) == false)
  552. return true;
  553. string Package;
  554. string Version;
  555. unsigned int Op;
  556. while (1)
  557. {
  558. Start = ParseDepends(Start,Stop,Package,Version,Op);
  559. if (Start == 0)
  560. return _error->Error("Problem parsing Provides line");
  561. if (Op != pkgCache::Dep::NoOp) {
  562. _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
  563. } else {
  564. if (NewProvides(Ver,Package,Version) == false)
  565. return false;
  566. }
  567. if (Start == Stop)
  568. break;
  569. }
  570. return true;
  571. }
  572. /*}}}*/
  573. // ListParser::GrabWord - Matches a word and returns /*{{{*/
  574. // ---------------------------------------------------------------------
  575. /* Looks for a word in a list of words - for ParseStatus */
  576. bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
  577. {
  578. for (unsigned int C = 0; List[C].Str != 0; C++)
  579. {
  580. if (strcasecmp(Word.c_str(),List[C].Str) == 0)
  581. {
  582. Out = List[C].Val;
  583. return true;
  584. }
  585. }
  586. return false;
  587. }
  588. /*}}}*/
  589. // ListParser::Step - Move to the next section in the file /*{{{*/
  590. // ---------------------------------------------------------------------
  591. /* This has to be carefull to only process the correct architecture */
  592. bool debListParser::Step()
  593. {
  594. iOffset = Tags.Offset();
  595. while (Tags.Step(Section) == true)
  596. {
  597. /* See if this is the correct Architecture, if it isn't then we
  598. drop the whole section. A missing arch tag only happens (in theory)
  599. inside the Status file, so that is a positive return */
  600. string const Architecture = Section.FindS("Architecture");
  601. if (Architecture.empty() == true)
  602. return true;
  603. if (Arch.empty() == true)
  604. {
  605. if (APT::Configuration::checkArchitecture(Architecture) == true)
  606. return true;
  607. }
  608. else
  609. {
  610. if (Architecture == Arch)
  611. return true;
  612. if (Architecture == "all")
  613. return true;
  614. }
  615. iOffset = Tags.Offset();
  616. }
  617. return false;
  618. }
  619. /*}}}*/
  620. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  621. // ---------------------------------------------------------------------
  622. /* */
  623. bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator FileI,
  624. FileFd &File, string component)
  625. {
  626. pkgTagFile Tags(&File, File.Size() + 256); // XXX
  627. pkgTagSection Section;
  628. if (Tags.Step(Section) == false)
  629. return false;
  630. // FIXME: Do we need it now for multi-arch?
  631. // mvo: I don't think we need to fill that in (it's unused since apt-0.6)
  632. // FileI->Architecture = WriteUniqString(Arch);
  633. // apt-secure does no longer download individual (per-section) Release
  634. // file. to provide Component pinning we use the section name now
  635. FileI->Component = WriteUniqString(component);
  636. const char *Start;
  637. const char *Stop;
  638. if (Section.Find("Suite",Start,Stop) == true)
  639. FileI->Archive = WriteUniqString(Start,Stop - Start);
  640. if (Section.Find("Component",Start,Stop) == true)
  641. FileI->Component = WriteUniqString(Start,Stop - Start);
  642. if (Section.Find("Version",Start,Stop) == true)
  643. FileI->Version = WriteUniqString(Start,Stop - Start);
  644. if (Section.Find("Origin",Start,Stop) == true)
  645. FileI->Origin = WriteUniqString(Start,Stop - Start);
  646. if (Section.Find("Codename",Start,Stop) == true)
  647. FileI->Codename = WriteUniqString(Start,Stop - Start);
  648. if (Section.Find("Label",Start,Stop) == true)
  649. FileI->Label = WriteUniqString(Start,Stop - Start);
  650. if (Section.Find("Architecture",Start,Stop) == true)
  651. FileI->Architecture = WriteUniqString(Start,Stop - Start);
  652. if (Section.FindFlag("NotAutomatic",FileI->Flags,
  653. pkgCache::Flag::NotAutomatic) == false)
  654. _error->Warning("Bad NotAutomatic flag");
  655. return !_error->PendingError();
  656. }
  657. /*}}}*/
  658. // ListParser::GetPrio - Convert the priority from a string /*{{{*/
  659. // ---------------------------------------------------------------------
  660. /* */
  661. unsigned char debListParser::GetPrio(string Str)
  662. {
  663. unsigned char Out;
  664. if (GrabWord(Str,PrioList,Out) == false)
  665. Out = pkgCache::State::Extra;
  666. return Out;
  667. }
  668. /*}}}*/