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 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR < 13)
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
+ "/";
76 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
79 if (Dist
[Dist
.size() - 1] != '/')
82 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
84 Res
+= Section
+ "/binary-" + Arch
+ '/';
90 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
92 if (Dist
[Dist
.size() - 1] == '/')
102 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
105 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
108 if (Dist
[Dist
.size() - 1] != '/')
109 Res
+= Section
+ "/source/";
113 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
116 if (Dist
[Dist
.size() - 1] == '/')
125 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
128 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
131 if (Dist
[Dist
.size() - 1] != '/')
132 Res
+= Section
+ "/i18n/Translation-";
136 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
139 if (Dist
[Dist
.size() - 1] == '/')
148 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
151 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
152 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
155 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
156 metaIndex(URI
, Dist
, "deb") {
160 debReleaseIndex::~debReleaseIndex() {
161 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
162 A
!= ArchEntries
.end(); ++A
)
163 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
164 S
!= A
->second
.end(); ++S
)
168 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
169 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
171 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
172 if (src
!= ArchEntries
.end()) {
173 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
174 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
175 I
!= SectionEntries
.end(); ++I
) {
176 IndexTarget
* Target
= new IndexTarget();
177 Target
->ShortDesc
= "Sources";
178 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
179 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
180 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
181 IndexTargets
->push_back (Target
);
185 // Only source release
186 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
189 std::set
<std::string
> sections
;
190 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
191 a
!= ArchEntries
.end(); ++a
) {
192 if (a
->first
== "source")
194 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
195 I
!= a
->second
.end(); ++I
) {
196 IndexTarget
* Target
= new IndexTarget();
197 Target
->ShortDesc
= "Packages";
198 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
199 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
200 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
201 IndexTargets
->push_back (Target
);
202 sections
.insert((*I
)->Section
);
206 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
207 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
208 if (lend
!= lang
.end())
211 if (lang
.empty() == true)
214 // get the Translation-* files, later we will skip download of non-existent if we have an index
215 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
216 s
!= sections
.end(); ++s
) {
217 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
218 l
!= lang
.end(); ++l
) {
219 IndexTarget
* Target
= new OptionalIndexTarget();
220 Target
->ShortDesc
= "Translation-" + *l
;
221 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
222 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
223 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
224 IndexTargets
->push_back(Target
);
231 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
233 bool const tryInRelease
= _config
->FindB("Acquire::TryInRelease", true);
235 // special case for --print-uris
237 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
238 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
239 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
240 (*Target
)->ShortDesc
, HashString());
244 // this is normally created in pkgAcqMetaSig, but if we run
245 // in --print-uris mode, we add it here
246 if (tryInRelease
== false)
247 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
248 MetaIndexInfo("Release"), "Release",
249 MetaIndexURI("Release.gpg"),
250 ComputeIndexTargets(),
251 new indexRecords (Dist
));
254 if (tryInRelease
== true)
255 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
256 MetaIndexInfo("InRelease"), "InRelease",
257 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
258 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
259 ComputeIndexTargets(),
260 new indexRecords (Dist
));
262 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
263 MetaIndexInfo("Release.gpg"), "Release.gpg",
264 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
265 ComputeIndexTargets(),
266 new indexRecords (Dist
));
271 void debReleaseIndex::SetTrusted(bool const Trusted
)
274 this->Trusted
= ALWAYS_TRUSTED
;
276 this->Trusted
= NEVER_TRUSTED
;
279 bool debReleaseIndex::IsTrusted() const
281 if (Trusted
== ALWAYS_TRUSTED
)
283 else if (Trusted
== NEVER_TRUSTED
)
287 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
288 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
291 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
292 URItoFileName(MetaIndexURI("Release")) + ".gpg";
294 if (FileExists(VerifiedSigFile
))
297 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
298 URItoFileName(MetaIndexURI("InRelease"));
300 return FileExists(VerifiedSigFile
);
303 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
307 Indexes
= new vector
<pkgIndexFile
*>;
308 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
309 if (src
!= ArchEntries
.end()) {
310 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
311 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
312 I
!= SectionEntries
.end(); ++I
)
313 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
316 // Only source release
317 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
320 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
321 map
<string
, set
<string
> > sections
;
322 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
323 a
!= ArchEntries
.end(); ++a
) {
324 if (a
->first
== "source")
326 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
327 I
!= a
->second
.end(); ++I
) {
328 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
329 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
333 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
334 s
!= sections
.end(); ++s
)
335 for (set
<string
>::const_iterator l
= s
->second
.begin();
336 l
!= s
->second
.end(); ++l
) {
337 if (*l
== "none") continue;
338 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
344 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
345 for (vector
<string
>::const_iterator a
= Archs
.begin();
346 a
!= Archs
.end(); ++a
)
347 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
351 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
352 ArchEntries
[Arch
].push_back(Entry
);
355 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
356 if (Entry
->IsSrc
== true)
357 PushSectionEntry("source", Entry
);
359 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
360 a
!= ArchEntries
.end(); ++a
) {
361 a
->second
.push_back(Entry
);
366 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
367 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
370 class debSLTypeDebian
: public pkgSourceList::Type
374 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
375 string
const &Dist
, string
const &Section
,
376 bool const &IsSrc
, map
<string
, string
> const &Options
) const
378 // parse arch=, arch+= and arch-= settings
379 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
380 vector
<string
> Archs
=
381 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
382 APT::Configuration::getArchitectures();
383 if ((arch
= Options
.find("arch+")) != Options
.end())
385 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
386 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
387 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
388 Archs
.push_back(*plus
);
390 if ((arch
= Options
.find("arch-")) != Options
.end())
392 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
393 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
395 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
396 if (kill
!= Archs
.end())
401 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
403 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
404 I
!= List
.end(); ++I
)
406 // We only worry about debian entries here
407 if (strcmp((*I
)->GetType(), "deb") != 0)
410 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
411 if (trusted
!= Options
.end())
412 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
414 /* This check insures that there will be only one Release file
415 queued for all the Packages files and Sources files it
417 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
420 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
423 if (Dist
[Dist
.size() - 1] == '/')
424 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
426 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
432 // No currently created Release file indexes this entry, so we create a new one.
433 debReleaseIndex
*Deb
;
434 if (trusted
!= Options
.end())
435 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
437 Deb
= new debReleaseIndex(URI
, Dist
);
440 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
443 if (Dist
[Dist
.size() - 1] == '/')
444 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
446 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
453 class debSLTypeDeb
: public debSLTypeDebian
457 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
458 string
const &Dist
, string
const &Section
,
459 std::map
<string
, string
> const &Options
) const
461 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
467 Label
= "Standard Debian binary tree";
471 class debSLTypeDebSrc
: public debSLTypeDebian
475 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
476 string
const &Dist
, string
const &Section
,
477 std::map
<string
, string
> const &Options
) const
479 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
485 Label
= "Standard Debian source tree";
489 debSLTypeDeb _apt_DebType
;
490 debSLTypeDebSrc _apt_DebSrcType
;