]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
448a76c27eea7dd1945bd28a490aeac9d586f1a8
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 /*{{{*/
8 #include <apt-pkg/indexrecords.h>
9 #include <apt-pkg/tagfile.h>
10 #include <apt-pkg/error.h>
11 #include <apt-pkg/strutl.h>
12 #include <apt-pkg/configuration.h>
18 string
indexRecords::GetDist() const
23 bool indexRecords::CheckDist(const string MaybeDist
) const
25 return (this->Dist
== MaybeDist
26 || this->Suite
== MaybeDist
);
29 string
indexRecords::GetExpectedDist() const
31 return this->ExpectedDist
;
34 time_t indexRecords::GetValidUntil() const
36 return this->ValidUntil
;
39 const indexRecords::checkSum
*indexRecords::Lookup(const string MetaKey
)
41 return Entries
[MetaKey
];
44 bool indexRecords::Exists(string
const &MetaKey
) const
46 return Entries
.count(MetaKey
) == 1;
49 bool indexRecords::Load(const string Filename
) /*{{{*/
51 FileFd
Fd(Filename
, FileFd::ReadOnly
);
52 pkgTagFile
TagFile(&Fd
, Fd
.Size() + 256); // XXX
53 if (_error
->PendingError() == true)
55 strprintf(ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
59 pkgTagSection Section
;
60 const char *Start
, *End
;
61 // Skip over sections beginning with ----- as this is an idicator for clearsigns
63 if (TagFile
.Step(Section
) == false)
65 strprintf(ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
69 Section
.Get (Start
, End
, 0);
70 } while (End
- Start
> 5 && strncmp(Start
, "-----", 5) == 0);
72 Suite
= Section
.FindS("Suite");
73 Dist
= Section
.FindS("Codename");
76 for (i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
78 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
83 unsigned long long Size
;
86 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
88 indexRecords::checkSum
*Sum
= new indexRecords::checkSum
;
89 Sum
->MetaKeyFilename
= Name
;
90 Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);
97 if(HashString::SupportedHashes()[i
] == NULL
)
99 strprintf(ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
103 string Label
= Section
.FindS("Label");
104 string StrDate
= Section
.FindS("Date");
105 string StrValidUntil
= Section
.FindS("Valid-Until");
107 // if we have a Valid-Until header in the Release file, use it as default
108 if (StrValidUntil
.empty() == false)
110 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
112 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
116 // get the user settings for this archive and use what expires earlier
117 int MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
118 if (Label
.empty() == false)
119 MaxAge
= _config
->FindI(string("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
120 int MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
121 if (Label
.empty() == false)
122 MinAge
= _config
->FindI(string("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
125 (MinAge
== 0 || ValidUntil
== 0)) // No user settings, use the one from the Release file
129 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
131 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
135 if (MinAge
!= 0 && ValidUntil
!= 0) {
136 time_t const min_date
= date
+ MinAge
;
137 if (ValidUntil
< min_date
)
138 ValidUntil
= min_date
;
141 time_t const max_date
= date
+ MaxAge
;
142 if (ValidUntil
== 0 || ValidUntil
> max_date
)
143 ValidUntil
= max_date
;
149 vector
<string
> indexRecords::MetaKeys() /*{{{*/
151 std::vector
<std::string
> keys
;
152 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
153 while(I
!= Entries
.end()) {
154 keys
.push_back((*I
).first
);
160 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
161 string
&Name
, string
&Hash
, unsigned long long &Size
)
166 /* Skip over the first blank */
167 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
173 /* Move EntryEnd to the end of the first entry (the hash) */
174 const char *EntryEnd
= Start
;
175 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
181 Hash
.append(Start
, EntryEnd
-Start
);
183 /* Skip over intermediate blanks */
185 while (*Start
== '\t' || *Start
== ' ')
191 /* Find the end of the second entry (the size) */
192 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
198 Size
= strtoull (Start
, NULL
, 10);
200 /* Skip over intermediate blanks */
202 while (*Start
== '\t' || *Start
== ' ')
208 /* Find the end of the third entry (the filename) */
209 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
213 Name
.append(Start
, EntryEnd
-Start
);
214 Start
= EntryEnd
; //prepare for the next round
218 indexRecords::indexRecords()
222 indexRecords::indexRecords(const string ExpectedDist
) :
223 ExpectedDist(ExpectedDist
), ValidUntil(0)