]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/indexrecords.cc
* apt-pkg/indexrecords.{cc,h}:
[apt.git] / apt-pkg / indexrecords.cc
... / ...
CommitLineData
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#include <apt-pkg/indexrecords.h>
7#include <apt-pkg/tagfile.h>
8#include <apt-pkg/error.h>
9#include <apt-pkg/strutl.h>
10#include <apti18n.h>
11#include <sys/stat.h>
12 /*}}}*/
13string indexRecords::GetDist() const
14{
15 return this->Dist;
16}
17
18bool indexRecords::CheckDist(const string MaybeDist) const
19{
20 return (this->Dist == MaybeDist
21 || this->Suite == MaybeDist);
22}
23
24string indexRecords::GetExpectedDist() const
25{
26 return this->ExpectedDist;
27}
28
29const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey)
30{
31 return Entries[MetaKey];
32}
33
34bool indexRecords::Exists(string const &MetaKey) const
35{
36 return Entries.count(MetaKey) == 1;
37}
38
39bool indexRecords::Load(const string Filename) /*{{{*/
40{
41 FileFd Fd(Filename, FileFd::ReadOnly);
42 pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX
43 if (_error->PendingError() == true)
44 {
45 strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
46 return false;
47 }
48
49 pkgTagSection Section;
50 if (TagFile.Step(Section) == false)
51 {
52 strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str());
53 return false;
54 }
55
56 const char *Start, *End;
57 Section.Get (Start, End, 0);
58
59 Suite = Section.FindS("Suite");
60 Dist = Section.FindS("Codename");
61
62 int i;
63 for (i=0;HashString::SupportedHashes()[i] != NULL; i++)
64 {
65 if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
66 continue;
67
68 string Name;
69 string Hash;
70 size_t Size;
71 while (Start < End)
72 {
73 if (!parseSumData(Start, End, Name, Hash, Size))
74 return false;
75 indexRecords::checkSum *Sum = new indexRecords::checkSum;
76 Sum->MetaKeyFilename = Name;
77 Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);
78 Sum->Size = Size;
79 Entries[Name] = Sum;
80 }
81 break;
82 }
83
84 if(HashString::SupportedHashes()[i] == NULL)
85 {
86 strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
87 return false;
88 }
89
90 string Strdate = Section.FindS("Date"); // FIXME: verify this somehow?
91 return true;
92}
93 /*}}}*/
94vector<string> indexRecords::MetaKeys() /*{{{*/
95{
96 std::vector<std::string> keys;
97 std::map<string,checkSum *>::iterator I = Entries.begin();
98 while(I != Entries.end()) {
99 keys.push_back((*I).first);
100 ++I;
101 }
102 return keys;
103}
104 /*}}}*/
105bool indexRecords::parseSumData(const char *&Start, const char *End, /*{{{*/
106 string &Name, string &Hash, size_t &Size)
107{
108 Name = "";
109 Hash = "";
110 Size = 0;
111 /* Skip over the first blank */
112 while ((*Start == '\t' || *Start == ' ' || *Start == '\n')
113 && Start < End)
114 Start++;
115 if (Start >= End)
116 return false;
117
118 /* Move EntryEnd to the end of the first entry (the hash) */
119 const char *EntryEnd = Start;
120 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
121 && EntryEnd < End)
122 EntryEnd++;
123 if (EntryEnd == End)
124 return false;
125
126 Hash.append(Start, EntryEnd-Start);
127
128 /* Skip over intermediate blanks */
129 Start = EntryEnd;
130 while (*Start == '\t' || *Start == ' ')
131 Start++;
132 if (Start >= End)
133 return false;
134
135 EntryEnd = Start;
136 /* Find the end of the second entry (the size) */
137 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
138 && EntryEnd < End)
139 EntryEnd++;
140 if (EntryEnd == End)
141 return false;
142
143 Size = strtol (Start, NULL, 10);
144
145 /* Skip over intermediate blanks */
146 Start = EntryEnd;
147 while (*Start == '\t' || *Start == ' ')
148 Start++;
149 if (Start >= End)
150 return false;
151
152 EntryEnd = Start;
153 /* Find the end of the third entry (the filename) */
154 while ((*EntryEnd != '\t' && *EntryEnd != ' ' && *EntryEnd != '\n')
155 && EntryEnd < End)
156 EntryEnd++;
157
158 Name.append(Start, EntryEnd-Start);
159 Start = EntryEnd; //prepare for the next round
160 return true;
161}
162 /*}}}*/
163indexRecords::indexRecords()
164{
165}
166
167indexRecords::indexRecords(const string ExpectedDist) :
168 ExpectedDist(ExpectedDist)
169{
170}