indexrecords.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $
  4. /*}}}*/
  5. // Include Files /*{{{*/
  6. #ifdef __GNUG__
  7. #pragma implementation "apt-pkg/indexrecords.h"
  8. #endif
  9. #include <apt-pkg/indexrecords.h>
  10. #include <apt-pkg/tagfile.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/strutl.h>
  13. #include <apti18n.h>
  14. #include <sys/stat.h>
  15. string indexRecords::GetDist() const
  16. {
  17. return this->Dist;
  18. }
  19. bool indexRecords::CheckDist(const string MaybeDist) const
  20. {
  21. return (this->Dist == MaybeDist
  22. || this->Suite == MaybeDist);
  23. }
  24. string indexRecords::GetExpectedDist() const
  25. {
  26. return this->ExpectedDist;
  27. }
  28. const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
  29. {
  30. return Entries[MetaKey];
  31. }
  32. bool indexRecords::Load(const string Filename)
  33. {
  34. FileFd Fd(Filename, FileFd::ReadOnly);
  35. pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX
  36. if (_error->PendingError() == true)
  37. {
  38. ErrorText = _(("Unable to parse Release file " + Filename).c_str());
  39. return false;
  40. }
  41. pkgTagSection Section;
  42. if (TagFile.Step(Section) == false)
  43. {
  44. ErrorText = _(("No sections in Release file " + Filename).c_str());
  45. return false;
  46. }
  47. const char *Start, *End;
  48. Section.Get (Start, End, 0);
  49. Suite = Section.FindS("Suite");
  50. Dist = Section.FindS("Codename");
  51. // if (Dist.empty())
  52. // {
  53. // ErrorText = _(("No Codename entry in Release file " + Filename).c_str());
  54. // return false;
  55. // }
  56. if (!Section.Find("MD5Sum", Start, End))
  57. {
  58. ErrorText = _(("No MD5Sum entry in Release file " + Filename).c_str());
  59. return false;
  60. }
  61. string Name;
  62. string MD5Hash;
  63. size_t Size;
  64. while (Start < End)
  65. {
  66. if (!parseSumData(Start, End, Name, MD5Hash, Size))
  67. return false;
  68. indexRecords::checkSum *Sum = new indexRecords::checkSum;
  69. Sum->MetaKeyFilename = Name;
  70. Sum->MD5Hash = MD5Hash;
  71. Sum->Size = Size;
  72. Entries[Name] = Sum;
  73. }
  74. string Strdate = Section.FindS("Date"); // FIXME: verify this somehow?
  75. return true;
  76. }
  77. bool indexRecords::parseSumData(const char *&Start, const char *End,
  78. string &Name, string &Hash, size_t &Size)
  79. {
  80. Name = "";
  81. Hash = "";
  82. Size = 0;
  83. /* Skip over the first blank */
  84. while ((*Start == '\t' || *Start == ' ' || *Start == '\n')
  85. && Start < End)
  86. Start++;
  87. if (Start >= End)
  88. return false;
  89. /* Move EntryEnd to the end of the first entry (the hash) */
  90. const char *EntryEnd = Start;
  91. while ((*EntryEnd != '\t' && *EntryEnd != ' ')
  92. && EntryEnd < End)
  93. EntryEnd++;
  94. if (EntryEnd == End)
  95. return false;
  96. Hash.append(Start, EntryEnd-Start);
  97. /* Skip over intermediate blanks */
  98. Start = EntryEnd;
  99. while (*Start == '\t' || *Start == ' ')
  100. Start++;
  101. if (Start >= End)
  102. return false;
  103. EntryEnd = Start;
  104. /* Find the end of the second entry (the size) */
  105. while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
  106. && EntryEnd < End)
  107. EntryEnd++;
  108. if (EntryEnd == End)
  109. return false;
  110. Size = strtol (Start, NULL, 10);
  111. /* Skip over intermediate blanks */
  112. Start = EntryEnd;
  113. while (*Start == '\t' || *Start == ' ')
  114. Start++;
  115. if (Start >= End)
  116. return false;
  117. EntryEnd = Start;
  118. /* Find the end of the third entry (the filename) */
  119. while ((*EntryEnd != '\t' && *EntryEnd != ' ' && *EntryEnd != '\n')
  120. && EntryEnd < End)
  121. EntryEnd++;
  122. Name.append(Start, EntryEnd-Start);
  123. Start = EntryEnd; //prepare for the next round
  124. return true;
  125. }
  126. indexRecords::indexRecords()
  127. {
  128. }
  129. indexRecords::indexRecords(const string ExpectedDist) :
  130. ExpectedDist(ExpectedDist)
  131. {
  132. }