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