]>
git.saurik.com Git - apt.git/blob - apt-pkg/indexrecords.cc
cdc2897bff4cfcda50b63c7ac75027d62743709a
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 in the Release file, use it as default
98 if (StrValidUntil
.empty() == false)
100 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
102 strprintf(ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
106 // get the user settings for this archive and use what expires earlier
107 int MaxAge
= _config
->FindI("APT::Acquire::Max-Default-Age", 0);
108 if (Label
.empty() == true)
109 MaxAge
= _config
->FindI(string("APT::Acquire::Max-Default-Age::" + Label
).c_str(), MaxAge
);
111 if(MaxAge
== 0) // No user settings, use the one from the Release file
115 if (RFC1123StrToTime(StrDate
.c_str(), date
) == false)
117 strprintf(ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
120 date
+= 24*60*60*MaxAge
;
122 if (ValidUntil
== 0 || ValidUntil
> date
)
128 vector
<string
> indexRecords::MetaKeys() /*{{{*/
130 std::vector
<std::string
> keys
;
131 std::map
<string
,checkSum
*>::iterator I
= Entries
.begin();
132 while(I
!= Entries
.end()) {
133 keys
.push_back((*I
).first
);
139 bool indexRecords::parseSumData(const char *&Start
, const char *End
, /*{{{*/
140 string
&Name
, string
&Hash
, size_t &Size
)
145 /* Skip over the first blank */
146 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n')
152 /* Move EntryEnd to the end of the first entry (the hash) */
153 const char *EntryEnd
= Start
;
154 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
160 Hash
.append(Start
, EntryEnd
-Start
);
162 /* Skip over intermediate blanks */
164 while (*Start
== '\t' || *Start
== ' ')
170 /* Find the end of the second entry (the size) */
171 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
177 Size
= strtol (Start
, NULL
, 10);
179 /* Skip over intermediate blanks */
181 while (*Start
== '\t' || *Start
== ' ')
187 /* Find the end of the third entry (the filename) */
188 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' && *EntryEnd
!= '\n')
192 Name
.append(Start
, EntryEnd
-Start
);
193 Start
= EntryEnd
; //prepare for the next round
197 indexRecords::indexRecords()
201 indexRecords::indexRecords(const string ExpectedDist
) :
202 ExpectedDist(ExpectedDist
), ValidUntil(0)