4 #include <apt-pkg/debmetaindex.h>
5 #include <apt-pkg/debindexfile.h>
6 #include <apt-pkg/strutl.h>
7 #include <apt-pkg/fileutl.h>
8 #include <apt-pkg/acquire-item.h>
9 #include <apt-pkg/configuration.h>
10 #include <apt-pkg/aptconfiguration.h>
11 #include <apt-pkg/indexrecords.h>
12 #include <apt-pkg/sourcelist.h>
13 #include <apt-pkg/error.h>
20 string
debReleaseIndex::Info(const char *Type
, string
const &Section
, string
const &Arch
) const
22 string Info
= ::URI::SiteOnly(URI
) + ' ';
23 if (Dist
[Dist
.size() - 1] == '/')
30 Info
+= Dist
+ '/' + Section
;
31 if (Arch
.empty() != true)
39 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
41 string Info
= ::URI::SiteOnly(URI
) + ' ';
42 if (Dist
[Dist
.size() - 1] == '/')
54 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
56 return _config
->FindDir("Dir::State::lists") +
57 URItoFileName(MetaIndexURI(Type
));
60 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
66 else if (Dist
[Dist
.size()-1] == '/')
69 Res
= URI
+ "dists/" + Dist
+ "/";
75 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
78 if (Dist
[Dist
.size() - 1] != '/')
81 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
83 Res
+= Section
+ "/binary-" + Arch
+ '/';
89 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
91 if (Dist
[Dist
.size() - 1] == '/')
101 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
104 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
107 if (Dist
[Dist
.size() - 1] != '/')
108 Res
+= Section
+ "/source/";
112 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
115 if (Dist
[Dist
.size() - 1] == '/')
124 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
127 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
130 if (Dist
[Dist
.size() - 1] != '/')
131 Res
+= Section
+ "/i18n/Translation-";
135 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
138 if (Dist
[Dist
.size() - 1] == '/')
147 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
150 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
151 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
154 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
155 metaIndex(URI
, Dist
, "deb") {
159 debReleaseIndex::~debReleaseIndex() {
160 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
161 A
!= ArchEntries
.end(); ++A
)
162 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
163 S
!= A
->second
.end(); ++S
)
167 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
168 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
170 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
171 if (src
!= ArchEntries
.end()) {
172 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
173 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
174 I
!= SectionEntries
.end(); ++I
) {
175 IndexTarget
* Target
= new IndexTarget();
176 Target
->ShortDesc
= "Sources";
177 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
178 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
179 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
180 IndexTargets
->push_back (Target
);
184 // Only source release
185 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
188 std::set
<std::string
> sections
;
189 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
190 a
!= ArchEntries
.end(); ++a
) {
191 if (a
->first
== "source")
193 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
194 I
!= a
->second
.end(); ++I
) {
195 IndexTarget
* Target
= new IndexTarget();
196 Target
->ShortDesc
= "Packages";
197 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
198 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
199 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
200 IndexTargets
->push_back (Target
);
201 sections
.insert((*I
)->Section
);
205 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
206 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
207 if (lend
!= lang
.end())
210 if (lang
.empty() == true)
213 // get the Translation-* files, later we will skip download of non-existent if we have an index
214 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
215 s
!= sections
.end(); ++s
) {
216 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
217 l
!= lang
.end(); ++l
) {
218 IndexTarget
* Target
= new OptionalIndexTarget();
219 Target
->ShortDesc
= "Translation-" + *l
;
220 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
221 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
222 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
223 IndexTargets
->push_back(Target
);
230 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
232 bool const tryInRelease
= _config
->FindB("Acquire::TryInRelease", true);
234 // special case for --print-uris
236 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
237 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
238 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
239 (*Target
)->ShortDesc
, HashString());
243 // this is normally created in pkgAcqMetaSig, but if we run
244 // in --print-uris mode, we add it here
245 if (tryInRelease
== false)
246 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
247 MetaIndexInfo("Release"), "Release",
248 MetaIndexURI("Release.gpg"),
249 ComputeIndexTargets(),
250 new indexRecords (Dist
));
253 if (tryInRelease
== true)
254 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
255 MetaIndexInfo("InRelease"), "InRelease",
256 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
257 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
258 ComputeIndexTargets(),
259 new indexRecords (Dist
));
261 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
262 MetaIndexInfo("Release.gpg"), "Release.gpg",
263 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
264 ComputeIndexTargets(),
265 new indexRecords (Dist
));
270 void debReleaseIndex::SetTrusted(bool const Trusted
)
273 this->Trusted
= ALWAYS_TRUSTED
;
275 this->Trusted
= NEVER_TRUSTED
;
278 bool debReleaseIndex::IsTrusted() const
280 if (Trusted
== ALWAYS_TRUSTED
)
282 else if (Trusted
== NEVER_TRUSTED
)
286 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
287 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
290 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
291 URItoFileName(MetaIndexURI("Release")) + ".gpg";
293 if (FileExists(VerifiedSigFile
))
296 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
297 URItoFileName(MetaIndexURI("InRelease"));
299 return FileExists(VerifiedSigFile
);
302 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
306 Indexes
= new vector
<pkgIndexFile
*>;
307 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
308 if (src
!= ArchEntries
.end()) {
309 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
310 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
311 I
!= SectionEntries
.end(); ++I
)
312 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
315 // Only source release
316 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
319 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
320 map
<string
, set
<string
> > sections
;
321 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
322 a
!= ArchEntries
.end(); ++a
) {
323 if (a
->first
== "source")
325 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
326 I
!= a
->second
.end(); ++I
) {
327 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
328 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
332 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
333 s
!= sections
.end(); ++s
)
334 for (set
<string
>::const_iterator l
= s
->second
.begin();
335 l
!= s
->second
.end(); ++l
) {
336 if (*l
== "none") continue;
337 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
343 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
344 for (vector
<string
>::const_iterator a
= Archs
.begin();
345 a
!= Archs
.end(); ++a
)
346 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
350 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
351 ArchEntries
[Arch
].push_back(Entry
);
354 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
355 if (Entry
->IsSrc
== true)
356 PushSectionEntry("source", Entry
);
358 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
359 a
!= ArchEntries
.end(); ++a
) {
360 a
->second
.push_back(Entry
);
365 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
366 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
369 class debSLTypeDebian
: public pkgSourceList::Type
373 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
374 string
const &Dist
, string
const &Section
,
375 bool const &IsSrc
, map
<string
, string
> const &Options
) const
377 // parse arch=, arch+= and arch-= settings
378 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
379 vector
<string
> Archs
=
380 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
381 APT::Configuration::getArchitectures();
382 if ((arch
= Options
.find("arch+")) != Options
.end())
384 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
385 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
386 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
387 Archs
.push_back(*plus
);
389 if ((arch
= Options
.find("arch-")) != Options
.end())
391 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
392 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
394 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
395 if (kill
!= Archs
.end())
400 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
402 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
403 I
!= List
.end(); ++I
)
405 // We only worry about debian entries here
406 if (strcmp((*I
)->GetType(), "deb") != 0)
409 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
410 if (trusted
!= Options
.end())
411 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
413 /* This check insures that there will be only one Release file
414 queued for all the Packages files and Sources files it
416 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
419 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
422 if (Dist
[Dist
.size() - 1] == '/')
423 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
425 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
431 // No currently created Release file indexes this entry, so we create a new one.
432 debReleaseIndex
*Deb
;
433 if (trusted
!= Options
.end())
434 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
436 Deb
= new debReleaseIndex(URI
, Dist
);
439 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
442 if (Dist
[Dist
.size() - 1] == '/')
443 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
445 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
452 class debSLTypeDeb
: public debSLTypeDebian
456 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
457 string
const &Dist
, string
const &Section
,
458 std::map
<string
, string
> const &Options
) const
460 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
466 Label
= "Standard Debian binary tree";
470 class debSLTypeDebSrc
: public debSLTypeDebian
474 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
475 string
const &Dist
, string
const &Section
,
476 std::map
<string
, string
> const &Options
) const
478 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
484 Label
= "Standard Debian source tree";
488 debSLTypeDeb _apt_DebType
;
489 debSLTypeDebSrc _apt_DebSrcType
;