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