]>
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 /*{{{*/
7 #pragma implementation "apt-pkg/indexrecords.h"
9 #include <apt-pkg/indexrecords.h>
10 #include <apt-pkg/tagfile.h>
11 #include <apt-pkg/error.h>
12 #include <apt-pkg/strutl.h>
16 string
indexRecords::GetDist() const
21 bool indexRecords::CheckDist(const string MaybeDist
) const
23 return (this->Dist
== MaybeDist
24 || this->Suite
== MaybeDist
);
27 string
indexRecords::GetExpectedDist() const
29 return this->ExpectedDist
;
32 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
34 return Entries
[MetaKey
];
37 bool indexRecords::Load(const string Filename
)
39 FileFd
Fd(Filename
, FileFd::ReadOnly
);
40 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
41 if (_error
->PendingError() == true)
43 ErrorText
= _(("Unable to parse Release file " + Filename
).c_str());
47 pkgTagSection Section
;
48 if (TagFile
.Step(Section
) == false)
50 ErrorText
= _(("No sections in Release file " + Filename
).c_str());
54 const char *Start
, *End
;
55 Section
.Get (Start
, End
, 0);
56 Suite
= Section
.FindS("Suite");
57 Dist
= Section
.FindS("Codename");
60 // ErrorText = _(("No Codename entry in Release file " + Filename).c_str());
63 if (!Section
.Find("MD5Sum", Start
, End
))
65 ErrorText
= _(("No MD5Sum entry in Release file " + Filename
).c_str());
73 if (!parseSumData(Start
, End
, Name
, MD5Hash
, Size
))
75 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
76 Sum
->MetaKeyFilename
= Name
;
77 Sum
->MD5Hash
= MD5Hash
;
82 string Strdate
= Section
.FindS("Date"); // FIXME: verify this somehow?
86 vector
<string
> indexRecords::MetaKeys()
88 std::vector
<std::string
> keys
;
89 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
90 while(I
!= Entries
.end()) {
91 keys
.push_back((*I
).first
);
97 bool indexRecords::parseSumData(const char *&Start
, const char *End
,
98 string
&Name
, string
&Hash
, size_t &Size
)
103 /* Skip over the first blank */
104 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
110 /* Move EntryEnd to the end of the first entry (the hash) */
111 const char *EntryEnd
= Start
;
112 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
118 Hash
.append(Start
, EntryEnd
-Start
);
120 /* Skip over intermediate blanks */
122 while (*Start
== '\t' || *Start
== ' ')
128 /* Find the end of the second entry (the size) */
129 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
135 Size
= strtol (Start
, NULL
, 10);
137 /* Skip over intermediate blanks */
139 while (*Start
== '\t' || *Start
== ' ')
145 /* Find the end of the third entry (the filename) */
146 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
150 Name
.append(Start
, EntryEnd
-Start
);
151 Start
= EntryEnd
; //prepare for the next round
155 indexRecords::indexRecords()
159 indexRecords::indexRecords(const string ExpectedDist
) :
160 ExpectedDist(ExpectedDist
)