3 #include <apt-pkg/debmetaindex.h>
4 #include <apt-pkg/debindexfile.h>
5 #include <apt-pkg/strutl.h>
6 #include <apt-pkg/fileutl.h>
7 #include <apt-pkg/acquire-item.h>
8 #include <apt-pkg/configuration.h>
9 #include <apt-pkg/aptconfiguration.h>
10 #include <apt-pkg/indexrecords.h>
11 #include <apt-pkg/sourcelist.h>
12 #include <apt-pkg/hashes.h>
13 #include <apt-pkg/macros.h>
14 #include <apt-pkg/metaindex.h>
26 string
debReleaseIndex::Info(const char *Type
, string
const &Section
, string
const &Arch
) const
28 string Info
= ::URI::SiteOnly(URI
) + ' ';
29 if (Dist
[Dist
.size() - 1] == '/')
36 Info
+= Dist
+ '/' + Section
;
37 if (Arch
.empty() != true)
45 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
47 string Info
= ::URI::SiteOnly(URI
) + ' ';
48 if (Dist
[Dist
.size() - 1] == '/')
60 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
62 return _config
->FindDir("Dir::State::lists") +
63 URItoFileName(MetaIndexURI(Type
));
66 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
72 else if (Dist
[Dist
.size()-1] == '/')
75 Res
= URI
+ "dists/" + Dist
+ "/";
81 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
82 std::string
debReleaseIndex::LocalFileName() const
84 // see if we have a InRelease file
85 std::string PathInRelease
= MetaIndexFile("InRelease");
86 if (FileExists(PathInRelease
))
89 // and if not return the normal one
90 if (FileExists(PathInRelease
))
91 return MetaIndexFile("Release");
97 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
100 if (Dist
[Dist
.size() - 1] != '/')
102 if (Arch
== "native")
103 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
105 Res
+= Section
+ "/binary-" + Arch
+ '/';
111 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
113 if (Dist
[Dist
.size() - 1] == '/')
123 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
126 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
129 if (Dist
[Dist
.size() - 1] != '/')
130 Res
+= Section
+ "/source/";
134 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
137 if (Dist
[Dist
.size() - 1] == '/')
146 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
149 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
152 if (Dist
[Dist
.size() - 1] != '/')
153 Res
+= Section
+ "/i18n/Translation-";
157 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
160 if (Dist
[Dist
.size() - 1] == '/')
169 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
172 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
173 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
176 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
177 metaIndex(URI
, Dist
, "deb") {
181 debReleaseIndex::~debReleaseIndex() {
182 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
183 A
!= ArchEntries
.end(); ++A
)
184 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
185 S
!= A
->second
.end(); ++S
)
189 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
190 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
192 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
193 if (src
!= ArchEntries
.end()) {
194 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
195 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
196 I
!= SectionEntries
.end(); ++I
) {
197 IndexTarget
* Target
= new IndexTarget();
198 Target
->ShortDesc
= "Sources";
199 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
200 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
201 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
202 IndexTargets
->push_back (Target
);
206 // Only source release
207 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
210 std::set
<std::string
> sections
;
211 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
212 a
!= ArchEntries
.end(); ++a
) {
213 if (a
->first
== "source")
215 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
216 I
!= a
->second
.end(); ++I
) {
217 IndexTarget
* Target
= new IndexTarget();
218 Target
->ShortDesc
= "Packages";
219 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
220 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
221 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
222 IndexTargets
->push_back (Target
);
223 sections
.insert((*I
)->Section
);
227 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
228 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
229 if (lend
!= lang
.end())
232 if (lang
.empty() == true)
235 // get the Translation-* files, later we will skip download of non-existent if we have an index
236 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
237 s
!= sections
.end(); ++s
) {
238 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
239 l
!= lang
.end(); ++l
) {
240 IndexTarget
* Target
= new OptionalIndexTarget();
241 Target
->ShortDesc
= "Translation-" + *l
;
242 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
243 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
244 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
245 IndexTargets
->push_back(Target
);
252 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
254 bool const tryInRelease
= _config
->FindB("Acquire::TryInRelease", true);
256 // special case for --print-uris
258 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
259 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
260 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
261 (*Target
)->ShortDesc
, HashString());
265 // this is normally created in pkgAcqMetaSig, but if we run
266 // in --print-uris mode, we add it here
267 if (tryInRelease
== false)
268 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
269 MetaIndexInfo("Release"), "Release",
270 MetaIndexURI("Release.gpg"),
271 ComputeIndexTargets(),
272 new indexRecords (Dist
));
275 if (tryInRelease
== true)
276 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
277 MetaIndexInfo("InRelease"), "InRelease",
278 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
279 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
280 ComputeIndexTargets(),
281 new indexRecords (Dist
));
283 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
284 MetaIndexInfo("Release.gpg"), "Release.gpg",
285 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
286 ComputeIndexTargets(),
287 new indexRecords (Dist
));
292 void debReleaseIndex::SetTrusted(bool const Trusted
)
295 this->Trusted
= ALWAYS_TRUSTED
;
297 this->Trusted
= NEVER_TRUSTED
;
300 bool debReleaseIndex::IsTrusted() const
302 if (Trusted
== ALWAYS_TRUSTED
)
304 else if (Trusted
== NEVER_TRUSTED
)
308 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
309 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
312 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
313 URItoFileName(MetaIndexURI("Release")) + ".gpg";
315 if (FileExists(VerifiedSigFile
))
318 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
319 URItoFileName(MetaIndexURI("InRelease"));
321 return FileExists(VerifiedSigFile
);
324 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
328 Indexes
= new vector
<pkgIndexFile
*>;
329 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
330 if (src
!= ArchEntries
.end()) {
331 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
332 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
333 I
!= SectionEntries
.end(); ++I
)
334 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
337 // Only source release
338 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
341 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
342 map
<string
, set
<string
> > sections
;
343 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
344 a
!= ArchEntries
.end(); ++a
) {
345 if (a
->first
== "source")
347 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
348 I
!= a
->second
.end(); ++I
) {
349 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
350 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
354 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
355 s
!= sections
.end(); ++s
)
356 for (set
<string
>::const_iterator l
= s
->second
.begin();
357 l
!= s
->second
.end(); ++l
) {
358 if (*l
== "none") continue;
359 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
365 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
366 for (vector
<string
>::const_iterator a
= Archs
.begin();
367 a
!= Archs
.end(); ++a
)
368 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
372 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
373 ArchEntries
[Arch
].push_back(Entry
);
376 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
377 if (Entry
->IsSrc
== true)
378 PushSectionEntry("source", Entry
);
380 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
381 a
!= ArchEntries
.end(); ++a
) {
382 a
->second
.push_back(Entry
);
387 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
388 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
391 class debSLTypeDebian
: public pkgSourceList::Type
395 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
396 string
const &Dist
, string
const &Section
,
397 bool const &IsSrc
, map
<string
, string
> const &Options
) const
399 // parse arch=, arch+= and arch-= settings
400 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
401 vector
<string
> Archs
=
402 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
403 APT::Configuration::getArchitectures();
404 if ((arch
= Options
.find("arch+")) != Options
.end())
406 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
407 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
408 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
409 Archs
.push_back(*plus
);
411 if ((arch
= Options
.find("arch-")) != Options
.end())
413 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
414 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
416 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
417 if (kill
!= Archs
.end())
422 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
424 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
425 I
!= List
.end(); ++I
)
427 // We only worry about debian entries here
428 if (strcmp((*I
)->GetType(), "deb") != 0)
431 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
432 if (trusted
!= Options
.end())
433 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
435 /* This check insures that there will be only one Release file
436 queued for all the Packages files and Sources files it
438 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
441 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
444 if (Dist
[Dist
.size() - 1] == '/')
445 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
447 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
453 // No currently created Release file indexes this entry, so we create a new one.
454 debReleaseIndex
*Deb
;
455 if (trusted
!= Options
.end())
456 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
458 Deb
= new debReleaseIndex(URI
, Dist
);
461 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
464 if (Dist
[Dist
.size() - 1] == '/')
465 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
467 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
474 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
)
475 : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
)
477 DebIndex
= new debDebPkgFileIndex(DebFile
);
478 Indexes
= new vector
<pkgIndexFile
*>();
479 Indexes
->push_back(DebIndex
);
483 class debSLTypeDeb
: public debSLTypeDebian
487 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
488 string
const &Dist
, string
const &Section
,
489 std::map
<string
, string
> const &Options
) const
491 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
497 Label
= "Standard Debian binary tree";
501 class debSLTypeDebSrc
: public debSLTypeDebian
505 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
506 string
const &Dist
, string
const &Section
,
507 std::map
<string
, string
> const &Options
) const
509 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
515 Label
= "Standard Debian source tree";
519 class debSLTypeDebFile
: public pkgSourceList::Type
523 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
524 string
const &Dist
, string
const &Section
,
525 std::map
<string
, string
> const &Options
) const
527 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
535 Label
= "Debian Deb File";
538 debSLTypeDeb _apt_DebType
;
539 debSLTypeDebSrc _apt_DebSrcType
;
540 debSLTypeDebFile _apt_DebFileType
;