]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
34b53501 | 3 | // $Id: sourcelist.cc,v 1.3 2002/08/15 20:51:37 niemeyer Exp $ |
6c139d6e AL |
4 | /* ###################################################################### |
5 | ||
6 | List of Sources | |
7 | ||
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | // Include Files /*{{{*/ | |
ea542140 DK |
11 | #include<config.h> |
12 | ||
094a497d AL |
13 | #include <apt-pkg/sourcelist.h> |
14 | #include <apt-pkg/error.h> | |
15 | #include <apt-pkg/fileutl.h> | |
cdcc6d34 | 16 | #include <apt-pkg/strutl.h> |
7db98ffc | 17 | #include <apt-pkg/configuration.h> |
472ff00e DK |
18 | #include <apt-pkg/metaindex.h> |
19 | #include <apt-pkg/indexfile.h> | |
a537ce19 | 20 | #include <apt-pkg/tagfile.h> |
453b82a3 DK |
21 | #include <apt-pkg/pkgcache.h> |
22 | #include <apt-pkg/cacheiterators.h> | |
6c139d6e | 23 | |
453b82a3 DK |
24 | #include <ctype.h> |
25 | #include <stddef.h> | |
26 | #include <time.h> | |
27 | #include <cstring> | |
28 | #include <map> | |
29 | #include <string> | |
30 | #include <vector> | |
90f057fd | 31 | #include <fstream> |
41e6bd08 | 32 | #include <algorithm> |
ea542140 DK |
33 | |
34 | #include <apti18n.h> | |
b2e465d6 AL |
35 | /*}}}*/ |
36 | ||
4d6f8bdf AL |
37 | using namespace std; |
38 | ||
39 | // Global list of Items supported | |
463c8d80 | 40 | static pkgSourceList::Type *ItmList[10]; |
b2e465d6 AL |
41 | pkgSourceList::Type **pkgSourceList::Type::GlobalList = ItmList; |
42 | unsigned long pkgSourceList::Type::GlobalListLen = 0; | |
43 | ||
44 | // Type::Type - Constructor /*{{{*/ | |
45 | // --------------------------------------------------------------------- | |
46 | /* Link this to the global list of items*/ | |
463c8d80 | 47 | pkgSourceList::Type::Type(char const * const pName, char const * const pLabel) : Name(pName), Label(pLabel) |
b2e465d6 AL |
48 | { |
49 | ItmList[GlobalListLen] = this; | |
463c8d80 | 50 | ++GlobalListLen; |
b2e465d6 | 51 | } |
463c8d80 | 52 | pkgSourceList::Type::~Type() {} |
b2e465d6 AL |
53 | /*}}}*/ |
54 | // Type::GetType - Get a specific meta for a given type /*{{{*/ | |
55 | // --------------------------------------------------------------------- | |
56 | /* */ | |
57 | pkgSourceList::Type *pkgSourceList::Type::GetType(const char *Type) | |
58 | { | |
463c8d80 | 59 | for (unsigned I = 0; I != GlobalListLen; ++I) |
b2e465d6 AL |
60 | if (strcmp(GlobalList[I]->Name,Type) == 0) |
61 | return GlobalList[I]; | |
62 | return 0; | |
63 | } | |
64 | /*}}}*/ | |
65 | // Type::FixupURI - Normalize the URI and check it.. /*{{{*/ | |
66 | // --------------------------------------------------------------------- | |
67 | /* */ | |
68 | bool pkgSourceList::Type::FixupURI(string &URI) const | |
69 | { | |
70 | if (URI.empty() == true) | |
71 | return false; | |
72 | ||
73 | if (URI.find(':') == string::npos) | |
74 | return false; | |
75 | ||
76 | URI = SubstVar(URI,"$(ARCH)",_config->Find("APT::Architecture")); | |
77 | ||
a7c835af | 78 | // Make sure that the URI is / postfixed |
b2e465d6 AL |
79 | if (URI[URI.size() - 1] != '/') |
80 | URI += '/'; | |
81 | ||
82 | return true; | |
83 | } | |
84 | /*}}}*/ | |
81460e32 | 85 | bool pkgSourceList::Type::ParseStanza(vector<metaIndex *> &List, /*{{{*/ |
7037aab5 | 86 | pkgTagSection &Tags, |
81460e32 | 87 | unsigned int const i, |
7037aab5 MV |
88 | FileFd &Fd) |
89 | { | |
90 | map<string, string> Options; | |
91 | ||
7dd62ea9 | 92 | string Enabled = Tags.FindS("Enabled"); |
81460e32 | 93 | if (Enabled.empty() == false && StringToBool(Enabled) == false) |
7dd62ea9 | 94 | return true; |
463c8d80 | 95 | |
b0d40854 | 96 | std::map<char const * const, std::pair<char const * const, bool> > mapping; |
463c8d80 | 97 | #define APT_PLUSMINUS(X, Y) \ |
b0d40854 DK |
98 | mapping.insert(std::make_pair(X, std::make_pair(Y, true))); \ |
99 | mapping.insert(std::make_pair(X "Add", std::make_pair(Y "+", true))); \ | |
100 | mapping.insert(std::make_pair(X "Remove", std::make_pair(Y "-", true))) | |
463c8d80 DK |
101 | APT_PLUSMINUS("Architectures", "arch"); |
102 | APT_PLUSMINUS("Languages", "lang"); | |
103 | APT_PLUSMINUS("Targets", "target"); | |
104 | #undef APT_PLUSMINUS | |
b0d40854 DK |
105 | mapping.insert(std::make_pair("Trusted", std::make_pair("trusted", false))); |
106 | mapping.insert(std::make_pair("Check-Valid-Until", std::make_pair("check-valid-until", false))); | |
107 | mapping.insert(std::make_pair("Valid-Until-Min", std::make_pair("valid-until-min", false))); | |
108 | mapping.insert(std::make_pair("Valid-Until-Max", std::make_pair("valid-until-max", false))); | |
109 | mapping.insert(std::make_pair("Signed-By", std::make_pair("signed-by", false))); | |
5ad0096a | 110 | |
b0d40854 | 111 | for (std::map<char const * const, std::pair<char const * const, bool> >::const_iterator m = mapping.begin(); m != mapping.end(); ++m) |
463c8d80 | 112 | if (Tags.Exists(m->first)) |
41e6bd08 | 113 | { |
b0d40854 DK |
114 | std::string option = Tags.FindS(m->first); |
115 | // for deb822 the " " is the delimiter, but the backend expects "," | |
116 | if (m->second.second == true) | |
117 | std::replace(option.begin(), option.end(), ' ', ','); | |
118 | Options[m->second.first] = option; | |
41e6bd08 | 119 | } |
463c8d80 | 120 | |
d73743dd | 121 | // now create one item per suite/section |
6c069a22 | 122 | string Suite = Tags.FindS("Suites"); |
d73743dd | 123 | Suite = SubstVar(Suite,"$(ARCH)",_config->Find("APT::Architecture")); |
81460e32 DK |
124 | string const Component = Tags.FindS("Components"); |
125 | string const URIS = Tags.FindS("URIs"); | |
126 | ||
127 | std::vector<std::string> const list_uris = VectorizeString(URIS, ' '); | |
128 | std::vector<std::string> const list_suite = VectorizeString(Suite, ' '); | |
129 | std::vector<std::string> const list_comp = VectorizeString(Component, ' '); | |
130 | ||
131 | if (list_uris.empty()) | |
132 | // TRANSLATOR: %u is a line number, the first %s is a filename of a file with the extension "second %s" and the third %s is a unique identifier for bugreports | |
133 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "URI"); | |
d73743dd | 134 | |
75c10df1 | 135 | for (std::vector<std::string>::const_iterator U = list_uris.begin(); |
804de19f | 136 | U != list_uris.end(); ++U) |
d73743dd | 137 | { |
81460e32 DK |
138 | std::string URI = *U; |
139 | if (U->empty() || FixupURI(URI) == false) | |
140 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "URI parse"); | |
141 | ||
142 | if (list_suite.empty()) | |
143 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "Suite"); | |
75c10df1 | 144 | |
81460e32 DK |
145 | for (std::vector<std::string>::const_iterator S = list_suite.begin(); |
146 | S != list_suite.end(); ++S) | |
75c10df1 | 147 | { |
81460e32 DK |
148 | if (S->empty() == false && (*S)[S->size() - 1] == '/') |
149 | { | |
150 | if (list_comp.empty() == false) | |
151 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "absolute Suite Component"); | |
152 | if (CreateItem(List, URI, *S, "", Options) == false) | |
153 | return false; | |
154 | } | |
155 | else | |
156 | { | |
157 | if (list_comp.empty()) | |
158 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "Component"); | |
159 | ||
160 | for (std::vector<std::string>::const_iterator C = list_comp.begin(); | |
161 | C != list_comp.end(); ++C) | |
162 | { | |
163 | if (CreateItem(List, URI, *S, *C, Options) == false) | |
164 | { | |
165 | return false; | |
166 | } | |
167 | } | |
168 | } | |
75c10df1 | 169 | } |
d73743dd | 170 | } |
7037aab5 MV |
171 | return true; |
172 | } | |
81460e32 | 173 | /*}}}*/ |
b2e465d6 AL |
174 | // Type::ParseLine - Parse a single line /*{{{*/ |
175 | // --------------------------------------------------------------------- | |
176 | /* This is a generic one that is the 'usual' format for sources.list | |
177 | Weird types may override this. */ | |
7db98ffc | 178 | bool pkgSourceList::Type::ParseLine(vector<metaIndex *> &List, |
b2e465d6 | 179 | const char *Buffer, |
81460e32 | 180 | unsigned int const CurLine, |
5dd4c8b8 | 181 | string const &File) const |
b2e465d6 | 182 | { |
5dd4c8b8 DK |
183 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces |
184 | ||
185 | // Parse option field if it exists | |
186 | // e.g.: [ option1=value1 option2=value2 ] | |
187 | map<string, string> Options; | |
188 | if (Buffer != 0 && Buffer[0] == '[') | |
189 | { | |
190 | ++Buffer; // ignore the [ | |
191 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces | |
192 | while (*Buffer != ']') | |
193 | { | |
194 | // get one option, e.g. option1=value1 | |
195 | string option; | |
196 | if (ParseQuoteWord(Buffer,option) == false) | |
81460e32 | 197 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] unparseable"); |
5dd4c8b8 DK |
198 | |
199 | if (option.length() < 3) | |
81460e32 | 200 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] too short"); |
5dd4c8b8 | 201 | |
6838dd87 DK |
202 | // accept options even if the last has no space before the ]-end marker |
203 | if (option.at(option.length()-1) == ']') | |
204 | { | |
205 | for (; *Buffer != ']'; --Buffer); | |
206 | option.resize(option.length()-1); | |
207 | } | |
208 | ||
5dd4c8b8 DK |
209 | size_t const needle = option.find('='); |
210 | if (needle == string::npos) | |
81460e32 | 211 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] not assignment"); |
5dd4c8b8 DK |
212 | |
213 | string const key = string(option, 0, needle); | |
214 | string const value = string(option, needle + 1, option.length()); | |
215 | ||
216 | if (key.empty() == true) | |
81460e32 | 217 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] no key"); |
5dd4c8b8 DK |
218 | |
219 | if (value.empty() == true) | |
81460e32 | 220 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] no value"); |
5dd4c8b8 DK |
221 | |
222 | Options[key] = value; | |
223 | } | |
224 | ++Buffer; // ignore the ] | |
225 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces | |
226 | } | |
227 | ||
b2e465d6 AL |
228 | string URI; |
229 | string Dist; | |
5dd4c8b8 DK |
230 | string Section; |
231 | ||
b2e465d6 | 232 | if (ParseQuoteWord(Buffer,URI) == false) |
81460e32 | 233 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "URI"); |
b2e465d6 | 234 | if (ParseQuoteWord(Buffer,Dist) == false) |
81460e32 DK |
235 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "Suite"); |
236 | ||
b2e465d6 | 237 | if (FixupURI(URI) == false) |
81460e32 | 238 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "URI parse"); |
463c8d80 | 239 | |
b2e465d6 AL |
240 | // Check for an absolute dists specification. |
241 | if (Dist.empty() == false && Dist[Dist.size() - 1] == '/') | |
242 | { | |
243 | if (ParseQuoteWord(Buffer,Section) == true) | |
81460e32 | 244 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "absolute Suite Component"); |
b2e465d6 | 245 | Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); |
5dd4c8b8 | 246 | return CreateItem(List, URI, Dist, Section, Options); |
b2e465d6 | 247 | } |
81460e32 | 248 | |
b2e465d6 AL |
249 | // Grab the rest of the dists |
250 | if (ParseQuoteWord(Buffer,Section) == false) | |
81460e32 DK |
251 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "Component"); |
252 | ||
b2e465d6 AL |
253 | do |
254 | { | |
5dd4c8b8 | 255 | if (CreateItem(List, URI, Dist, Section, Options) == false) |
b2e465d6 AL |
256 | return false; |
257 | } | |
258 | while (ParseQuoteWord(Buffer,Section) == true); | |
81460e32 | 259 | |
b2e465d6 AL |
260 | return true; |
261 | } | |
6c139d6e | 262 | /*}}}*/ |
6c139d6e AL |
263 | // SourceList::pkgSourceList - Constructors /*{{{*/ |
264 | // --------------------------------------------------------------------- | |
265 | /* */ | |
6c55f07a | 266 | pkgSourceList::pkgSourceList() : d(NULL) |
6c139d6e | 267 | { |
6c139d6e AL |
268 | } |
269 | /*}}}*/ | |
1c193e02 AL |
270 | // SourceList::~pkgSourceList - Destructor /*{{{*/ |
271 | // --------------------------------------------------------------------- | |
272 | /* */ | |
273 | pkgSourceList::~pkgSourceList() | |
274 | { | |
f7f0d6c7 | 275 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
1c193e02 | 276 | delete *I; |
5465192b | 277 | SrcList.clear(); |
c9d71534 JAK |
278 | for (auto F = VolatileFiles.begin(); F != VolatileFiles.end(); ++F) |
279 | delete (*F); | |
5465192b | 280 | VolatileFiles.clear(); |
1c193e02 AL |
281 | } |
282 | /*}}}*/ | |
6c139d6e AL |
283 | // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ |
284 | // --------------------------------------------------------------------- | |
285 | /* */ | |
286 | bool pkgSourceList::ReadMainList() | |
287 | { | |
34b53501 MV |
288 | // CNC:2003-03-03 - Multiple sources list support. |
289 | bool Res = true; | |
290 | #if 0 | |
291 | Res = ReadVendors(); | |
292 | if (Res == false) | |
293 | return false; | |
294 | #endif | |
295 | ||
296 | Reset(); | |
297 | // CNC:2003-11-28 - Entries in sources.list have priority over | |
298 | // entries in sources.list.d. | |
299 | string Main = _config->FindFile("Dir::Etc::sourcelist"); | |
67793cf3 JAK |
300 | string Parts = _config->FindDir("Dir::Etc::sourceparts"); |
301 | ||
36f1098a | 302 | if (RealFileExists(Main) == true) |
6009e60d | 303 | Res &= ReadAppend(Main); |
448eaf8b | 304 | else if (DirectoryExists(Parts) == false) |
67793cf3 | 305 | // Only warn if there are no sources.list.d. |
448eaf8b | 306 | _error->WarningE("DirectoryExists", _("Unable to read %s"), Parts.c_str()); |
34b53501 | 307 | |
448eaf8b | 308 | if (DirectoryExists(Parts) == true) |
34b53501 | 309 | Res &= ReadSourceDir(Parts); |
36f1098a | 310 | else if (RealFileExists(Main) == false) |
67793cf3 | 311 | // Only warn if there is no sources.list file. |
36f1098a | 312 | _error->WarningE("RealFileExists", _("Unable to read %s"), Main.c_str()); |
6009e60d | 313 | |
34b53501 | 314 | return Res; |
6c139d6e AL |
315 | } |
316 | /*}}}*/ | |
34b53501 MV |
317 | // SourceList::Reset - Clear the sourcelist contents /*{{{*/ |
318 | // --------------------------------------------------------------------- | |
319 | /* */ | |
320 | void pkgSourceList::Reset() | |
321 | { | |
f7f0d6c7 | 322 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
34b53501 MV |
323 | delete *I; |
324 | SrcList.erase(SrcList.begin(),SrcList.end()); | |
325 | } | |
326 | /*}}}*/ | |
6c139d6e AL |
327 | // SourceList::Read - Parse the sourcelist file /*{{{*/ |
328 | // --------------------------------------------------------------------- | |
329 | /* */ | |
81460e32 | 330 | bool pkgSourceList::Read(string const &File) |
34b53501 MV |
331 | { |
332 | Reset(); | |
333 | return ReadAppend(File); | |
334 | } | |
335 | /*}}}*/ | |
6f447813 MV |
336 | // SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ |
337 | // --------------------------------------------------------------------- | |
338 | /* */ | |
81460e32 | 339 | bool pkgSourceList::ReadAppend(string const &File) |
6f447813 | 340 | { |
81460e32 DK |
341 | if (flExtension(File) == "sources") |
342 | return ParseFileDeb822(File); | |
343 | else | |
344 | return ParseFileOldStyle(File); | |
1fa78a8a | 345 | } |
5465192b | 346 | /*}}}*/ |
1fa78a8a MV |
347 | // SourceList::ReadFileOldStyle - Read Traditional style sources.list /*{{{*/ |
348 | // --------------------------------------------------------------------- | |
349 | /* */ | |
81460e32 | 350 | bool pkgSourceList::ParseFileOldStyle(std::string const &File) |
1fa78a8a | 351 | { |
6c139d6e | 352 | // Open the stream for reading |
4d6f8bdf | 353 | ifstream F(File.c_str(),ios::in /*| ios::nocreate*/); |
2b4cead3 | 354 | if (F.fail() == true) |
b2e465d6 | 355 | return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str()); |
a537ce19 | 356 | |
81460e32 DK |
357 | std::string Buffer; |
358 | for (unsigned int CurLine = 1; std::getline(F, Buffer); ++CurLine) | |
6c139d6e | 359 | { |
81460e32 DK |
360 | // remove comments |
361 | size_t curpos = 0; | |
362 | while ((curpos = Buffer.find('#', curpos)) != std::string::npos) | |
363 | { | |
364 | size_t const openbrackets = std::count(Buffer.begin(), Buffer.begin() + curpos, '['); | |
365 | size_t const closedbrackets = std::count(Buffer.begin(), Buffer.begin() + curpos, ']'); | |
366 | if (openbrackets > closedbrackets) | |
367 | { | |
368 | // a # in an option, unlikely, but oh well, it was supported so stick to it | |
369 | ++curpos; | |
370 | continue; | |
371 | } | |
372 | Buffer.erase(curpos); | |
373 | break; | |
374 | } | |
375 | // remove spaces before/after | |
376 | curpos = Buffer.find_first_not_of(" \t\r"); | |
377 | if (curpos != 0) | |
378 | Buffer.erase(0, curpos); | |
379 | curpos = Buffer.find_last_not_of(" \t\r"); | |
380 | if (curpos != std::string::npos) | |
381 | Buffer.erase(curpos + 1); | |
382 | ||
383 | if (Buffer.empty()) | |
6c139d6e | 384 | continue; |
81460e32 | 385 | |
6c139d6e | 386 | // Grok it |
81460e32 DK |
387 | std::string const LineType = Buffer.substr(0, Buffer.find(' ')); |
388 | if (LineType.empty() || LineType == Buffer) | |
b2e465d6 | 389 | return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str()); |
6c139d6e | 390 | |
b2e465d6 AL |
391 | Type *Parse = Type::GetType(LineType.c_str()); |
392 | if (Parse == 0) | |
39442e44 | 393 | return _error->Error(_("Type '%s' is not known on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str()); |
81460e32 DK |
394 | |
395 | if (Parse->ParseLine(SrcList, Buffer.c_str() + LineType.length(), CurLine, File) == false) | |
b2e465d6 | 396 | return false; |
6c139d6e AL |
397 | } |
398 | return true; | |
399 | } | |
400 | /*}}}*/ | |
1fa78a8a MV |
401 | // SourceList::ParseFileDeb822 - Parse deb822 style sources.list /*{{{*/ |
402 | // --------------------------------------------------------------------- | |
4194c9ae | 403 | /* Returns: the number of stanzas parsed*/ |
81460e32 | 404 | bool pkgSourceList::ParseFileDeb822(string const &File) |
1fa78a8a | 405 | { |
81460e32 DK |
406 | pkgUserTagSection Tags; |
407 | unsigned int i = 1; | |
fce9f472 MV |
408 | |
409 | // see if we can read the file | |
1fa78a8a | 410 | FileFd Fd(File, FileFd::ReadOnly); |
fce9f472 | 411 | pkgTagFile Sources(&Fd); |
1fa78a8a | 412 | if (_error->PendingError() == true) |
81460e32 DK |
413 | return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str()); |
414 | ||
fce9f472 | 415 | // read step by step |
1fa78a8a MV |
416 | while (Sources.Step(Tags) == true) |
417 | { | |
81460e32 DK |
418 | if(Tags.Exists("Types") == false) |
419 | return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str()); | |
42e19c82 | 420 | |
7f316a3f | 421 | string const types = Tags.FindS("Types"); |
81460e32 | 422 | std::vector<std::string> const list_types = VectorizeString(types, ' '); |
7f316a3f | 423 | for (std::vector<std::string>::const_iterator I = list_types.begin(); |
804de19f | 424 | I != list_types.end(); ++I) |
4194c9ae | 425 | { |
7f316a3f MV |
426 | Type *Parse = Type::GetType((*I).c_str()); |
427 | if (Parse == 0) | |
428 | { | |
429 | _error->Error(_("Type '%s' is not known on stanza %u in source list %s"), (*I).c_str(),i,Fd.Name().c_str()); | |
81460e32 | 430 | return false; |
7f316a3f | 431 | } |
81460e32 | 432 | |
7f316a3f | 433 | if (!Parse->ParseStanza(SrcList, Tags, i, Fd)) |
81460e32 | 434 | return false; |
1fa78a8a | 435 | |
81460e32 | 436 | ++i; |
7f316a3f | 437 | } |
1fa78a8a | 438 | } |
81460e32 | 439 | return true; |
1fa78a8a MV |
440 | } |
441 | /*}}}*/ | |
b2e465d6 | 442 | // SourceList::FindIndex - Get the index associated with a file /*{{{*/ |
6c139d6e AL |
443 | // --------------------------------------------------------------------- |
444 | /* */ | |
b2e465d6 AL |
445 | bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, |
446 | pkgIndexFile *&Found) const | |
6c139d6e | 447 | { |
f7f0d6c7 | 448 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
6c139d6e | 449 | { |
7db98ffc MZ |
450 | vector<pkgIndexFile *> *Indexes = (*I)->GetIndexFiles(); |
451 | for (vector<pkgIndexFile *>::const_iterator J = Indexes->begin(); | |
f7f0d6c7 | 452 | J != Indexes->end(); ++J) |
b2e465d6 | 453 | { |
7db98ffc MZ |
454 | if ((*J)->FindInCache(*File.Cache()) == File) |
455 | { | |
456 | Found = (*J); | |
457 | return true; | |
458 | } | |
b2e465d6 | 459 | } |
be8922fd | 460 | } |
5465192b DK |
461 | for (vector<pkgIndexFile *>::const_iterator J = VolatileFiles.begin(); |
462 | J != VolatileFiles.end(); ++J) | |
463 | { | |
464 | if ((*J)->FindInCache(*File.Cache()) == File) | |
465 | { | |
466 | Found = (*J); | |
467 | return true; | |
468 | } | |
469 | } | |
b2e465d6 | 470 | return false; |
36375005 AL |
471 | } |
472 | /*}}}*/ | |
b2e465d6 | 473 | // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/ |
6c139d6e AL |
474 | // --------------------------------------------------------------------- |
475 | /* */ | |
7db98ffc | 476 | bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const |
6c139d6e | 477 | { |
f7f0d6c7 | 478 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
7db98ffc | 479 | if ((*I)->GetIndexes(Owner,GetAll) == false) |
b2e465d6 AL |
480 | return false; |
481 | return true; | |
6c139d6e AL |
482 | } |
483 | /*}}}*/ | |
34b53501 MV |
484 | // CNC:2003-03-03 - By Anton V. Denisov <avd@altlinux.org>. |
485 | // SourceList::ReadSourceDir - Read a directory with sources files | |
486 | // Based on ReadConfigDir() /*{{{*/ | |
487 | // --------------------------------------------------------------------- | |
488 | /* */ | |
81460e32 | 489 | bool pkgSourceList::ReadSourceDir(string const &Dir) |
34b53501 | 490 | { |
81460e32 DK |
491 | std::vector<std::string> ext; |
492 | ext.push_back("list"); | |
493 | ext.push_back("sources"); | |
494 | std::vector<std::string> const List = GetListOfFilesInDir(Dir, ext, true); | |
34b53501 MV |
495 | |
496 | // Read the files | |
f7f0d6c7 | 497 | for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) |
34b53501 MV |
498 | if (ReadAppend(*I) == false) |
499 | return false; | |
500 | return true; | |
501 | ||
502 | } | |
503 | /*}}}*/ | |
2ec858bc MV |
504 | // GetLastModified() /*{{{*/ |
505 | // --------------------------------------------------------------------- | |
506 | /* */ | |
507 | time_t pkgSourceList::GetLastModifiedTime() | |
508 | { | |
5e7b0aa9 MV |
509 | vector<string> List; |
510 | ||
2ec858bc MV |
511 | string Main = _config->FindFile("Dir::Etc::sourcelist"); |
512 | string Parts = _config->FindDir("Dir::Etc::sourceparts"); | |
5e7b0aa9 MV |
513 | |
514 | // go over the parts | |
515 | if (DirectoryExists(Parts) == true) | |
516 | List = GetListOfFilesInDir(Parts, "list", true); | |
2ec858bc MV |
517 | |
518 | // calculate the time | |
519 | time_t mtime_sources = GetModificationTime(Main); | |
f7f0d6c7 | 520 | for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) |
2ec858bc MV |
521 | mtime_sources = std::max(mtime_sources, GetModificationTime(*I)); |
522 | ||
523 | return mtime_sources; | |
524 | } | |
525 | /*}}}*/ | |
5465192b DK |
526 | std::vector<pkgIndexFile*> pkgSourceList::GetVolatileFiles() const /*{{{*/ |
527 | { | |
528 | return VolatileFiles; | |
529 | } | |
530 | /*}}}*/ | |
531 | void pkgSourceList::AddVolatileFile(pkgIndexFile * const File) /*{{{*/ | |
532 | { | |
533 | if (File != NULL) | |
534 | VolatileFiles.push_back(File); | |
535 | } | |
536 | /*}}}*/ |