]>
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::Exists(string
const &MetaKey
) const
36 return Entries
.count(MetaKey
) == 1;
39 bool indexRecords::Load(const string Filename
) /*{{{*/
41 FileFd
Fd(Filename
, FileFd::ReadOnly
);
42 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
43 if (_error
->PendingError() == true)
45 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
49 pkgTagSection Section
;
50 if (TagFile
.Step(Section
) == false)
52 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
56 const char *Start
, *End
;
57 Section
.Get (Start
, End
, 0);
59 Suite
= Section
.FindS("Suite");
60 Dist
= Section
.FindS("Codename");
63 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
65 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
73 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
75 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
76 Sum
->MetaKeyFilename
= Name
;
77 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
84 if(HashString::SupportedHashes()[i
] == NULL
)
86 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
90 string Strdate
= Section
.FindS("Date"); // FIXME: verify this somehow?
94 vector
<string
> indexRecords::MetaKeys() /*{{{*/
96 std::vector
<std::string
> keys
;
97 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
98 while(I
!= Entries
.end()) {
99 keys
.push_back((*I
).first
);
105 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
106 string
&Name
, string
&Hash
, size_t &Size
)
111 /* Skip over the first blank */
112 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
118 /* Move EntryEnd to the end of the first entry (the hash) */
119 const char *EntryEnd
= Start
;
120 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
126 Hash
.append(Start
, EntryEnd
-Start
);
128 /* Skip over intermediate blanks */
130 while (*Start
== '\t' || *Start
== ' ')
136 /* Find the end of the second entry (the size) */
137 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
143 Size
= strtol (Start
, NULL
, 10);
145 /* Skip over intermediate blanks */
147 while (*Start
== '\t' || *Start
== ' ')
153 /* Find the end of the third entry (the filename) */
154 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
158 Name
.append(Start
, EntryEnd
-Start
);
159 Start
= EntryEnd
; //prepare for the next round
163 indexRecords::indexRecords()
167 indexRecords::indexRecords(const string ExpectedDist
) :
168 ExpectedDist(ExpectedDist
)