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>
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 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
77 if (Dist
[Dist
.size() - 1] != '/')
80 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
82 Res
+= Section
+ "/binary-" + Arch
+ '/';
88 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
90 if (Dist
[Dist
.size() - 1] == '/')
100 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
103 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
106 if (Dist
[Dist
.size() - 1] != '/')
107 Res
+= Section
+ "/source/";
111 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
114 if (Dist
[Dist
.size() - 1] == '/')
123 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
126 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
129 if (Dist
[Dist
.size() - 1] != '/')
130 Res
+= Section
+ "/i18n/";
134 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
137 if (Dist
[Dist
.size() - 1] == '/')
146 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
149 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
150 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
153 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
154 metaIndex(URI
, Dist
, "deb") {
158 debReleaseIndex::~debReleaseIndex() {
159 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
160 A
!= ArchEntries
.end(); ++A
)
161 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
162 S
!= A
->second
.end(); ++S
)
166 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
167 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
169 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
170 if (src
!= ArchEntries
.end()) {
171 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
172 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
173 I
!= SectionEntries
.end(); ++I
) {
174 IndexTarget
* Target
= new IndexTarget();
175 Target
->ShortDesc
= "Sources";
176 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
177 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
178 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
179 IndexTargets
->push_back (Target
);
183 // Only source release
184 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
187 std::set
<std::string
> sections
;
188 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
189 a
!= ArchEntries
.end(); ++a
) {
190 if (a
->first
== "source")
192 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
193 I
!= a
->second
.end(); ++I
) {
194 IndexTarget
* Target
= new IndexTarget();
195 Target
->ShortDesc
= "Packages";
196 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
197 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
198 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
199 IndexTargets
->push_back (Target
);
200 sections
.insert((*I
)->Section
);
204 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
205 if (lang
.empty() == true)
208 // get the Translations:
209 // - if its a dists-style repository get the i18n/Index first
210 // - if its flat try to acquire files by guessing
211 if (Dist
[Dist
.size() - 1] == '/') {
212 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
213 s
!= sections
.end(); ++s
) {
214 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
215 l
!= lang
.end(); ++l
) {
216 if (*l
== "none") continue;
217 IndexTarget
* Target
= new OptionalIndexTarget();
218 Target
->ShortDesc
= "Translation-" + *l
;
219 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
220 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
221 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
222 IndexTargets
->push_back(Target
);
226 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
227 s
!= sections
.end(); ++s
) {
228 IndexTarget
* Target
= new OptionalIndexTarget();
229 Target
->ShortDesc
= "TranslationIndex";
230 Target
->MetaKey
= TranslationIndexURISuffix("Index", *s
);
231 Target
->URI
= TranslationIndexURI("Index", *s
);
232 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
233 IndexTargets
->push_back (Target
);
240 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
242 // special case for --print-uris
244 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
245 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
246 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
247 (*Target
)->ShortDesc
, HashString());
251 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
252 MetaIndexInfo("InRelease"), "InRelease",
253 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
254 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
255 ComputeIndexTargets(),
256 new indexRecords (Dist
));
261 void debReleaseIndex::SetTrusted(bool const Trusted
)
264 this->Trusted
= ALWAYS_TRUSTED
;
266 this->Trusted
= NEVER_TRUSTED
;
269 bool debReleaseIndex::IsTrusted() const
271 if (Trusted
== ALWAYS_TRUSTED
)
273 else if (Trusted
== NEVER_TRUSTED
)
277 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
278 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
281 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
282 URItoFileName(MetaIndexURI("Release")) + ".gpg";
284 if (FileExists(VerifiedSigFile
))
287 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
288 URItoFileName(MetaIndexURI("InRelease"));
290 return FileExists(VerifiedSigFile
);
293 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
297 Indexes
= new vector
<pkgIndexFile
*>;
298 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
299 if (src
!= ArchEntries
.end()) {
300 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
301 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
302 I
!= SectionEntries
.end(); ++I
)
303 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
306 // Only source release
307 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
310 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
311 map
<string
, set
<string
> > sections
;
312 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
313 a
!= ArchEntries
.end(); ++a
) {
314 if (a
->first
== "source")
316 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
317 I
!= a
->second
.end(); ++I
) {
318 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
319 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
323 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
324 s
!= sections
.end(); ++s
)
325 for (set
<string
>::const_iterator l
= s
->second
.begin();
326 l
!= s
->second
.end(); ++l
) {
327 if (*l
== "none") continue;
328 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
334 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
335 for (vector
<string
>::const_iterator a
= Archs
.begin();
336 a
!= Archs
.end(); ++a
)
337 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
341 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
342 ArchEntries
[Arch
].push_back(Entry
);
345 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
346 if (Entry
->IsSrc
== true)
347 PushSectionEntry("source", Entry
);
349 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
350 a
!= ArchEntries
.end(); ++a
) {
351 a
->second
.push_back(Entry
);
356 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
357 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
360 class debSLTypeDebian
: public pkgSourceList::Type
364 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
365 string
const &Dist
, string
const &Section
,
366 bool const &IsSrc
, map
<string
, string
> const &Options
) const
368 map
<string
, string
>::const_iterator
const arch
= Options
.find("arch");
369 vector
<string
> const Archs
=
370 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
371 APT::Configuration::getArchitectures();
372 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
374 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
375 I
!= List
.end(); ++I
)
377 // We only worry about debian entries here
378 if (strcmp((*I
)->GetType(), "deb") != 0)
381 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
382 if (trusted
!= Options
.end())
383 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
385 /* This check insures that there will be only one Release file
386 queued for all the Packages files and Sources files it
388 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
391 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
394 if (Dist
[Dist
.size() - 1] == '/')
395 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
397 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
403 // No currently created Release file indexes this entry, so we create a new one.
404 debReleaseIndex
*Deb
;
405 if (trusted
!= Options
.end())
406 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
408 Deb
= new debReleaseIndex(URI
, Dist
);
411 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
414 if (Dist
[Dist
.size() - 1] == '/')
415 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
417 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
424 class debSLTypeDeb
: public debSLTypeDebian
428 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
429 string
const &Dist
, string
const &Section
,
430 std::map
<string
, string
> const &Options
) const
432 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
438 Label
= "Standard Debian binary tree";
442 class debSLTypeDebSrc
: public debSLTypeDebian
446 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
447 string
const &Dist
, string
const &Section
,
448 std::map
<string
, string
> const &Options
) const
450 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
456 Label
= "Standard Debian source tree";
460 debSLTypeDeb _apt_DebType
;
461 debSLTypeDebSrc _apt_DebSrcType
;