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 std::string
debReleaseIndex::LocalFileName() const
83 // see if we have a InRelease file
84 std::string PathInRelease
= MetaIndexFile("InRelease");
85 if (FileExists(PathInRelease
))
88 // and if not return the normal one
89 if (FileExists(PathInRelease
))
90 return MetaIndexFile("Release");
95 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
98 if (Dist
[Dist
.size() - 1] != '/')
100 if (Arch
== "native")
101 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
103 Res
+= Section
+ "/binary-" + Arch
+ '/';
109 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
111 if (Dist
[Dist
.size() - 1] == '/')
121 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
124 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
127 if (Dist
[Dist
.size() - 1] != '/')
128 Res
+= Section
+ "/source/";
132 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
135 if (Dist
[Dist
.size() - 1] == '/')
144 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
147 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
150 if (Dist
[Dist
.size() - 1] != '/')
151 Res
+= Section
+ "/i18n/Translation-";
155 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
158 if (Dist
[Dist
.size() - 1] == '/')
167 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
170 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
171 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
174 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
175 metaIndex(URI
, Dist
, "deb") {
179 debReleaseIndex::~debReleaseIndex() {
180 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
181 A
!= ArchEntries
.end(); ++A
)
182 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
183 S
!= A
->second
.end(); ++S
)
187 vector
<IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
188 vector
<IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
190 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
191 if (src
!= ArchEntries
.end()) {
192 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
193 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
194 I
!= SectionEntries
.end(); ++I
) {
195 IndexTarget
* Target
= new IndexTarget();
196 Target
->ShortDesc
= "Sources";
197 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
198 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
199 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
200 IndexTargets
->push_back (Target
);
204 // Only source release
205 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
208 std::set
<std::string
> sections
;
209 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
210 a
!= ArchEntries
.end(); ++a
) {
211 if (a
->first
== "source")
213 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
214 I
!= a
->second
.end(); ++I
) {
215 IndexTarget
* Target
= new IndexTarget();
216 Target
->ShortDesc
= "Packages";
217 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
218 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
219 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
220 IndexTargets
->push_back (Target
);
221 sections
.insert((*I
)->Section
);
225 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
226 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
227 if (lend
!= lang
.end())
230 if (lang
.empty() == true)
233 // get the Translation-* files, later we will skip download of non-existent if we have an index
234 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
235 s
!= sections
.end(); ++s
) {
236 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
237 l
!= lang
.end(); ++l
) {
238 IndexTarget
* Target
= new OptionalIndexTarget();
239 Target
->ShortDesc
= "Translation-" + *l
;
240 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
241 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
242 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
243 IndexTargets
->push_back(Target
);
250 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
252 bool const tryInRelease
= _config
->FindB("Acquire::TryInRelease", true);
254 indexRecords
* const iR
= new indexRecords(Dist
);
255 if (Trusted
== ALWAYS_TRUSTED
)
256 iR
->SetTrusted(true);
257 else if (Trusted
== NEVER_TRUSTED
)
258 iR
->SetTrusted(false);
260 // special case for --print-uris
262 vector
<IndexTarget
*> *targets
= ComputeIndexTargets();
263 for (vector
<IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
264 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
265 (*Target
)->ShortDesc
, HashStringList());
269 // this is normally created in pkgAcqMetaSig, but if we run
270 // in --print-uris mode, we add it here
271 if (tryInRelease
== false)
272 new pkgAcqMetaIndex(Owner
, NULL
,
273 MetaIndexURI("Release"),
274 MetaIndexInfo("Release"), "Release",
275 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
276 ComputeIndexTargets(),
279 if (tryInRelease
== true)
280 new pkgAcqMetaClearSig(Owner
,
281 MetaIndexURI("InRelease"), MetaIndexInfo("InRelease"), "InRelease",
282 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
283 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
284 ComputeIndexTargets(),
287 new pkgAcqMetaIndex(Owner
, NULL
,
288 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
289 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
290 ComputeIndexTargets(),
296 void debReleaseIndex::SetTrusted(bool const Trusted
)
299 this->Trusted
= ALWAYS_TRUSTED
;
301 this->Trusted
= NEVER_TRUSTED
;
304 bool debReleaseIndex::IsTrusted() const
306 if (Trusted
== ALWAYS_TRUSTED
)
308 else if (Trusted
== NEVER_TRUSTED
)
312 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
313 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
316 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
317 URItoFileName(MetaIndexURI("Release")) + ".gpg";
319 if (FileExists(VerifiedSigFile
))
322 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
323 URItoFileName(MetaIndexURI("InRelease"));
325 return FileExists(VerifiedSigFile
);
328 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
332 Indexes
= new vector
<pkgIndexFile
*>;
333 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
334 if (src
!= ArchEntries
.end()) {
335 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
336 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
337 I
!= SectionEntries
.end(); ++I
)
338 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
341 // Only source release
342 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
345 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
346 map
<string
, set
<string
> > sections
;
347 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
348 a
!= ArchEntries
.end(); ++a
) {
349 if (a
->first
== "source")
351 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
352 I
!= a
->second
.end(); ++I
) {
353 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
354 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
358 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
359 s
!= sections
.end(); ++s
)
360 for (set
<string
>::const_iterator l
= s
->second
.begin();
361 l
!= s
->second
.end(); ++l
) {
362 if (*l
== "none") continue;
363 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
369 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
370 for (vector
<string
>::const_iterator a
= Archs
.begin();
371 a
!= Archs
.end(); ++a
)
372 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
376 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
377 ArchEntries
[Arch
].push_back(Entry
);
380 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
381 if (Entry
->IsSrc
== true)
382 PushSectionEntry("source", Entry
);
384 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
385 a
!= ArchEntries
.end(); ++a
) {
386 a
->second
.push_back(Entry
);
391 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
392 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
395 class debSLTypeDebian
: public pkgSourceList::Type
399 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
400 string
const &Dist
, string
const &Section
,
401 bool const &IsSrc
, map
<string
, string
> const &Options
) const
403 // parse arch=, arch+= and arch-= settings
404 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
405 vector
<string
> Archs
=
406 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
407 APT::Configuration::getArchitectures();
408 if ((arch
= Options
.find("arch+")) != Options
.end())
410 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
411 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
412 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
413 Archs
.push_back(*plus
);
415 if ((arch
= Options
.find("arch-")) != Options
.end())
417 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
418 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
420 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
421 if (kill
!= Archs
.end())
426 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
428 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
429 I
!= List
.end(); ++I
)
431 // We only worry about debian entries here
432 if (strcmp((*I
)->GetType(), "deb") != 0)
435 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
436 if (trusted
!= Options
.end())
437 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
439 /* This check insures that there will be only one Release file
440 queued for all the Packages files and Sources files it
442 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
445 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
448 if (Dist
[Dist
.size() - 1] == '/')
449 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
451 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
457 // No currently created Release file indexes this entry, so we create a new one.
458 debReleaseIndex
*Deb
;
459 if (trusted
!= Options
.end())
460 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
462 Deb
= new debReleaseIndex(URI
, Dist
);
465 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
468 if (Dist
[Dist
.size() - 1] == '/')
469 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
471 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
478 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
)
479 : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
)
481 DebIndex
= new debDebPkgFileIndex(DebFile
);
482 Indexes
= new vector
<pkgIndexFile
*>();
483 Indexes
->push_back(DebIndex
);
487 class debSLTypeDeb
: public debSLTypeDebian
491 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
492 string
const &Dist
, string
const &Section
,
493 std::map
<string
, string
> const &Options
) const
495 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
501 Label
= "Standard Debian binary tree";
505 class debSLTypeDebSrc
: public debSLTypeDebian
509 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
510 string
const &Dist
, string
const &Section
,
511 std::map
<string
, string
> const &Options
) const
513 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
519 Label
= "Standard Debian source tree";
523 class debSLTypeDebFile
: public pkgSourceList::Type
527 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
528 string
const &/*Dist*/, string
const &/*Section*/,
529 std::map
<string
, string
> const &/*Options*/) const
531 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
539 Label
= "Debian Deb File";
542 debSLTypeDeb _apt_DebType
;
543 debSLTypeDebSrc _apt_DebSrcType
;
544 debSLTypeDebFile _apt_DebFileType
;