]> git.saurik.com Git - apt.git/blame - apt-pkg/indexrecords.cc
* apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / indexrecords.cc
CommitLineData
7db98ffc
MZ
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 /*{{{*/
7db98ffc
MZ
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>
92fcbfc1 12 /*}}}*/
7db98ffc
MZ
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
92fcbfc1 34bool indexRecords::Load(const string Filename) /*{{{*/
7db98ffc
MZ
35{
36 FileFd Fd(Filename, FileFd::ReadOnly);
37 pkgTagFile TagFile(&Fd, Fd.Size() + 256); // XXX
38 if (_error->PendingError() == true)
39 {
d4cd303e 40 strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
7db98ffc
MZ
41 return false;
42 }
43
44 pkgTagSection Section;
45 if (TagFile.Step(Section) == false)
46 {
d4cd303e 47 strprintf(ErrorText, _("No sections in Release file %s"), Filename.c_str());
7db98ffc
MZ
48 return false;
49 }
50
51 const char *Start, *End;
52 Section.Get (Start, End, 0);
495e5cb2 53
7db98ffc
MZ
54 Suite = Section.FindS("Suite");
55 Dist = Section.FindS("Codename");
495e5cb2
MV
56
57 int i;
58 for (i=0;HashString::SupportedHashes()[i] != NULL; i++)
7db98ffc 59 {
495e5cb2
MV
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;
7db98ffc 77 }
495e5cb2
MV
78
79 if(HashString::SupportedHashes()[i] == NULL)
7db98ffc 80 {
d4cd303e 81 strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
495e5cb2
MV
82 return false;
83 }
84
7db98ffc
MZ
85 string Strdate = Section.FindS("Date"); // FIXME: verify this somehow?
86 return true;
87}
92fcbfc1
DK
88 /*}}}*/
89vector<string> indexRecords::MetaKeys() /*{{{*/
a75c6a6e
MZ
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}
92fcbfc1
DK
99 /*}}}*/
100bool indexRecords::parseSumData(const char *&Start, const char *End, /*{{{*/
7db98ffc
MZ
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}
92fcbfc1 157 /*}}}*/
7db98ffc
MZ
158indexRecords::indexRecords()
159{
160}
161
162indexRecords::indexRecords(const string ExpectedDist) :
163 ExpectedDist(ExpectedDist)
164{
165}