]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debmetaindex.cc
run update post-invokes even on (partial) failures
[apt.git] / apt-pkg / deb / debmetaindex.cc
CommitLineData
ea542140 1#include <config.h>
7db98ffc 2
b07aeb1a 3#include <apt-pkg/error.h>
7db98ffc
MZ
4#include <apt-pkg/debmetaindex.h>
5#include <apt-pkg/debindexfile.h>
6#include <apt-pkg/strutl.h>
472ff00e 7#include <apt-pkg/fileutl.h>
7db98ffc
MZ
8#include <apt-pkg/acquire-item.h>
9#include <apt-pkg/configuration.h>
45df0ad2 10#include <apt-pkg/aptconfiguration.h>
472ff00e 11#include <apt-pkg/sourcelist.h>
453b82a3 12#include <apt-pkg/hashes.h>
453b82a3 13#include <apt-pkg/metaindex.h>
b07aeb1a
DK
14#include <apt-pkg/pkgcachegen.h>
15#include <apt-pkg/tagfile.h>
16#include <apt-pkg/gpgv.h>
17#include <apt-pkg/macros.h>
7db98ffc 18
453b82a3
DK
19#include <map>
20#include <string>
21#include <utility>
22#include <vector>
7cb28948 23#include <algorithm>
d7a51997 24#include <sstream>
5dd4c8b8 25
b07aeb1a 26#include <sys/stat.h>
b07aeb1a
DK
27#include <string.h>
28
268ffceb
DK
29#include <apti18n.h>
30
463c8d80
DK
31class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
32{
33 public:
34 struct APT_HIDDEN debSectionEntry
35 {
7f2d1eef
DK
36 std::string const sourcesEntry;
37 std::string const Name;
38 std::vector<std::string> const Targets;
39 std::vector<std::string> const Architectures;
40 std::vector<std::string> const Languages;
41 bool const UsePDiffs;
42 std::string const UseByHash;
463c8d80
DK
43 };
44
45 std::vector<debSectionEntry> DebEntries;
46 std::vector<debSectionEntry> DebSrcEntries;
268ffceb 47
0741daeb
DK
48 metaIndex::TriState CheckValidUntil;
49 time_t ValidUntilMin;
50 time_t ValidUntilMax;
51
1dd20368 52 std::vector<std::string> Architectures;
a628ca52 53 std::vector<std::string> NoSupportForAll;
1dd20368 54
0741daeb 55 debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {}
463c8d80
DK
56};
57 /*}}}*/
58// ReleaseIndex::MetaIndex* - display helpers /*{{{*/
59std::string debReleaseIndex::MetaIndexInfo(const char *Type) const
7db98ffc 60{
463c8d80 61 std::string Info = ::URI::ArchiveOnly(URI) + ' ';
7db98ffc
MZ
62 if (Dist[Dist.size() - 1] == '/')
63 {
64 if (Dist != "/")
65 Info += Dist;
66 }
67 else
68 Info += Dist;
69 Info += " ";
70 Info += Type;
71 return Info;
72}
b07aeb1a
DK
73std::string debReleaseIndex::Describe() const
74{
75 return MetaIndexInfo("Release");
76}
7db98ffc 77
463c8d80 78std::string debReleaseIndex::MetaIndexFile(const char *Type) const
7db98ffc
MZ
79{
80 return _config->FindDir("Dir::State::lists") +
81 URItoFileName(MetaIndexURI(Type));
82}
b90faf24 83static std::string constructMetaIndexURI(std::string URI, std::string const &Dist, char const * const Type)
7db98ffc 84{
7db98ffc 85 if (Dist == "/")
b90faf24 86 ;
7db98ffc 87 else if (Dist[Dist.size()-1] == '/')
b90faf24 88 URI += Dist;
7db98ffc 89 else
b90faf24
DK
90 URI += "dists/" + Dist + "/";
91 return URI + Type;
92}
93std::string debReleaseIndex::MetaIndexURI(const char *Type) const
94{
95 return constructMetaIndexURI(URI, Dist, Type);
7db98ffc 96}
463c8d80 97 /*}}}*/
463c8d80
DK
98// ReleaseIndex Con- and Destructors /*{{{*/
99debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
268ffceb 100 metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
4b42f43b 101{}
5ad0096a
DK
102debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) :
103 metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
104{
105 Trusted = pTrusted ? TRI_YES : TRI_NO;
106}
5dd4c8b8 107debReleaseIndex::~debReleaseIndex() {
463c8d80
DK
108 if (d != NULL)
109 delete d;
7a9f09bd 110}
463c8d80
DK
111 /*}}}*/
112// ReleaseIndex::GetIndexTargets /*{{{*/
113static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist,
114 std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries,
115 std::vector<IndexTarget> &IndexTargets)
1e0f0f28 116{
1e0f0f28
DK
117 bool const flatArchive = (Dist[Dist.length() - 1] == '/');
118 std::string baseURI = URI;
119 if (flatArchive)
120 {
121 if (Dist != "/")
122 baseURI += Dist;
123 }
124 else
125 baseURI += "dists/" + Dist + "/";
126 std::string const Release = (Dist == "/") ? "" : Dist;
1da3b7b8 127 std::string const Site = ::URI::ArchiveOnly(URI);
463c8d80 128
d7a51997
DK
129 std::string DefCompressionTypes;
130 {
131 std::vector<std::string> types = APT::Configuration::getCompressionTypes();
132 if (types.empty() == false)
133 {
134 std::ostringstream os;
135 std::copy(types.begin(), types.end()-1, std::ostream_iterator<std::string>(os, " "));
136 os << *types.rbegin();
137 DefCompressionTypes = os.str();
138 }
139 }
0179cfa8
DK
140 std::string DefKeepCompressedAs;
141 {
142 std::vector<APT::Configuration::Compressor> comps = APT::Configuration::getCompressors();
143 if (comps.empty() == false)
144 {
145 std::sort(comps.begin(), comps.end(),
146 [](APT::Configuration::Compressor const &a, APT::Configuration::Compressor const &b) { return a.Cost < b.Cost; });
147 std::ostringstream os;
148 for (auto const &c : comps)
149 if (c.Cost != 0)
150 os << c.Extension.substr(1) << ' ';
151 DefKeepCompressedAs = os.str();
152 }
153 DefKeepCompressedAs += "uncompressed";
154 }
7c1dca14
DK
155
156 std::vector<std::string> const NativeArchs = { _config->Find("APT::Architecture"), "all" };
653ef26c 157 bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false);
463c8d80 158 for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E)
1e0f0f28 159 {
463c8d80 160 for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T)
1e0f0f28 161 {
d7a51997
DK
162#define APT_T_CONFIG_STR(X, Y) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
163#define APT_T_CONFIG_BOOL(X, Y) _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
164 std::string const tplMetaKey = APT_T_CONFIG_STR(flatArchive ? "flatMetaKey" : "MetaKey", "");
165 std::string const tplShortDesc = APT_T_CONFIG_STR("ShortDescription", "");
166 std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG_STR(flatArchive ? "flatDescription" : "Description", "");
39c724b4 167 std::string const tplIdentifier = APT_T_CONFIG_STR("Identifier", *T);
d7a51997
DK
168 bool const IsOptional = APT_T_CONFIG_BOOL("Optional", true);
169 bool const KeepCompressed = APT_T_CONFIG_BOOL("KeepCompressed", GzipIndex);
9adb9778 170 bool const DefaultEnabled = APT_T_CONFIG_BOOL("DefaultEnabled", true);
d7a51997 171 bool const UsePDiffs = APT_T_CONFIG_BOOL("PDiffs", E->UsePDiffs);
24e8f24e 172 std::string const UseByHash = APT_T_CONFIG_STR("By-Hash", E->UseByHash);
d7a51997 173 std::string const CompressionTypes = APT_T_CONFIG_STR("CompressionTypes", DefCompressionTypes);
0179cfa8 174 std::string KeepCompressedAs = APT_T_CONFIG_STR("KeepCompressedAs", "");
7f2d1eef 175 std::string const FallbackOf = APT_T_CONFIG_STR("Fallback-Of", "");
d7a51997
DK
176#undef APT_T_CONFIG_BOOL
177#undef APT_T_CONFIG_STR
463c8d80 178 if (tplMetaKey.empty())
1e0f0f28
DK
179 continue;
180
0179cfa8
DK
181 if (KeepCompressedAs.empty())
182 KeepCompressedAs = DefKeepCompressedAs;
183 else
184 {
185 std::vector<std::string> const defKeep = VectorizeString(DefKeepCompressedAs, ' ');
186 std::vector<std::string> const valKeep = VectorizeString(KeepCompressedAs, ' ');
187 std::vector<std::string> keep;
188 for (auto const &val : valKeep)
189 {
190 if (val.empty())
191 continue;
192 if (std::find(defKeep.begin(), defKeep.end(), val) == defKeep.end())
193 continue;
194 keep.push_back(val);
195 }
196 if (std::find(keep.begin(), keep.end(), "uncompressed") == keep.end())
197 keep.push_back("uncompressed");
198 std::ostringstream os;
199 std::copy(keep.begin(), keep.end()-1, std::ostream_iterator<std::string>(os, " "));
200 os << *keep.rbegin();
201 KeepCompressedAs = os.str();
202 }
203
463c8d80 204 for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L)
1e0f0f28 205 {
463c8d80
DK
206 if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
207 continue;
208
209 for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A)
1e0f0f28 210 {
7c1dca14 211 for (auto const &NativeArch: NativeArchs)
463c8d80 212 {
7c1dca14
DK
213 constexpr static auto BreakPoint = "$(NATIVE_ARCHITECTURE)";
214 // available in templates
215 std::map<std::string, std::string> Options;
216 Options.insert(std::make_pair("SITE", Site));
217 Options.insert(std::make_pair("RELEASE", Release));
218 if (tplMetaKey.find("$(COMPONENT)") != std::string::npos)
219 Options.insert(std::make_pair("COMPONENT", E->Name));
220 if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
221 Options.insert(std::make_pair("LANGUAGE", *L));
222 if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos)
223 Options.insert(std::make_pair("ARCHITECTURE", *A));
224 else if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
225 Options.insert(std::make_pair("ARCHITECTURE", NativeArch));
226 if (tplMetaKey.find("$(NATIVE_ARCHITECTURE)") != std::string::npos)
227 Options.insert(std::make_pair("NATIVE_ARCHITECTURE", NativeArch));
d7a51997 228
7c1dca14
DK
229 std::string MetaKey = tplMetaKey;
230 std::string ShortDesc = tplShortDesc;
231 std::string LongDesc = tplLongDesc;
39c724b4 232 std::string Identifier = tplIdentifier;
7c1dca14 233 for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
3090ae69 234 {
39c724b4
DK
235 std::string const varname = "$(" + O->first + ")";
236 MetaKey = SubstVar(MetaKey, varname, O->second);
237 ShortDesc = SubstVar(ShortDesc, varname, O->second);
238 LongDesc = SubstVar(LongDesc, varname, O->second);
239 Identifier = SubstVar(Identifier, varname, O->second);
3090ae69 240 }
3090ae69 241
3090ae69 242 {
7c1dca14
DK
243 auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
244 return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
245 E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T == IT.Option(IndexTarget::CREATED_BY);
246 });
247 if (dup != IndexTargets.end())
248 {
249 if (tplMetaKey.find(BreakPoint) == std::string::npos)
250 break;
251 continue;
252 }
3090ae69 253 }
3090ae69 254
3090ae69 255 {
7c1dca14
DK
256 auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &IT) {
257 return MetaKey == IT.MetaKey && baseURI == IT.Option(IndexTarget::BASE_URI) &&
258 E->sourcesEntry == IT.Option(IndexTarget::SOURCESENTRY) && *T != IT.Option(IndexTarget::CREATED_BY);
259 });
260 if (dup != IndexTargets.end())
261 {
262 std::string const dupT = dup->Option(IndexTarget::CREATED_BY);
263 std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
264 //TRANSLATOR: an identifier like Packages; Releasefile key indicating
265 // a file like main/binary-amd64/Packages; another identifier like Contents;
266 // filename and linenumber of the sources.list entry currently parsed
267 _error->Warning(_("Target %s wants to acquire the same file (%s) as %s from source %s"),
268 T->c_str(), MetaKey.c_str(), dupT.c_str(), dupEntry.c_str());
269 if (tplMetaKey.find(BreakPoint) == std::string::npos)
270 break;
271 continue;
272 }
3090ae69 273 }
3090ae69 274
7c1dca14
DK
275 {
276 auto const dup = std::find_if(IndexTargets.begin(), IndexTargets.end(), [&](IndexTarget const &T) {
277 return MetaKey == T.MetaKey && baseURI == T.Option(IndexTarget::BASE_URI) &&
278 E->sourcesEntry != T.Option(IndexTarget::SOURCESENTRY);
279 });
280 if (dup != IndexTargets.end())
281 {
282 std::string const dupEntry = dup->Option(IndexTarget::SOURCESENTRY);
283 //TRANSLATOR: an identifier like Packages; Releasefile key indicating
284 // a file like main/binary-amd64/Packages; filename and linenumber of
285 // two sources.list entries
286 _error->Warning(_("Target %s (%s) is configured multiple times in %s and %s"),
287 T->c_str(), MetaKey.c_str(), dupEntry.c_str(), E->sourcesEntry.c_str());
288 if (tplMetaKey.find(BreakPoint) == std::string::npos)
289 break;
290 continue;
291 }
292 }
d7a51997 293
7c1dca14
DK
294 // not available in templates, but in the indextarget
295 Options.insert(std::make_pair("BASE_URI", baseURI));
296 Options.insert(std::make_pair("REPO_URI", URI));
39c724b4 297 Options.insert(std::make_pair("IDENTIFIER", Identifier));
7c1dca14
DK
298 Options.insert(std::make_pair("TARGET_OF", Type));
299 Options.insert(std::make_pair("CREATED_BY", *T));
7f2d1eef 300 Options.insert(std::make_pair("FALLBACK_OF", FallbackOf));
7c1dca14
DK
301 Options.insert(std::make_pair("PDIFFS", UsePDiffs ? "yes" : "no"));
302 Options.insert(std::make_pair("BY_HASH", UseByHash));
303 Options.insert(std::make_pair("DEFAULTENABLED", DefaultEnabled ? "yes" : "no"));
304 Options.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes));
305 Options.insert(std::make_pair("KEEPCOMPRESSEDAS", KeepCompressedAs));
306 Options.insert(std::make_pair("SOURCESENTRY", E->sourcesEntry));
1dd20368 307
7c1dca14
DK
308 bool IsOpt = IsOptional;
309 if (IsOpt == false)
310 {
311 auto const arch = Options.find("ARCHITECTURE");
312 if (arch != Options.end() && arch->second == "all")
313 IsOpt = true;
314 }
315
316 IndexTarget Target(
317 MetaKey,
318 ShortDesc,
319 LongDesc,
320 Options.find("BASE_URI")->second + MetaKey,
321 IsOpt,
322 KeepCompressed,
323 Options
324 );
325 IndexTargets.push_back(Target);
326
327 if (tplMetaKey.find(BreakPoint) == std::string::npos)
328 break;
329 }
463c8d80
DK
330
331 if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos)
1e0f0f28 332 break;
d3a869e3 333
1e0f0f28
DK
334 }
335
463c8d80 336 if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos)
1e0f0f28 337 break;
463c8d80 338
1e0f0f28
DK
339 }
340
1e0f0f28
DK
341 }
342 }
59148d96 343}
261727f0 344std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
59148d96 345{
463c8d80
DK
346 std::vector<IndexTarget> IndexTargets;
347 GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets);
348 GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets);
349 return IndexTargets;
7db98ffc 350}
463c8d80 351 /*}}}*/
3090ae69
DK
352void debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/
353 bool const isSrc, std::string const &Name,
463c8d80
DK
354 std::vector<std::string> const &Targets,
355 std::vector<std::string> const &Architectures,
1a3a14ac 356 std::vector<std::string> Languages,
24e8f24e 357 bool const usePDiffs, std::string const &useByHash)
463c8d80
DK
358{
359 if (Languages.empty() == true)
360 Languages.push_back("none");
361 debReleaseIndexPrivate::debSectionEntry const entry = {
24e8f24e 362 sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs, useByHash
463c8d80
DK
363 };
364 if (isSrc)
365 d->DebSrcEntries.push_back(entry);
366 else
367 d->DebEntries.push_back(entry);
368}
369 /*}}}*/
59148d96 370
5ad0096a
DK
371bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/
372{
373 LoadedSuccessfully = TRI_NO;
374 FileFd Fd;
375 if (OpenMaybeClearSignedFile(Filename, Fd) == false)
376 return false;
377
378 pkgTagFile TagFile(&Fd, Fd.Size());
95278287 379 if (Fd.IsOpen() == false || Fd.Failed())
5ad0096a
DK
380 {
381 if (ErrorText != NULL)
382 strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
383 return false;
384 }
385
386 pkgTagSection Section;
387 const char *Start, *End;
388 if (TagFile.Step(Section) == false)
389 {
390 if (ErrorText != NULL)
391 strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str());
392 return false;
393 }
394 // FIXME: find better tag name
395 SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
396
397 Suite = Section.FindS("Suite");
398 Codename = Section.FindS("Codename");
1dd20368
DK
399 {
400 std::string const archs = Section.FindS("Architectures");
401 if (archs.empty() == false)
402 d->Architectures = VectorizeString(archs, ' ');
403 }
a628ca52
DK
404 {
405 std::string const targets = Section.FindS("No-Support-for-Architecture-all");
406 if (targets.empty() == false)
407 d->NoSupportForAll = VectorizeString(targets, ' ');
408 }
5ad0096a
DK
409
410 bool FoundHashSum = false;
bd4a8f51
DK
411 bool FoundStrongHashSum = false;
412 auto const SupportedHashes = HashString::SupportedHashes();
413 for (int i=0; SupportedHashes[i] != NULL; i++)
5ad0096a 414 {
bd4a8f51 415 if (!Section.Find(SupportedHashes[i], Start, End))
5ad0096a
DK
416 continue;
417
418 std::string Name;
419 std::string Hash;
420 unsigned long long Size;
421 while (Start < End)
422 {
423 if (!parseSumData(Start, End, Name, Hash, Size))
424 return false;
425
bd4a8f51 426 HashString const hs(SupportedHashes[i], Hash);
5ad0096a
DK
427 if (Entries.find(Name) == Entries.end())
428 {
429 metaIndex::checkSum *Sum = new metaIndex::checkSum;
430 Sum->MetaKeyFilename = Name;
431 Sum->Size = Size;
432 Sum->Hashes.FileSize(Size);
bd4a8f51 433 APT_IGNORE_DEPRECATED(Sum->Hash = hs;)
5ad0096a
DK
434 Entries[Name] = Sum;
435 }
bd4a8f51 436 Entries[Name]->Hashes.push_back(hs);
5ad0096a 437 FoundHashSum = true;
bd4a8f51
DK
438 if (FoundStrongHashSum == false && hs.usable() == true)
439 FoundStrongHashSum = true;
5ad0096a
DK
440 }
441 }
442
443 if(FoundHashSum == false)
444 {
445 if (ErrorText != NULL)
446 strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
447 return false;
448 }
bd4a8f51
DK
449 if(FoundStrongHashSum == false)
450 {
451 if (ErrorText != NULL)
a2025a9a 452 strprintf(*ErrorText, _("No Hash entry in Release file %s which is considered strong enough for security purposes"), Filename.c_str());
bd4a8f51
DK
453 return false;
454 }
5ad0096a
DK
455
456 std::string const StrDate = Section.FindS("Date");
457 if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
458 {
89901946 459 _error->Warning( _("Invalid '%s' entry in Release file %s"), "Date", Filename.c_str());
6fc2e030 460 Date = 0;
5ad0096a
DK
461 }
462
0741daeb
DK
463 bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true);
464 if (d->CheckValidUntil == metaIndex::TRI_NO)
465 CheckValidUntil = false;
466 else if (d->CheckValidUntil == metaIndex::TRI_YES)
467 CheckValidUntil = true;
5ad0096a 468
0741daeb 469 if (CheckValidUntil == true)
5ad0096a 470 {
0741daeb
DK
471 std::string const Label = Section.FindS("Label");
472 std::string const StrValidUntil = Section.FindS("Valid-Until");
473
474 // if we have a Valid-Until header in the Release file, use it as default
475 if (StrValidUntil.empty() == false)
5ad0096a 476 {
0741daeb
DK
477 if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
478 {
479 if (ErrorText != NULL)
89901946 480 strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Valid-Until", Filename.c_str());
0741daeb
DK
481 return false;
482 }
483 }
484 // get the user settings for this archive and use what expires earlier
485 time_t MaxAge = d->ValidUntilMax;
486 if (MaxAge == 0)
487 {
488 MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
489 if (Label.empty() == false)
490 MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
491 }
492 time_t MinAge = d->ValidUntilMin;
493 if (MinAge == 0)
494 {
495 MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
496 if (Label.empty() == false)
497 MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
5ad0096a 498 }
5ad0096a 499
6fc2e030
DK
500 if (MinAge != 0 || ValidUntil != 0 || MaxAge != 0)
501 {
502 if (MinAge != 0 && ValidUntil != 0) {
503 time_t const min_date = Date + MinAge;
504 if (ValidUntil < min_date)
505 ValidUntil = min_date;
506 }
507 if (MaxAge != 0 && Date != 0) {
508 time_t const max_date = Date + MaxAge;
509 if (ValidUntil == 0 || ValidUntil > max_date)
510 ValidUntil = max_date;
511 }
0741daeb 512 }
5ad0096a 513 }
59148d96 514
89901946
DK
515 /* as the Release file is parsed only after it was verified, the Signed-By field
516 does not effect the current, but the "next" Release file */
517 auto Sign = Section.FindS("Signed-By");
518 if (Sign.empty() == false)
519 {
520 std::transform(Sign.begin(), Sign.end(), Sign.begin(), [&](char const c) {
521 return (isspace(c) == 0) ? c : ',';
522 });
523 auto fingers = VectorizeString(Sign, ',');
524 std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
525 std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
526 if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
527 {
528 if (ErrorText != NULL)
529 strprintf(*ErrorText, _("Invalid '%s' entry in Release file %s"), "Signed-By", Filename.c_str());
530 return std::string();
531 }
532 return finger;
533 });
534 if (fingers.empty() == false && std::find(fingers.begin(), fingers.end(), "") == fingers.end())
535 {
536 std::stringstream os;
537 std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
538 SignedBy = os.str();
539 }
540 }
541
0741daeb 542 LoadedSuccessfully = TRI_YES;
5ad0096a
DK
543 return true;
544}
545 /*}}}*/
546metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/
547{
548 if (Trusted == TRI_NO)
549 return new debReleaseIndex(URI, Dist, false);
550 else if (Trusted == TRI_YES)
551 return new debReleaseIndex(URI, Dist, true);
552 else
553 return new debReleaseIndex(URI, Dist);
554}
555 /*}}}*/
556bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/
557 std::string &Name, std::string &Hash, unsigned long long &Size)
7db98ffc 558{
5ad0096a
DK
559 Name = "";
560 Hash = "";
561 Size = 0;
562 /* Skip over the first blank */
563 while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
564 && Start < End)
565 Start++;
566 if (Start >= End)
567 return false;
07cb47e7 568
5ad0096a
DK
569 /* Move EntryEnd to the end of the first entry (the hash) */
570 const char *EntryEnd = Start;
571 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
572 && EntryEnd < End)
573 EntryEnd++;
574 if (EntryEnd == End)
575 return false;
576
577 Hash.append(Start, EntryEnd-Start);
578
579 /* Skip over intermediate blanks */
580 Start = EntryEnd;
581 while (*Start == '\t' || *Start == ' ')
582 Start++;
583 if (Start >= End)
584 return false;
585
586 EntryEnd = Start;
587 /* Find the end of the second entry (the size) */
588 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
589 && EntryEnd < End)
590 EntryEnd++;
591 if (EntryEnd == End)
592 return false;
593
594 Size = strtoull (Start, NULL, 10);
595
596 /* Skip over intermediate blanks */
597 Start = EntryEnd;
598 while (*Start == '\t' || *Start == ' ')
599 Start++;
600 if (Start >= End)
601 return false;
602
603 EntryEnd = Start;
604 /* Find the end of the third entry (the filename) */
605 while ((*EntryEnd != '\t' && *EntryEnd != ' ' &&
606 *EntryEnd != '\n' && *EntryEnd != '\r')
607 && EntryEnd < End)
608 EntryEnd++;
609
610 Name.append(Start, EntryEnd-Start);
611 Start = EntryEnd; //prepare for the next round
612 return true;
613}
614 /*}}}*/
615
616bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/
617{
653ef26c 618#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>())
3d8232bf 619 pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
a8f565d3 620 APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), this);
448c38bd 621#undef APT_TARGET
5ad0096a 622 // special case for --print-uris
448c38bd 623 if (GetAll)
a8f565d3 624 for (auto const &Target: GetIndexTargets())
7f2d1eef
DK
625 if (Target.Option(IndexTarget::FALLBACK_OF).empty())
626 new pkgAcqIndex(Owner, TransactionManager, Target);
fe0f7911 627
55971004 628 return true;
7db98ffc 629}
463c8d80 630 /*}}}*/
0741daeb 631// ReleaseIndex::Set* TriState options /*{{{*/
5ad0096a 632bool debReleaseIndex::SetTrusted(TriState const pTrusted)
4b42f43b 633{
5ad0096a
DK
634 if (Trusted == TRI_UNSET)
635 Trusted = pTrusted;
636 else if (Trusted != pTrusted)
268ffceb 637 // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
d04e44ac 638 return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
268ffceb 639 return true;
4b42f43b 640}
0741daeb
DK
641bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil)
642{
643 if (d->CheckValidUntil == TRI_UNSET)
644 d->CheckValidUntil = pCheckValidUntil;
645 else if (d->CheckValidUntil != pCheckValidUntil)
d04e44ac 646 return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str());
0741daeb
DK
647 return true;
648}
649bool debReleaseIndex::SetValidUntilMin(time_t const Valid)
650{
651 if (d->ValidUntilMin == 0)
652 d->ValidUntilMin = Valid;
653 else if (d->ValidUntilMin != Valid)
d04e44ac 654 return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str());
0741daeb
DK
655 return true;
656}
657bool debReleaseIndex::SetValidUntilMax(time_t const Valid)
658{
659 if (d->ValidUntilMax == 0)
660 d->ValidUntilMax = Valid;
661 else if (d->ValidUntilMax != Valid)
d04e44ac 662 return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str());
0741daeb 663 return true;
b0d40854
DK
664}
665bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy)
666{
667 if (SignedBy.empty() == true && pSignedBy.empty() == false)
668 {
669 if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things
46e00c90 670 SignedBy = pSignedBy; // absolute path to a keyring file
b0d40854
DK
671 else
672 {
673 // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
674 // but fingerprints are harder to fake than the others and this option is set once,
675 // not interactively all the time so easy to type is not really a concern.
46e00c90
DK
676 auto fingers = VectorizeString(pSignedBy, ',');
677 std::transform(fingers.begin(), fingers.end(), fingers.begin(), [&](std::string finger) {
678 std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
679 if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
680 {
681 _error->Error(_("Invalid value set for option %s regarding source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint");
682 return std::string();
683 }
684 return finger;
685 });
686 std::stringstream os;
687 std::copy(fingers.begin(), fingers.end(), std::ostream_iterator<std::string>(os, ","));
688 SignedBy = os.str();
b0d40854 689 }
71203dbf
JAK
690 // Normalize the string: Remove trailing commas
691 while (SignedBy[SignedBy.size() - 1] == ',')
692 SignedBy.resize(SignedBy.size() - 1);
693 }
694 else {
695 // Only compare normalized strings
696 auto pSignedByView = APT::StringView(pSignedBy);
697 while (pSignedByView[pSignedByView.size() - 1] == ',')
698 pSignedByView = pSignedByView.substr(0, pSignedByView.size() - 1);
699 if (pSignedByView != SignedBy)
700 return _error->Error(_("Conflicting values set for option %s regarding source %s %s: %s != %s"), "Signed-By", URI.c_str(), Dist.c_str(), SignedBy.c_str(), pSignedByView.to_string().c_str());
b0d40854 701 }
b0d40854 702 return true;
0741daeb
DK
703}
704 /*}}}*/
705// ReleaseIndex::IsTrusted /*{{{*/
7db98ffc
MZ
706bool debReleaseIndex::IsTrusted() const
707{
5ad0096a 708 if (Trusted == TRI_YES)
4b42f43b 709 return true;
5ad0096a 710 else if (Trusted == TRI_NO)
4b42f43b
DK
711 return false;
712
713
4e0ad446 714 if(_config->FindB("APT::Authentication::TrustCDROM", false))
e8cdc56a
MV
715 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
716 return true;
fe0f7911 717
463c8d80 718 if (FileExists(MetaIndexFile("Release.gpg")))
7db98ffc 719 return true;
fe0f7911 720
463c8d80 721 return FileExists(MetaIndexFile("InRelease"));
7db98ffc 722}
463c8d80 723 /*}}}*/
1dd20368
DK
724bool debReleaseIndex::IsArchitectureSupported(std::string const &arch) const/*{{{*/
725{
726 if (d->Architectures.empty())
727 return true;
728 return std::find(d->Architectures.begin(), d->Architectures.end(), arch) != d->Architectures.end();
729}
730 /*}}}*/
a628ca52
DK
731bool debReleaseIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/
732{
733 if (d->NoSupportForAll.empty())
734 return true;
735 return std::find(d->NoSupportForAll.begin(), d->NoSupportForAll.end(), target.Option(IndexTarget::CREATED_BY)) == d->NoSupportForAll.end();
736}
737 /*}}}*/
463c8d80 738std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/
59148d96 739{
e3c1cfc7
DK
740 if (Indexes != NULL)
741 return Indexes;
59148d96 742
e3c1cfc7 743 Indexes = new std::vector<pkgIndexFile*>();
e3c1cfc7 744 bool const istrusted = IsTrusted();
8dd562a8 745 for (auto const &T: GetIndexTargets())
59148d96 746 {
8dd562a8 747 std::string const TargetName = T.Option(IndexTarget::CREATED_BY);
59148d96 748 if (TargetName == "Packages")
8dd562a8 749 Indexes->push_back(new debPackagesIndex(T, istrusted));
59148d96 750 else if (TargetName == "Sources")
8dd562a8 751 Indexes->push_back(new debSourcesIndex(T, istrusted));
59148d96 752 else if (TargetName == "Translations")
8dd562a8 753 Indexes->push_back(new debTranslationsIndex(T));
59148d96 754 }
e3c1cfc7 755 return Indexes;
5dd4c8b8 756}
463c8d80 757 /*}}}*/
a7a5b0d9 758
463c8d80 759static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/
b07aeb1a
DK
760{
761 ReleaseFile = That->MetaIndexFile("InRelease");
762 bool releaseExists = false;
763 if (FileExists(ReleaseFile) == true)
764 releaseExists = true;
765 else
766 {
767 ReleaseFile = That->MetaIndexFile("Release");
768 if (FileExists(ReleaseFile))
769 releaseExists = true;
770 }
771 return releaseExists;
772}
463c8d80 773 /*}}}*/
b07aeb1a
DK
774bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/
775{
776 std::string ReleaseFile;
777 bool const releaseExists = ReleaseFileName(this, ReleaseFile);
778
779 ::URI Tmp(URI);
780 if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false)
781 return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str());
782
783 if (releaseExists == false)
784 return true;
785
786 FileFd Rel;
787 // Beware: The 'Release' file might be clearsigned in case the
788 // signature for an 'InRelease' file couldn't be checked
789 if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
790 return false;
b07aeb1a
DK
791
792 // Store the IMS information
793 pkgCache::RlsFileIterator File = Gen.GetCurRlsFile();
794 pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File);
795 // Rel can't be used as this is potentially a temporary file
796 struct stat Buf;
797 if (stat(ReleaseFile.c_str(), &Buf) != 0)
798 return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str());
799 File->Size = Buf.st_size;
800 File->mtime = Buf.st_mtime;
801
802 pkgTagFile TagFile(&Rel, Rel.Size());
803 pkgTagSection Section;
95278287 804 if (Rel.IsOpen() == false || Rel.Failed() || TagFile.Step(Section) == false)
b07aeb1a
DK
805 return false;
806
807 std::string data;
808 #define APT_INRELEASE(TYPE, TAG, STORE) \
809 data = Section.FindS(TAG); \
810 if (data.empty() == false) \
811 { \
812 map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
95278287 813 if (storage == 0) return false; \
b07aeb1a
DK
814 STORE = storage; \
815 }
816 APT_INRELEASE(MIXED, "Suite", File->Archive)
817 APT_INRELEASE(VERSIONNUMBER, "Version", File->Version)
818 APT_INRELEASE(MIXED, "Origin", File->Origin)
819 APT_INRELEASE(MIXED, "Codename", File->Codename)
820 APT_INRELEASE(MIXED, "Label", File->Label)
821 #undef APT_INRELEASE
822 Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic);
823 Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades);
824
95278287 825 return true;
b07aeb1a
DK
826}
827 /*}}}*/
828// ReleaseIndex::FindInCache - Find this index /*{{{*/
3fd89e62 829pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const
b07aeb1a
DK
830{
831 std::string ReleaseFile;
832 bool const releaseExists = ReleaseFileName(this, ReleaseFile);
833
834 pkgCache::RlsFileIterator File = Cache.RlsFileBegin();
835 for (; File.end() == false; ++File)
836 {
837 if (File->FileName == 0 || ReleaseFile != File.FileName())
838 continue;
839
840 // empty means the file does not exist by "design"
3fd89e62 841 if (ModifyCheck == false || (releaseExists == false && File->Size == 0))
b07aeb1a
DK
842 return File;
843
844 struct stat St;
845 if (stat(File.FileName(),&St) != 0)
846 {
847 if (_config->FindB("Debug::pkgCacheGen", false))
848 std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
849 return pkgCache::RlsFileIterator(Cache);
850 }
851 if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
852 {
853 if (_config->FindB("Debug::pkgCacheGen", false))
854 std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
855 << ") or mtime (" << St.st_mtime << " <> " << File->mtime
856 << ") doesn't match for " << File.FileName() << std::endl;
857 return pkgCache::RlsFileIterator(Cache);
858 }
859 return File;
860 }
861
862 return File;
863}
864 /*}}}*/
865
463c8d80
DK
866static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, /*{{{*/
867 std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
7db98ffc 868{
463c8d80
DK
869 std::map<std::string, std::string>::const_iterator val = Options.find(Name);
870 std::vector<std::string> Values;
871 if (val != Options.end())
872 Values = VectorizeString(val->second, ',');
873 else
874 Values = defaultValues;
7db98ffc 875
1dd20368
DK
876 // all is a very special architecture users shouldn't be concerned with explicitly
877 if (Name == "arch" && std::find(Values.begin(), Values.end(), "all") == Values.end())
878 Values.push_back("all");
879
463c8d80 880 if ((val = Options.find(Name + "+")) != Options.end())
7db98ffc 881 {
8dd562a8
DK
882 std::vector<std::string> const plus = VectorizeString(val->second, ',');
883 std::copy_if(plus.begin(), plus.end(), std::back_inserter(Values), [&Values](std::string const &v) {
884 return std::find(Values.begin(), Values.end(), v) == Values.end();
885 });
463c8d80
DK
886 }
887 if ((val = Options.find(Name + "-")) != Options.end())
888 {
8dd562a8
DK
889 std::vector<std::string> const minus = VectorizeString(val->second, ',');
890 Values.erase(std::remove_if(Values.begin(), Values.end(), [&minus](std::string const &v) {
891 return std::find(minus.begin(), minus.end(), v) != minus.end();
892 }), Values.end());
463c8d80
DK
893 }
894 return Values;
895}
896 /*}}}*/
897class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
898{
0741daeb
DK
899 metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const
900 {
901 std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
902 if (opt != Options.end())
903 return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO;
904 return metaIndex::TRI_DONTCARE;
905 }
906
907 time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name) const
908 {
909 std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
910 if (opt == Options.end())
911 return 0;
912 return strtoull(opt->second.c_str(), NULL, 10);
913 }
914
463c8d80 915 protected:
3d1be93d 916
463c8d80
DK
917 bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI,
918 std::string const &Dist, std::string const &Section,
919 bool const &IsSrc, std::map<std::string, std::string> const &Options) const
920 {
b90faf24
DK
921 debReleaseIndex * Deb = nullptr;
922 std::string const FileName = URItoFileName(constructMetaIndexURI(URI, Dist, "Release"));
923 for (auto const &I: List)
7db98ffc 924 {
5dd4c8b8 925 // We only worry about debian entries here
b90faf24 926 if (strcmp(I->GetType(), "deb") != 0)
5dd4c8b8
DK
927 continue;
928
b90faf24
DK
929 auto const D = dynamic_cast<debReleaseIndex*>(I);
930 if (unlikely(D == nullptr))
931 continue;
932
933 /* This check ensures that there will be only one Release file
5dd4c8b8
DK
934 queued for all the Packages files and Sources files it
935 corresponds to. */
b90faf24 936 if (URItoFileName(D->MetaIndexURI("Release")) == FileName)
7db98ffc 937 {
b90faf24
DK
938 Deb = D;
939 break;
7db98ffc
MZ
940 }
941 }
4b42f43b 942
7db98ffc 943 // No currently created Release file indexes this entry, so we create a new one.
b90faf24 944 if (Deb == nullptr)
261727f0 945 {
4b42f43b 946 Deb = new debReleaseIndex(URI, Dist);
261727f0
DK
947 List.push_back(Deb);
948 }
4b42f43b 949
e6a12ff7 950 std::vector<std::string> const alltargets = _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true);
9adb9778
DK
951 std::vector<std::string> deftargets;
952 deftargets.reserve(alltargets.size());
953 std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(deftargets), [&](std::string const &t) {
954 std::string c = "Acquire::IndexTargets::";
955 c.append(Name).append("::").append(t).append("::DefaultEnabled");
956 return _config->FindB(c, true);
957 });
958 std::vector<std::string> mytargets = parsePlusMinusOptions("target", Options, deftargets);
8dd562a8
DK
959 for (auto const &target : alltargets)
960 {
961 std::map<std::string, std::string>::const_iterator const opt = Options.find(target);
962 if (opt == Options.end())
963 continue;
39c724b4
DK
964 auto const idMatch = [&](std::string const &t) {
965 return target == _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + t + "::Identifier", t);
966 };
967 if (StringToBool(opt->second))
968 std::copy_if(alltargets.begin(), alltargets.end(), std::back_inserter(mytargets), idMatch);
969 else
970 mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), idMatch), mytargets.end());
8dd562a8 971 }
7f2d1eef
DK
972 // if we can't order it in a 1000 steps we give up… probably a cycle
973 for (auto i = 0; i < 1000; ++i)
974 {
975 bool Changed = false;
976 for (auto t = mytargets.begin(); t != mytargets.end(); ++t)
977 {
978 std::string const fallback = _config->Find(std::string("Acquire::IndexTargets::") + Name + "::" + *t + "::Fallback-Of");
979 if (fallback.empty())
980 continue;
981 auto const faller = std::find(mytargets.begin(), mytargets.end(), fallback);
982 if (faller == mytargets.end() || faller < t)
983 continue;
984 Changed = true;
985 auto const tv = *t;
986 mytargets.erase(t);
987 mytargets.emplace_back(tv);
988 }
989 if (Changed == false)
990 break;
991 }
39c724b4
DK
992 // remove duplicates without changing the order (in first appearance)
993 {
994 std::set<std::string> seenOnce;
995 mytargets.erase(std::remove_if(mytargets.begin(), mytargets.end(), [&](std::string const &t) {
996 return seenOnce.insert(t).second == false;
997 }), mytargets.end());
998 }
8dd562a8 999
1a3a14ac
DK
1000 bool UsePDiffs = _config->FindB("Acquire::PDiffs", true);
1001 {
1002 std::map<std::string, std::string>::const_iterator const opt = Options.find("pdiffs");
1003 if (opt != Options.end())
1004 UsePDiffs = StringToBool(opt->second);
1005 }
8dd562a8 1006
24e8f24e
DK
1007 std::string UseByHash = _config->Find("APT::Acquire::By-Hash", "yes");
1008 UseByHash = _config->Find("Acquire::By-Hash", UseByHash);
1009 {
1010 std::string const host = ::URI(URI).Host;
1011 UseByHash = _config->Find("APT::Acquire::" + host + "::By-Hash", UseByHash);
1012 UseByHash = _config->Find("Acquire::" + host + "::By-Hash", UseByHash);
1013 std::map<std::string, std::string>::const_iterator const opt = Options.find("by-hash");
1014 if (opt != Options.end())
1015 UseByHash = opt->second;
1016 }
1017
3090ae69 1018 auto const entry = Options.find("sourceslist-entry");
463c8d80 1019 Deb->AddComponent(
3090ae69 1020 entry->second,
463c8d80
DK
1021 IsSrc,
1022 Section,
e6a12ff7 1023 mytargets,
463c8d80 1024 parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()),
1a3a14ac 1025 parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)),
24e8f24e
DK
1026 UsePDiffs,
1027 UseByHash
463c8d80 1028 );
261727f0 1029
0741daeb
DK
1030 if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||
1031 Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false ||
1032 Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false ||
1033 Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false)
268ffceb 1034 return false;
261727f0 1035
b0d40854
DK
1036 std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by");
1037 if (signedby == Options.end())
1038 {
89901946
DK
1039 bool alreadySet = false;
1040 std::string filename;
1041 if (ReleaseFileName(Deb, filename))
1042 {
1043 auto OldDeb = Deb->UnloadedClone();
1044 _error->PushToStack();
1045 OldDeb->Load(filename, nullptr);
1046 bool const goodLoad = _error->PendingError() == false;
1047 _error->RevertToStack();
1048 if (goodLoad)
1049 {
1050 if (OldDeb->GetValidUntil() > 0)
1051 {
1052 time_t const invalid_since = time(NULL) - OldDeb->GetValidUntil();
1053 if (invalid_since <= 0)
1054 {
1055 Deb->SetSignedBy(OldDeb->GetSignedBy());
1056 alreadySet = true;
1057 }
1058 }
1059 }
1060 delete OldDeb;
1061 }
1062 if (alreadySet == false && Deb->SetSignedBy("") == false)
b0d40854
DK
1063 return false;
1064 }
1065 else
1066 {
1067 if (Deb->SetSignedBy(signedby->second) == false)
1068 return false;
1069 }
1070
7db98ffc
MZ
1071 return true;
1072 }
0d29b9d4 1073
463c8d80
DK
1074 debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label)
1075 {
1076 }
1077};
1078 /*}}}*/
1079class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/
7db98ffc
MZ
1080{
1081 public:
1082
463c8d80
DK
1083 bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
1084 std::string const &Dist, std::string const &Section,
3b302846 1085 std::map<std::string, std::string> const &Options) const APT_OVERRIDE
7db98ffc 1086 {
5dd4c8b8 1087 return CreateItemInternal(List, URI, Dist, Section, false, Options);
7db98ffc
MZ
1088 }
1089
463c8d80 1090 debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
7db98ffc 1091 {
463c8d80 1092 }
7db98ffc 1093};
463c8d80
DK
1094 /*}}}*/
1095class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/
7db98ffc
MZ
1096{
1097 public:
1098
463c8d80
DK
1099 bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
1100 std::string const &Dist, std::string const &Section,
3b302846 1101 std::map<std::string, std::string> const &Options) const APT_OVERRIDE
7db98ffc 1102 {
5dd4c8b8 1103 return CreateItemInternal(List, URI, Dist, Section, true, Options);
7db98ffc 1104 }
463c8d80
DK
1105
1106 debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
7db98ffc 1107 {
463c8d80 1108 }
7db98ffc 1109};
463c8d80 1110 /*}}}*/
7db98ffc 1111
dce45dbe
DK
1112APT_HIDDEN debSLTypeDeb _apt_DebType;
1113APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;