]>
git.saurik.com Git - apt-legacy.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);
54 Suite
= Section
.FindS("Suite");
55 Dist
= Section
.FindS("Codename");
58 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
60 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
68 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
70 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
71 Sum
->MetaKeyFilename
= Name
;
72 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
79 if(HashString::SupportedHashes()[i
] == NULL
)
81 ErrorText
= _(("No Hash entry in Release file " + Filename
).c_str());
85 string Strdate
= Section
.FindS("Date"); // FIXME: verify this somehow?
89 vector
<string
> indexRecords::MetaKeys()
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
);
100 bool indexRecords::parseSumData(const char *&Start
, const char *End
,
101 string
&Name
, string
&Hash
, size_t &Size
)
106 /* Skip over the first blank */
107 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
113 /* Move EntryEnd to the end of the first entry (the hash) */
114 const char *EntryEnd
= Start
;
115 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
121 Hash
.append(Start
, EntryEnd
-Start
);
123 /* Skip over intermediate blanks */
125 while (*Start
== '\t' || *Start
== ' ')
131 /* Find the end of the second entry (the size) */
132 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
138 Size
= strtol (Start
, NULL
, 10);
140 /* Skip over intermediate blanks */
142 while (*Start
== '\t' || *Start
== ' ')
148 /* Find the end of the third entry (the filename) */
149 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
153 Name
.append(Start
, EntryEnd
-Start
);
154 Start
= EntryEnd
; //prepare for the next round
158 indexRecords::indexRecords()
162 indexRecords::indexRecords(const string ExpectedDist
) :
163 ExpectedDist(ExpectedDist
)