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