]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: indexrecords.cc,v 1.1.2.4 2003/12/30 02:11:43 mdz Exp $
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>
13 string
indexRecords::GetDist() const
18 bool indexRecords::CheckDist(const string MaybeDist
) const
20 return (this->Dist
== MaybeDist
21 || this->Suite
== MaybeDist
);
24 string
indexRecords::GetExpectedDist() const
26 return this->ExpectedDist
;
29 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
31 return Entries
[MetaKey
];
34 bool indexRecords::Load(const string Filename
)
36 FileFd
Fd(Filename
, FileFd::ReadOnly
);
37 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
38 if (_error
->PendingError() == true)
40 ErrorText
= _(("Unable to parse Release file " + Filename
).c_str());
44 pkgTagSection Section
;
45 if (TagFile
.Step(Section
) == false)
47 ErrorText
= _(("No sections in Release file " + Filename
).c_str());
51 const char *Start
, *End
;
52 Section
.Get (Start
, End
, 0);
53 Suite
= Section
.FindS("Suite");
54 Dist
= Section
.FindS("Codename");
57 // ErrorText = _(("No Codename entry in Release file " + Filename).c_str());
60 if (!Section
.Find("MD5Sum", Start
, End
))
62 ErrorText
= _(("No MD5Sum entry in Release file " + Filename
).c_str());
70 if (!parseSumData(Start
, End
, Name
, MD5Hash
, Size
))
72 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
73 Sum
->MetaKeyFilename
= Name
;
74 Sum
->MD5Hash
= MD5Hash
;
79 string Strdate
= Section
.FindS("Date"); // FIXME: verify this somehow?
83 vector
<string
> indexRecords::MetaKeys()
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
);
94 bool indexRecords::parseSumData(const char *&Start
, const char *End
,
95 string
&Name
, string
&Hash
, size_t &Size
)
100 /* Skip over the first blank */
101 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
107 /* Move EntryEnd to the end of the first entry (the hash) */
108 const char *EntryEnd
= Start
;
109 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
115 Hash
.append(Start
, EntryEnd
-Start
);
117 /* Skip over intermediate blanks */
119 while (*Start
== '\t' || *Start
== ' ')
125 /* Find the end of the second entry (the size) */
126 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
132 Size
= strtol (Start
, NULL
, 10);
134 /* Skip over intermediate blanks */
136 while (*Start
== '\t' || *Start
== ' ')
142 /* Find the end of the third entry (the filename) */
143 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
147 Name
.append(Start
, EntryEnd
-Start
);
148 Start
= EntryEnd
; //prepare for the next round
152 indexRecords::indexRecords()
156 indexRecords::indexRecords(const string ExpectedDist
) :
157 ExpectedDist(ExpectedDist
)