]>
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))); | |
1a3a14ac | 110 | mapping.insert(std::make_pair("PDiffs", std::make_pair("pdiffs", false))); |
5ad0096a | 111 | |
b0d40854 | 112 | for (std::map<char const * const, std::pair<char const * const, bool> >::const_iterator m = mapping.begin(); m != mapping.end(); ++m) |
463c8d80 | 113 | if (Tags.Exists(m->first)) |
41e6bd08 | 114 | { |
b0d40854 DK |
115 | std::string option = Tags.FindS(m->first); |
116 | // for deb822 the " " is the delimiter, but the backend expects "," | |
117 | if (m->second.second == true) | |
118 | std::replace(option.begin(), option.end(), ' ', ','); | |
119 | Options[m->second.first] = option; | |
41e6bd08 | 120 | } |
463c8d80 | 121 | |
d73743dd | 122 | // now create one item per suite/section |
6c069a22 | 123 | string Suite = Tags.FindS("Suites"); |
d73743dd | 124 | Suite = SubstVar(Suite,"$(ARCH)",_config->Find("APT::Architecture")); |
81460e32 DK |
125 | string const Component = Tags.FindS("Components"); |
126 | string const URIS = Tags.FindS("URIs"); | |
127 | ||
128 | std::vector<std::string> const list_uris = VectorizeString(URIS, ' '); | |
129 | std::vector<std::string> const list_suite = VectorizeString(Suite, ' '); | |
130 | std::vector<std::string> const list_comp = VectorizeString(Component, ' '); | |
131 | ||
132 | if (list_uris.empty()) | |
133 | // 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 | |
134 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "URI"); | |
d73743dd | 135 | |
75c10df1 | 136 | for (std::vector<std::string>::const_iterator U = list_uris.begin(); |
804de19f | 137 | U != list_uris.end(); ++U) |
d73743dd | 138 | { |
81460e32 DK |
139 | std::string URI = *U; |
140 | if (U->empty() || FixupURI(URI) == false) | |
141 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "URI parse"); | |
142 | ||
143 | if (list_suite.empty()) | |
144 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "Suite"); | |
75c10df1 | 145 | |
81460e32 DK |
146 | for (std::vector<std::string>::const_iterator S = list_suite.begin(); |
147 | S != list_suite.end(); ++S) | |
75c10df1 | 148 | { |
81460e32 DK |
149 | if (S->empty() == false && (*S)[S->size() - 1] == '/') |
150 | { | |
151 | if (list_comp.empty() == false) | |
152 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "absolute Suite Component"); | |
153 | if (CreateItem(List, URI, *S, "", Options) == false) | |
154 | return false; | |
155 | } | |
156 | else | |
157 | { | |
158 | if (list_comp.empty()) | |
159 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), i, "sources", Fd.Name().c_str(), "Component"); | |
160 | ||
161 | for (std::vector<std::string>::const_iterator C = list_comp.begin(); | |
162 | C != list_comp.end(); ++C) | |
163 | { | |
164 | if (CreateItem(List, URI, *S, *C, Options) == false) | |
165 | { | |
166 | return false; | |
167 | } | |
168 | } | |
169 | } | |
75c10df1 | 170 | } |
d73743dd | 171 | } |
7037aab5 MV |
172 | return true; |
173 | } | |
81460e32 | 174 | /*}}}*/ |
b2e465d6 AL |
175 | // Type::ParseLine - Parse a single line /*{{{*/ |
176 | // --------------------------------------------------------------------- | |
177 | /* This is a generic one that is the 'usual' format for sources.list | |
178 | Weird types may override this. */ | |
7db98ffc | 179 | bool pkgSourceList::Type::ParseLine(vector<metaIndex *> &List, |
b2e465d6 | 180 | const char *Buffer, |
81460e32 | 181 | unsigned int const CurLine, |
5dd4c8b8 | 182 | string const &File) const |
b2e465d6 | 183 | { |
5dd4c8b8 DK |
184 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces |
185 | ||
186 | // Parse option field if it exists | |
187 | // e.g.: [ option1=value1 option2=value2 ] | |
188 | map<string, string> Options; | |
189 | if (Buffer != 0 && Buffer[0] == '[') | |
190 | { | |
191 | ++Buffer; // ignore the [ | |
192 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces | |
193 | while (*Buffer != ']') | |
194 | { | |
195 | // get one option, e.g. option1=value1 | |
196 | string option; | |
197 | if (ParseQuoteWord(Buffer,option) == false) | |
81460e32 | 198 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] unparseable"); |
5dd4c8b8 DK |
199 | |
200 | if (option.length() < 3) | |
81460e32 | 201 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] too short"); |
5dd4c8b8 | 202 | |
6838dd87 DK |
203 | // accept options even if the last has no space before the ]-end marker |
204 | if (option.at(option.length()-1) == ']') | |
205 | { | |
206 | for (; *Buffer != ']'; --Buffer); | |
207 | option.resize(option.length()-1); | |
208 | } | |
209 | ||
5dd4c8b8 DK |
210 | size_t const needle = option.find('='); |
211 | if (needle == string::npos) | |
81460e32 | 212 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] not assignment"); |
5dd4c8b8 DK |
213 | |
214 | string const key = string(option, 0, needle); | |
215 | string const value = string(option, needle + 1, option.length()); | |
216 | ||
217 | if (key.empty() == true) | |
81460e32 | 218 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] no key"); |
5dd4c8b8 DK |
219 | |
220 | if (value.empty() == true) | |
81460e32 | 221 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "[option] no value"); |
5dd4c8b8 DK |
222 | |
223 | Options[key] = value; | |
224 | } | |
225 | ++Buffer; // ignore the ] | |
226 | for (;Buffer != 0 && isspace(*Buffer); ++Buffer); // Skip whitespaces | |
227 | } | |
228 | ||
b2e465d6 AL |
229 | string URI; |
230 | string Dist; | |
5dd4c8b8 DK |
231 | string Section; |
232 | ||
b2e465d6 | 233 | if (ParseQuoteWord(Buffer,URI) == false) |
81460e32 | 234 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "URI"); |
b2e465d6 | 235 | if (ParseQuoteWord(Buffer,Dist) == false) |
81460e32 DK |
236 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "Suite"); |
237 | ||
b2e465d6 | 238 | if (FixupURI(URI) == false) |
81460e32 | 239 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "URI parse"); |
463c8d80 | 240 | |
b2e465d6 AL |
241 | // Check for an absolute dists specification. |
242 | if (Dist.empty() == false && Dist[Dist.size() - 1] == '/') | |
243 | { | |
244 | if (ParseQuoteWord(Buffer,Section) == true) | |
81460e32 | 245 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "absolute Suite Component"); |
b2e465d6 | 246 | Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); |
5dd4c8b8 | 247 | return CreateItem(List, URI, Dist, Section, Options); |
b2e465d6 | 248 | } |
81460e32 | 249 | |
b2e465d6 AL |
250 | // Grab the rest of the dists |
251 | if (ParseQuoteWord(Buffer,Section) == false) | |
81460e32 DK |
252 | return _error->Error(_("Malformed entry %u in %s file %s (%s)"), CurLine, "list", File.c_str(), "Component"); |
253 | ||
b2e465d6 AL |
254 | do |
255 | { | |
5dd4c8b8 | 256 | if (CreateItem(List, URI, Dist, Section, Options) == false) |
b2e465d6 AL |
257 | return false; |
258 | } | |
259 | while (ParseQuoteWord(Buffer,Section) == true); | |
81460e32 | 260 | |
b2e465d6 AL |
261 | return true; |
262 | } | |
6c139d6e | 263 | /*}}}*/ |
6c139d6e AL |
264 | // SourceList::pkgSourceList - Constructors /*{{{*/ |
265 | // --------------------------------------------------------------------- | |
266 | /* */ | |
6c55f07a | 267 | pkgSourceList::pkgSourceList() : d(NULL) |
6c139d6e | 268 | { |
6c139d6e AL |
269 | } |
270 | /*}}}*/ | |
1c193e02 AL |
271 | // SourceList::~pkgSourceList - Destructor /*{{{*/ |
272 | // --------------------------------------------------------------------- | |
273 | /* */ | |
274 | pkgSourceList::~pkgSourceList() | |
275 | { | |
f7f0d6c7 | 276 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
1c193e02 | 277 | delete *I; |
5465192b | 278 | SrcList.clear(); |
c9d71534 JAK |
279 | for (auto F = VolatileFiles.begin(); F != VolatileFiles.end(); ++F) |
280 | delete (*F); | |
5465192b | 281 | VolatileFiles.clear(); |
1c193e02 AL |
282 | } |
283 | /*}}}*/ | |
6c139d6e AL |
284 | // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ |
285 | // --------------------------------------------------------------------- | |
286 | /* */ | |
287 | bool pkgSourceList::ReadMainList() | |
288 | { | |
34b53501 MV |
289 | // CNC:2003-03-03 - Multiple sources list support. |
290 | bool Res = true; | |
291 | #if 0 | |
292 | Res = ReadVendors(); | |
293 | if (Res == false) | |
294 | return false; | |
295 | #endif | |
296 | ||
297 | Reset(); | |
298 | // CNC:2003-11-28 - Entries in sources.list have priority over | |
299 | // entries in sources.list.d. | |
300 | string Main = _config->FindFile("Dir::Etc::sourcelist"); | |
67793cf3 JAK |
301 | string Parts = _config->FindDir("Dir::Etc::sourceparts"); |
302 | ||
36f1098a | 303 | if (RealFileExists(Main) == true) |
6009e60d | 304 | Res &= ReadAppend(Main); |
448eaf8b | 305 | else if (DirectoryExists(Parts) == false) |
67793cf3 | 306 | // Only warn if there are no sources.list.d. |
448eaf8b | 307 | _error->WarningE("DirectoryExists", _("Unable to read %s"), Parts.c_str()); |
34b53501 | 308 | |
448eaf8b | 309 | if (DirectoryExists(Parts) == true) |
34b53501 | 310 | Res &= ReadSourceDir(Parts); |
36f1098a | 311 | else if (RealFileExists(Main) == false) |
67793cf3 | 312 | // Only warn if there is no sources.list file. |
36f1098a | 313 | _error->WarningE("RealFileExists", _("Unable to read %s"), Main.c_str()); |
6009e60d | 314 | |
34b53501 | 315 | return Res; |
6c139d6e AL |
316 | } |
317 | /*}}}*/ | |
34b53501 MV |
318 | // SourceList::Reset - Clear the sourcelist contents /*{{{*/ |
319 | // --------------------------------------------------------------------- | |
320 | /* */ | |
321 | void pkgSourceList::Reset() | |
322 | { | |
f7f0d6c7 | 323 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
34b53501 | 324 | delete *I; |
8dd562a8 | 325 | SrcList.clear(); |
34b53501 MV |
326 | } |
327 | /*}}}*/ | |
6c139d6e AL |
328 | // SourceList::Read - Parse the sourcelist file /*{{{*/ |
329 | // --------------------------------------------------------------------- | |
330 | /* */ | |
81460e32 | 331 | bool pkgSourceList::Read(string const &File) |
34b53501 MV |
332 | { |
333 | Reset(); | |
334 | return ReadAppend(File); | |
335 | } | |
336 | /*}}}*/ | |
6f447813 MV |
337 | // SourceList::ReadAppend - Parse a sourcelist file /*{{{*/ |
338 | // --------------------------------------------------------------------- | |
339 | /* */ | |
81460e32 | 340 | bool pkgSourceList::ReadAppend(string const &File) |
6f447813 | 341 | { |
81460e32 DK |
342 | if (flExtension(File) == "sources") |
343 | return ParseFileDeb822(File); | |
344 | else | |
345 | return ParseFileOldStyle(File); | |
1fa78a8a | 346 | } |
5465192b | 347 | /*}}}*/ |
1fa78a8a MV |
348 | // SourceList::ReadFileOldStyle - Read Traditional style sources.list /*{{{*/ |
349 | // --------------------------------------------------------------------- | |
350 | /* */ | |
81460e32 | 351 | bool pkgSourceList::ParseFileOldStyle(std::string const &File) |
1fa78a8a | 352 | { |
6c139d6e | 353 | // Open the stream for reading |
4d6f8bdf | 354 | ifstream F(File.c_str(),ios::in /*| ios::nocreate*/); |
2b4cead3 | 355 | if (F.fail() == true) |
b2e465d6 | 356 | return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str()); |
a537ce19 | 357 | |
81460e32 DK |
358 | std::string Buffer; |
359 | for (unsigned int CurLine = 1; std::getline(F, Buffer); ++CurLine) | |
6c139d6e | 360 | { |
81460e32 DK |
361 | // remove comments |
362 | size_t curpos = 0; | |
363 | while ((curpos = Buffer.find('#', curpos)) != std::string::npos) | |
364 | { | |
365 | size_t const openbrackets = std::count(Buffer.begin(), Buffer.begin() + curpos, '['); | |
366 | size_t const closedbrackets = std::count(Buffer.begin(), Buffer.begin() + curpos, ']'); | |
367 | if (openbrackets > closedbrackets) | |
368 | { | |
369 | // a # in an option, unlikely, but oh well, it was supported so stick to it | |
370 | ++curpos; | |
371 | continue; | |
372 | } | |
373 | Buffer.erase(curpos); | |
374 | break; | |
375 | } | |
376 | // remove spaces before/after | |
377 | curpos = Buffer.find_first_not_of(" \t\r"); | |
378 | if (curpos != 0) | |
379 | Buffer.erase(0, curpos); | |
380 | curpos = Buffer.find_last_not_of(" \t\r"); | |
381 | if (curpos != std::string::npos) | |
382 | Buffer.erase(curpos + 1); | |
383 | ||
384 | if (Buffer.empty()) | |
6c139d6e | 385 | continue; |
81460e32 | 386 | |
6c139d6e | 387 | // Grok it |
defe3231 | 388 | std::string const LineType = Buffer.substr(0, Buffer.find_first_of(" \t\v")); |
81460e32 | 389 | if (LineType.empty() || LineType == Buffer) |
b2e465d6 | 390 | return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str()); |
6c139d6e | 391 | |
b2e465d6 AL |
392 | Type *Parse = Type::GetType(LineType.c_str()); |
393 | if (Parse == 0) | |
39442e44 | 394 | return _error->Error(_("Type '%s' is not known on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str()); |
81460e32 DK |
395 | |
396 | if (Parse->ParseLine(SrcList, Buffer.c_str() + LineType.length(), CurLine, File) == false) | |
b2e465d6 | 397 | return false; |
6c139d6e AL |
398 | } |
399 | return true; | |
400 | } | |
401 | /*}}}*/ | |
1fa78a8a MV |
402 | // SourceList::ParseFileDeb822 - Parse deb822 style sources.list /*{{{*/ |
403 | // --------------------------------------------------------------------- | |
4194c9ae | 404 | /* Returns: the number of stanzas parsed*/ |
81460e32 | 405 | bool pkgSourceList::ParseFileDeb822(string const &File) |
1fa78a8a | 406 | { |
81460e32 DK |
407 | pkgUserTagSection Tags; |
408 | unsigned int i = 1; | |
fce9f472 MV |
409 | |
410 | // see if we can read the file | |
1fa78a8a | 411 | FileFd Fd(File, FileFd::ReadOnly); |
fce9f472 | 412 | pkgTagFile Sources(&Fd); |
1fa78a8a | 413 | if (_error->PendingError() == true) |
81460e32 DK |
414 | return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str()); |
415 | ||
fce9f472 | 416 | // read step by step |
1fa78a8a MV |
417 | while (Sources.Step(Tags) == true) |
418 | { | |
81460e32 DK |
419 | if(Tags.Exists("Types") == false) |
420 | return _error->Error(_("Malformed stanza %u in source list %s (type)"),i,File.c_str()); | |
42e19c82 | 421 | |
7f316a3f | 422 | string const types = Tags.FindS("Types"); |
81460e32 | 423 | std::vector<std::string> const list_types = VectorizeString(types, ' '); |
7f316a3f | 424 | for (std::vector<std::string>::const_iterator I = list_types.begin(); |
804de19f | 425 | I != list_types.end(); ++I) |
4194c9ae | 426 | { |
7f316a3f MV |
427 | Type *Parse = Type::GetType((*I).c_str()); |
428 | if (Parse == 0) | |
429 | { | |
430 | _error->Error(_("Type '%s' is not known on stanza %u in source list %s"), (*I).c_str(),i,Fd.Name().c_str()); | |
81460e32 | 431 | return false; |
7f316a3f | 432 | } |
81460e32 | 433 | |
7f316a3f | 434 | if (!Parse->ParseStanza(SrcList, Tags, i, Fd)) |
81460e32 | 435 | return false; |
1fa78a8a | 436 | |
81460e32 | 437 | ++i; |
7f316a3f | 438 | } |
1fa78a8a | 439 | } |
81460e32 | 440 | return true; |
1fa78a8a MV |
441 | } |
442 | /*}}}*/ | |
b2e465d6 | 443 | // SourceList::FindIndex - Get the index associated with a file /*{{{*/ |
8dd562a8 DK |
444 | static bool FindInIndexFileContainer(std::vector<pkgIndexFile *> const &Cont, pkgCache::PkgFileIterator const &File, pkgIndexFile *&Found) |
445 | { | |
446 | auto const J = std::find_if(Cont.begin(), Cont.end(), [&File](pkgIndexFile const * const J) { | |
447 | return J->FindInCache(*File.Cache()) == File; | |
448 | }); | |
449 | if (J != Cont.end()) | |
450 | { | |
451 | Found = (*J); | |
452 | return true; | |
453 | } | |
454 | return false; | |
455 | } | |
b2e465d6 AL |
456 | bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, |
457 | pkgIndexFile *&Found) const | |
6c139d6e | 458 | { |
f7f0d6c7 | 459 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
8dd562a8 | 460 | if (FindInIndexFileContainer(*(*I)->GetIndexFiles(), File, Found)) |
5465192b | 461 | return true; |
8dd562a8 DK |
462 | |
463 | return FindInIndexFileContainer(VolatileFiles, File, Found); | |
36375005 AL |
464 | } |
465 | /*}}}*/ | |
b2e465d6 | 466 | // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/ |
6c139d6e AL |
467 | // --------------------------------------------------------------------- |
468 | /* */ | |
7db98ffc | 469 | bool pkgSourceList::GetIndexes(pkgAcquire *Owner, bool GetAll) const |
6c139d6e | 470 | { |
f7f0d6c7 | 471 | for (const_iterator I = SrcList.begin(); I != SrcList.end(); ++I) |
7db98ffc | 472 | if ((*I)->GetIndexes(Owner,GetAll) == false) |
b2e465d6 AL |
473 | return false; |
474 | return true; | |
6c139d6e AL |
475 | } |
476 | /*}}}*/ | |
34b53501 MV |
477 | // CNC:2003-03-03 - By Anton V. Denisov <avd@altlinux.org>. |
478 | // SourceList::ReadSourceDir - Read a directory with sources files | |
479 | // Based on ReadConfigDir() /*{{{*/ | |
480 | // --------------------------------------------------------------------- | |
481 | /* */ | |
81460e32 | 482 | bool pkgSourceList::ReadSourceDir(string const &Dir) |
34b53501 | 483 | { |
81460e32 DK |
484 | std::vector<std::string> ext; |
485 | ext.push_back("list"); | |
486 | ext.push_back("sources"); | |
487 | std::vector<std::string> const List = GetListOfFilesInDir(Dir, ext, true); | |
34b53501 MV |
488 | |
489 | // Read the files | |
f7f0d6c7 | 490 | for (vector<string>::const_iterator I = List.begin(); I != List.end(); ++I) |
34b53501 MV |
491 | if (ReadAppend(*I) == false) |
492 | return false; | |
493 | return true; | |
494 | ||
495 | } | |
496 | /*}}}*/ | |
2ec858bc MV |
497 | // GetLastModified() /*{{{*/ |
498 | // --------------------------------------------------------------------- | |
499 | /* */ | |
500 | time_t pkgSourceList::GetLastModifiedTime() | |
501 | { | |
5e7b0aa9 MV |
502 | vector<string> List; |
503 | ||
2ec858bc MV |
504 | string Main = _config->FindFile("Dir::Etc::sourcelist"); |
505 | string Parts = _config->FindDir("Dir::Etc::sourceparts"); | |
5e7b0aa9 MV |
506 | |
507 | // go over the parts | |
508 | if (DirectoryExists(Parts) == true) | |
509 | List = GetListOfFilesInDir(Parts, "list", true); | |
2ec858bc MV |
510 | |
511 | // calculate the time | |
8dd562a8 DK |
512 | std::vector<time_t> modtimes; |
513 | modtimes.reserve(1 + List.size()); | |
514 | modtimes.push_back(GetModificationTime(Main)); | |
515 | std::transform(List.begin(), List.end(), std::back_inserter(modtimes), GetModificationTime); | |
516 | auto const maxmtime = std::max_element(modtimes.begin(), modtimes.end()); | |
517 | return *maxmtime; | |
2ec858bc MV |
518 | } |
519 | /*}}}*/ | |
5465192b DK |
520 | std::vector<pkgIndexFile*> pkgSourceList::GetVolatileFiles() const /*{{{*/ |
521 | { | |
522 | return VolatileFiles; | |
523 | } | |
524 | /*}}}*/ | |
525 | void pkgSourceList::AddVolatileFile(pkgIndexFile * const File) /*{{{*/ | |
526 | { | |
527 | if (File != NULL) | |
528 | VolatileFiles.push_back(File); | |
529 | } | |
530 | /*}}}*/ |