]>
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>
10 #include <apt-pkg/configuration.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 time_t indexRecords::GetValidUntil() const
34 return this->ValidUntil
;
37 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
39 return Entries
[MetaKey
];
42 bool indexRecords::Load(const string Filename
) /*{{{*/
44 FileFd
Fd(Filename
, FileFd::ReadOnly
);
45 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
46 if (_error
->PendingError() == true)
48 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
52 pkgTagSection Section
;
53 if (TagFile
.Step(Section
) == false)
55 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
59 const char *Start
, *End
;
60 Section
.Get (Start
, End
, 0);
62 Suite
= Section
.FindS("Suite");
63 Dist
= Section
.FindS("Codename");
66 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
68 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
76 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
78 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
79 Sum
->MetaKeyFilename
= Name
;
80 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
87 if(HashString::SupportedHashes()[i
] == NULL
)
89 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
93 string Label
= Section
.FindS("Label");
94 string StrDate
= Section
.FindS("Date");
95 string StrValidUntil
= Section
.FindS("Valid-Until");
97 // if we have a Valid-Until header, use it
98 if (!StrValidUntil
.empty())
100 // set ValidUntil based on the information in the Release file
101 if(!StrToTime(StrValidUntil
, ValidUntil
))
103 ErrorText
= _(("Invalid 'Valid-Until' entry in Release file " + Filename
).c_str());
107 // if we don't have a valid-until string, check if we have a default
110 int MaxAge
= _config
->FindI(string("apt::acquire::max-default-age::"+Label
).c_str(),0);
111 if(MaxAge
> 0 && !StrToTime(StrDate
, ValidUntil
))
113 ErrorText
= _(("Invalid 'Date' entry in Release file " + Filename
).c_str());
116 ValidUntil
+= 24*60*60*MaxAge
;
123 vector
<string
> indexRecords::MetaKeys() /*{{{*/
125 std::vector
<std::string
> keys
;
126 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
127 while(I
!= Entries
.end()) {
128 keys
.push_back((*I
).first
);
134 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
135 string
&Name
, string
&Hash
, size_t &Size
)
140 /* Skip over the first blank */
141 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
147 /* Move EntryEnd to the end of the first entry (the hash) */
148 const char *EntryEnd
= Start
;
149 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
155 Hash
.append(Start
, EntryEnd
-Start
);
157 /* Skip over intermediate blanks */
159 while (*Start
== '\t' || *Start
== ' ')
165 /* Find the end of the second entry (the size) */
166 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
172 Size
= strtol (Start
, NULL
, 10);
174 /* Skip over intermediate blanks */
176 while (*Start
== '\t' || *Start
== ' ')
182 /* Find the end of the third entry (the filename) */
183 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
187 Name
.append(Start
, EntryEnd
-Start
);
188 Start
= EntryEnd
; //prepare for the next round
192 indexRecords::indexRecords()
196 indexRecords::indexRecords(const string ExpectedDist
) :
197 ExpectedDist(ExpectedDist
), ValidUntil(0)