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