3 #include <apt-pkg/debmetaindex.h>
4 #include <apt-pkg/debindexfile.h>
5 #include <apt-pkg/strutl.h>
6 #include <apt-pkg/acquire-item.h>
7 #include <apt-pkg/configuration.h>
8 #include <apt-pkg/aptconfiguration.h>
9 #include <apt-pkg/error.h>
15 string
debReleaseIndex::Info(const char *Type
, string
const &Section
, string
const &Arch
) const
17 string Info
= ::URI::SiteOnly(URI
) + ' ';
18 if (Dist
[Dist
.size() - 1] == '/')
25 Info
+= Dist
+ '/' + Section
;
26 if (Arch
.empty() != true)
34 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
36 string Info
= ::URI::SiteOnly(URI
) + ' ';
37 if (Dist
[Dist
.size() - 1] == '/')
49 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
51 return _config
->FindDir("Dir::State::lists") +
52 URItoFileName(MetaIndexURI(Type
));
55 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
61 else if (Dist
[Dist
.size()-1] == '/')
64 Res
= URI
+ "dists/" + Dist
+ "/";
70 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
73 if (Dist
[Dist
.size() - 1] != '/')
76 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
78 Res
+= Section
+ "/binary-" + Arch
+ '/';
84 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
86 if (Dist
[Dist
.size() - 1] == '/')
96 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
99 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
102 if (Dist
[Dist
.size() - 1] != '/')
103 Res
+= Section
+ "/source/";
107 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
110 if (Dist
[Dist
.size() - 1] == '/')
119 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
122 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
125 if (Dist
[Dist
.size() - 1] != '/')
126 Res
+= Section
+ "/i18n/";
130 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
133 if (Dist
[Dist
.size() - 1] == '/')
142 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
145 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
146 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
149 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
150 metaIndex(URI
, Dist
, "deb") {
154 debReleaseIndex::~debReleaseIndex() {
155 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
156 A
!= ArchEntries
.end(); ++A
)
157 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
158 S
!= A
->second
.end(); ++S
)
162 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
163 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
165 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
166 if (src
!= ArchEntries
.end()) {
167 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
168 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
169 I
!= SectionEntries
.end(); ++I
) {
170 IndexTarget
* Target
= new IndexTarget();
171 Target
->ShortDesc
= "Sources";
172 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
173 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
174 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
175 IndexTargets
->push_back (Target
);
179 // Only source release
180 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
183 std::set
<std::string
> sections
;
184 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
185 a
!= ArchEntries
.end(); ++a
) {
186 if (a
->first
== "source")
188 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
189 I
!= a
->second
.end(); ++I
) {
190 IndexTarget
* Target
= new IndexTarget();
191 Target
->ShortDesc
= "Packages";
192 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
193 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
194 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
195 IndexTargets
->push_back (Target
);
196 sections
.insert((*I
)->Section
);
200 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
201 if (lang
.empty() == true)
204 // get the Translations:
205 // - if its a dists-style repository get the i18n/Index first
206 // - if its flat try to acquire files by guessing
207 if (Dist
[Dist
.size() - 1] == '/') {
208 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
209 s
!= sections
.end(); ++s
) {
210 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
211 l
!= lang
.end(); l
++) {
212 if (*l
== "none") continue;
213 IndexTarget
* Target
= new OptionalIndexTarget();
214 Target
->ShortDesc
= "Translation-" + *l
;
215 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
216 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
217 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
218 IndexTargets
->push_back(Target
);
222 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
223 s
!= sections
.end(); ++s
) {
224 IndexTarget
* Target
= new OptionalIndexTarget();
225 Target
->ShortDesc
= "TranslationIndex";
226 Target
->MetaKey
= TranslationIndexURISuffix("Index", *s
);
227 Target
->URI
= TranslationIndexURI("Index", *s
);
228 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
229 IndexTargets
->push_back (Target
);
236 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
238 // special case for --print-uris
240 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
241 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); Target
++) {
242 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
243 (*Target
)->ShortDesc
, HashString());
247 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
248 MetaIndexInfo("InRelease"), "InRelease",
249 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
250 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
251 ComputeIndexTargets(),
252 new indexRecords (Dist
));
257 void debReleaseIndex::SetTrusted(bool const Trusted
)
260 this->Trusted
= ALWAYS_TRUSTED
;
262 this->Trusted
= NEVER_TRUSTED
;
265 bool debReleaseIndex::IsTrusted() const
267 if (Trusted
== ALWAYS_TRUSTED
)
269 else if (Trusted
== NEVER_TRUSTED
)
273 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
274 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
277 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
278 URItoFileName(MetaIndexURI("Release")) + ".gpg";
280 if (FileExists(VerifiedSigFile
))
283 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
284 URItoFileName(MetaIndexURI("InRelease"));
286 return FileExists(VerifiedSigFile
);
289 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
293 Indexes
= new vector
<pkgIndexFile
*>;
294 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
295 if (src
!= ArchEntries
.end()) {
296 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
297 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
298 I
!= SectionEntries
.end(); I
++)
299 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
302 // Only source release
303 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
306 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
307 map
<string
, set
<string
> > sections
;
308 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
309 a
!= ArchEntries
.end(); ++a
) {
310 if (a
->first
== "source")
312 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
313 I
!= a
->second
.end(); I
++) {
314 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
315 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
319 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
320 s
!= sections
.end(); ++s
)
321 for (set
<string
>::const_iterator l
= s
->second
.begin();
322 l
!= s
->second
.end(); l
++) {
323 if (*l
== "none") continue;
324 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
330 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
331 for (vector
<string
>::const_iterator a
= Archs
.begin();
332 a
!= Archs
.end(); ++a
)
333 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
337 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
338 ArchEntries
[Arch
].push_back(Entry
);
341 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
342 if (Entry
->IsSrc
== true)
343 PushSectionEntry("source", Entry
);
345 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
346 a
!= ArchEntries
.end(); ++a
) {
347 a
->second
.push_back(Entry
);
352 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
353 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
356 class debSLTypeDebian
: public pkgSourceList::Type
360 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
361 string
const &Dist
, string
const &Section
,
362 bool const &IsSrc
, map
<string
, string
> const &Options
) const
364 map
<string
, string
>::const_iterator
const arch
= Options
.find("arch");
365 vector
<string
> const Archs
=
366 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
367 APT::Configuration::getArchitectures();
368 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
370 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
371 I
!= List
.end(); I
++)
373 // We only worry about debian entries here
374 if (strcmp((*I
)->GetType(), "deb") != 0)
377 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
378 if (trusted
!= Options
.end())
379 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
381 /* This check insures that there will be only one Release file
382 queued for all the Packages files and Sources files it
384 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
387 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
390 if (Dist
[Dist
.size() - 1] == '/')
391 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
393 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
399 // No currently created Release file indexes this entry, so we create a new one.
400 debReleaseIndex
*Deb
;
401 if (trusted
!= Options
.end())
402 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
404 Deb
= new debReleaseIndex(URI
, Dist
);
407 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
410 if (Dist
[Dist
.size() - 1] == '/')
411 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
413 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
420 class debSLTypeDeb
: public debSLTypeDebian
424 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
425 string
const &Dist
, string
const &Section
,
426 std::map
<string
, string
> const &Options
) const
428 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
434 Label
= "Standard Debian binary tree";
438 class debSLTypeDebSrc
: public debSLTypeDebian
442 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
443 string
const &Dist
, string
const &Section
,
444 std::map
<string
, string
> const &Options
) const
446 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
452 Label
= "Standard Debian source tree";
456 debSLTypeDeb _apt_DebType
;
457 debSLTypeDebSrc _apt_DebSrcType
;