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