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/error.h>
19 string
debReleaseIndex::Info(const char *Type
, string
const &Section
, string
const &Arch
) const
21 string Info
= ::URI::SiteOnly(URI
) + ' ';
22 if (Dist
[Dist
.size() - 1] == '/')
29 Info
+= Dist
+ '/' + Section
;
30 if (Arch
.empty() != true)
38 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
40 string Info
= ::URI::SiteOnly(URI
) + ' ';
41 if (Dist
[Dist
.size() - 1] == '/')
53 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
55 return _config
->FindDir("Dir::State::lists") +
56 URItoFileName(MetaIndexURI(Type
));
59 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
65 else if (Dist
[Dist
.size()-1] == '/')
68 Res
= URI
+ "dists/" + Dist
+ "/";
74 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
75 std::string
debReleaseIndex::LocalFileName() const
77 // see if we have a InRelease file
78 std::string PathInRelease
= MetaIndexFile("InRelease");
79 if (FileExists(PathInRelease
))
82 // and if not return the normal one
83 if (FileExists(PathInRelease
))
84 return MetaIndexFile("Release");
90 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
93 if (Dist
[Dist
.size() - 1] != '/')
96 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
98 Res
+= Section
+ "/binary-" + Arch
+ '/';
104 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
106 if (Dist
[Dist
.size() - 1] == '/')
116 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
119 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
122 if (Dist
[Dist
.size() - 1] != '/')
123 Res
+= Section
+ "/source/";
127 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
130 if (Dist
[Dist
.size() - 1] == '/')
139 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
142 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
145 if (Dist
[Dist
.size() - 1] != '/')
146 Res
+= Section
+ "/i18n/Translation-";
150 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
153 if (Dist
[Dist
.size() - 1] == '/')
162 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
165 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
166 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
169 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
170 metaIndex(URI
, Dist
, "deb") {
174 debReleaseIndex::~debReleaseIndex() {
175 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
176 A
!= ArchEntries
.end(); ++A
)
177 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
178 S
!= A
->second
.end(); ++S
)
182 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
183 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
185 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
186 if (src
!= ArchEntries
.end()) {
187 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
188 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
189 I
!= SectionEntries
.end(); ++I
) {
190 IndexTarget
* Target
= new IndexTarget();
191 Target
->ShortDesc
= "Sources";
192 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
193 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
194 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
195 IndexTargets
->push_back (Target
);
199 // Only source release
200 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
203 std::set
<std::string
> sections
;
204 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
205 a
!= ArchEntries
.end(); ++a
) {
206 if (a
->first
== "source")
208 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
209 I
!= a
->second
.end(); ++I
) {
210 IndexTarget
* Target
= new IndexTarget();
211 Target
->ShortDesc
= "Packages";
212 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
213 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
214 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
215 IndexTargets
->push_back (Target
);
216 sections
.insert((*I
)->Section
);
220 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
221 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
222 if (lend
!= lang
.end())
225 if (lang
.empty() == true)
228 // get the Translation-* files, later we will skip download of non-existent if we have an index
229 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
230 s
!= sections
.end(); ++s
) {
231 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
232 l
!= lang
.end(); ++l
) {
233 IndexTarget
* Target
= new OptionalIndexTarget();
234 Target
->ShortDesc
= "Translation-" + *l
;
235 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
236 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
237 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
238 IndexTargets
->push_back(Target
);
245 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
247 bool const tryInRelease
= _config
->FindB("Acquire::TryInRelease", true);
249 // special case for --print-uris
251 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
252 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
253 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
254 (*Target
)->ShortDesc
, HashString());
258 // this is normally created in pkgAcqMetaSig, but if we run
259 // in --print-uris mode, we add it here
260 if (tryInRelease
== false)
261 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
262 MetaIndexInfo("Release"), "Release",
263 MetaIndexURI("Release.gpg"),
264 ComputeIndexTargets(),
265 new indexRecords (Dist
));
268 if (tryInRelease
== true)
269 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
270 MetaIndexInfo("InRelease"), "InRelease",
271 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
272 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
273 ComputeIndexTargets(),
274 new indexRecords (Dist
));
276 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
277 MetaIndexInfo("Release.gpg"), "Release.gpg",
278 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
279 ComputeIndexTargets(),
280 new indexRecords (Dist
));
285 void debReleaseIndex::SetTrusted(bool const Trusted
)
288 this->Trusted
= ALWAYS_TRUSTED
;
290 this->Trusted
= NEVER_TRUSTED
;
293 bool debReleaseIndex::IsTrusted() const
295 if (Trusted
== ALWAYS_TRUSTED
)
297 else if (Trusted
== NEVER_TRUSTED
)
301 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
302 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
305 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
306 URItoFileName(MetaIndexURI("Release")) + ".gpg";
308 if (FileExists(VerifiedSigFile
))
311 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
312 URItoFileName(MetaIndexURI("InRelease"));
314 return FileExists(VerifiedSigFile
);
317 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
321 Indexes
= new vector
<pkgIndexFile
*>;
322 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
323 if (src
!= ArchEntries
.end()) {
324 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
325 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
326 I
!= SectionEntries
.end(); ++I
)
327 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
330 // Only source release
331 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
334 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
335 map
<string
, set
<string
> > sections
;
336 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
337 a
!= ArchEntries
.end(); ++a
) {
338 if (a
->first
== "source")
340 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
341 I
!= a
->second
.end(); ++I
) {
342 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
343 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
347 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
348 s
!= sections
.end(); ++s
)
349 for (set
<string
>::const_iterator l
= s
->second
.begin();
350 l
!= s
->second
.end(); ++l
) {
351 if (*l
== "none") continue;
352 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
358 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
359 for (vector
<string
>::const_iterator a
= Archs
.begin();
360 a
!= Archs
.end(); ++a
)
361 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
365 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
366 ArchEntries
[Arch
].push_back(Entry
);
369 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
370 if (Entry
->IsSrc
== true)
371 PushSectionEntry("source", Entry
);
373 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
374 a
!= ArchEntries
.end(); ++a
) {
375 a
->second
.push_back(Entry
);
380 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
381 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
384 class debSLTypeDebian
: public pkgSourceList::Type
388 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
389 string
const &Dist
, string
const &Section
,
390 bool const &IsSrc
, map
<string
, string
> const &Options
) const
392 // parse arch=, arch+= and arch-= settings
393 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
394 vector
<string
> Archs
=
395 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
396 APT::Configuration::getArchitectures();
397 if ((arch
= Options
.find("arch+")) != Options
.end())
399 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
400 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
401 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
402 Archs
.push_back(*plus
);
404 if ((arch
= Options
.find("arch-")) != Options
.end())
406 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
407 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
409 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
410 if (kill
!= Archs
.end())
415 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
417 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
418 I
!= List
.end(); ++I
)
420 // We only worry about debian entries here
421 if (strcmp((*I
)->GetType(), "deb") != 0)
424 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
425 if (trusted
!= Options
.end())
426 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
428 /* This check insures that there will be only one Release file
429 queued for all the Packages files and Sources files it
431 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
434 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
437 if (Dist
[Dist
.size() - 1] == '/')
438 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
440 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
446 // No currently created Release file indexes this entry, so we create a new one.
447 debReleaseIndex
*Deb
;
448 if (trusted
!= Options
.end())
449 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
451 Deb
= new debReleaseIndex(URI
, Dist
);
454 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
457 if (Dist
[Dist
.size() - 1] == '/')
458 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
460 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
467 class debSLTypeDeb
: public debSLTypeDebian
471 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
472 string
const &Dist
, string
const &Section
,
473 std::map
<string
, string
> const &Options
) const
475 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
481 Label
= "Standard Debian binary tree";
485 class debSLTypeDebSrc
: public debSLTypeDebian
489 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
490 string
const &Dist
, string
const &Section
,
491 std::map
<string
, string
> const &Options
) const
493 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
499 Label
= "Standard Debian source tree";
503 debSLTypeDeb _apt_DebType
;
504 debSLTypeDebSrc _apt_DebSrcType
;