]> git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
apt-pkg/deb/dpkgpm.{cc,h}
[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 ErrorText = _(("Unable to parse Release file " + Filename).c_str());
41 return false;
42 }
43
44 pkgTagSection Section;
45 if (TagFile.Step(Section) == false)
46 {
47 ErrorText = _(("No sections in Release file " + Filename).c_str());
48 return false;
49 }
50
51 const char *Start, *End;
52 Section.Get (Start, End, 0);
53 Suite = Section.FindS("Suite");
54 Dist = Section.FindS("Codename");
55 // if (Dist.empty())
56 // {
57 // ErrorText = _(("No Codename entry in Release file " + Filename).c_str());
58 // return false;
59 // }
60 if (!Section.Find("MD5Sum", Start, End))
61 {
62 ErrorText = _(("No MD5Sum entry in Release file " + Filename).c_str());
63 return false;
64 }
65 string Name;
66 string MD5Hash;
67 size_t Size;
68 while (Start < End)
69 {
70 if (!parseSumData(Start, End, Name, MD5Hash, Size))
71 return false;
72 indexRecords::checkSum *Sum = new indexRecords::checkSum;
73 Sum->MetaKeyFilename = Name;
74 Sum->MD5Hash = MD5Hash;
75 Sum->Size = Size;
76 Entries[Name] = Sum;
77 }
78
79 string Strdate = Section.FindS("Date"); // FIXME: verify this somehow?
80 return true;
81 }
82
83 vector<string> indexRecords::MetaKeys()
84 {
85 std::vector<std::string> keys;
86 std::map<string,checkSum *>::iterator I = Entries.begin();
87 while(I != Entries.end()) {
88 keys.push_back((*I).first);
89 ++I;
90 }
91 return keys;
92 }
93
94 bool indexRecords::parseSumData(const char *&Start, const char *End,
95 string &Name, string &Hash, size_t &Size)
96 {
97 Name = "";
98 Hash = "";
99 Size = 0;
100 /* Skip over the first blank */
101 while ((*Start == '\t' || *Start == ' ' || *Start == '\n')
102 && Start < End)
103 Start++;
104 if (Start >= End)
105 return false;
106
107 /* Move EntryEnd to the end of the first entry (the hash) */
108 const char *EntryEnd = Start;
109 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
110 && EntryEnd < End)
111 EntryEnd++;
112 if (EntryEnd == End)
113 return false;
114
115 Hash.append(Start, EntryEnd-Start);
116
117 /* Skip over intermediate blanks */
118 Start = EntryEnd;
119 while (*Start == '\t' || *Start == ' ')
120 Start++;
121 if (Start >= End)
122 return false;
123
124 EntryEnd = Start;
125 /* Find the end of the second entry (the size) */
126 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
127 && EntryEnd < End)
128 EntryEnd++;
129 if (EntryEnd == End)
130 return false;
131
132 Size = strtol (Start, NULL, 10);
133
134 /* Skip over intermediate blanks */
135 Start = EntryEnd;
136 while (*Start == '\t' || *Start == ' ')
137 Start++;
138 if (Start >= End)
139 return false;
140
141 EntryEnd = Start;
142 /* Find the end of the third entry (the filename) */
143 while ((*EntryEnd != '\t' && *EntryEnd != ' ' && *EntryEnd != '\n')
144 && EntryEnd < End)
145 EntryEnd++;
146
147 Name.append(Start, EntryEnd-Start);
148 Start = EntryEnd; //prepare for the next round
149 return true;
150 }
151
152 indexRecords::indexRecords()
153 {
154 }
155
156 indexRecords::indexRecords(const string ExpectedDist) :
157 ExpectedDist(ExpectedDist)
158 {
159 }