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
<IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
190 vector
<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
<IndexTarget
*> *targets
= ComputeIndexTargets();
259 for (vector
<IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
260 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
261 (*Target
)->ShortDesc
, HashStringList());
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
, 0,
269 MetaIndexURI("Release"),
270 MetaIndexInfo("Release"), "Release",
271 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
272 ComputeIndexTargets(),
273 new indexRecords (Dist
));
276 if (tryInRelease
== true)
277 new pkgAcqMetaClearSig(Owner
,
278 MetaIndexURI("InRelease"), MetaIndexInfo("InRelease"), "InRelease",
279 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
280 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
281 ComputeIndexTargets(),
282 new indexRecords (Dist
));
284 new pkgAcqMetaIndex(Owner
, 0,
285 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
286 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
287 ComputeIndexTargets(),
288 new indexRecords (Dist
));
293 void debReleaseIndex::SetTrusted(bool const Trusted
)
296 this->Trusted
= ALWAYS_TRUSTED
;
298 this->Trusted
= NEVER_TRUSTED
;
301 bool debReleaseIndex::IsTrusted() const
303 if (Trusted
== ALWAYS_TRUSTED
)
305 else if (Trusted
== NEVER_TRUSTED
)
309 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
310 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
313 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
314 URItoFileName(MetaIndexURI("Release")) + ".gpg";
316 if (FileExists(VerifiedSigFile
))
319 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
320 URItoFileName(MetaIndexURI("InRelease"));
322 return FileExists(VerifiedSigFile
);
325 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
329 Indexes
= new vector
<pkgIndexFile
*>;
330 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
331 if (src
!= ArchEntries
.end()) {
332 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
333 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
334 I
!= SectionEntries
.end(); ++I
)
335 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
338 // Only source release
339 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
342 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
343 map
<string
, set
<string
> > sections
;
344 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
345 a
!= ArchEntries
.end(); ++a
) {
346 if (a
->first
== "source")
348 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
349 I
!= a
->second
.end(); ++I
) {
350 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
351 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
355 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
356 s
!= sections
.end(); ++s
)
357 for (set
<string
>::const_iterator l
= s
->second
.begin();
358 l
!= s
->second
.end(); ++l
) {
359 if (*l
== "none") continue;
360 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
366 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
367 for (vector
<string
>::const_iterator a
= Archs
.begin();
368 a
!= Archs
.end(); ++a
)
369 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
373 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
374 ArchEntries
[Arch
].push_back(Entry
);
377 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
378 if (Entry
->IsSrc
== true)
379 PushSectionEntry("source", Entry
);
381 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
382 a
!= ArchEntries
.end(); ++a
) {
383 a
->second
.push_back(Entry
);
388 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
389 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
392 class debSLTypeDebian
: public pkgSourceList::Type
396 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
397 string
const &Dist
, string
const &Section
,
398 bool const &IsSrc
, map
<string
, string
> const &Options
) const
400 // parse arch=, arch+= and arch-= settings
401 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
402 vector
<string
> Archs
=
403 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
404 APT::Configuration::getArchitectures();
405 if ((arch
= Options
.find("arch+")) != Options
.end())
407 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
408 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
409 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
410 Archs
.push_back(*plus
);
412 if ((arch
= Options
.find("arch-")) != Options
.end())
414 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
415 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
417 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
418 if (kill
!= Archs
.end())
423 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
425 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
426 I
!= List
.end(); ++I
)
428 // We only worry about debian entries here
429 if (strcmp((*I
)->GetType(), "deb") != 0)
432 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
433 if (trusted
!= Options
.end())
434 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
436 /* This check insures that there will be only one Release file
437 queued for all the Packages files and Sources files it
439 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
442 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
445 if (Dist
[Dist
.size() - 1] == '/')
446 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
448 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
454 // No currently created Release file indexes this entry, so we create a new one.
455 debReleaseIndex
*Deb
;
456 if (trusted
!= Options
.end())
457 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
459 Deb
= new debReleaseIndex(URI
, Dist
);
462 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
465 if (Dist
[Dist
.size() - 1] == '/')
466 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
468 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
475 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
)
476 : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
)
478 DebIndex
= new debDebPkgFileIndex(DebFile
);
479 Indexes
= new vector
<pkgIndexFile
*>();
480 Indexes
->push_back(DebIndex
);
484 class debSLTypeDeb
: public debSLTypeDebian
488 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
489 string
const &Dist
, string
const &Section
,
490 std::map
<string
, string
> const &Options
) const
492 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
498 Label
= "Standard Debian binary tree";
502 class debSLTypeDebSrc
: public debSLTypeDebian
506 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
507 string
const &Dist
, string
const &Section
,
508 std::map
<string
, string
> const &Options
) const
510 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
516 Label
= "Standard Debian source tree";
520 class debSLTypeDebFile
: public pkgSourceList::Type
524 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
525 string
const &/*Dist*/, string
const &/*Section*/,
526 std::map
<string
, string
> const &/*Options*/) const
528 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
536 Label
= "Debian Deb File";
539 debSLTypeDeb _apt_DebType
;
540 debSLTypeDebSrc _apt_DebSrcType
;
541 debSLTypeDebFile _apt_DebFileType
;