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