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>
16 string
debReleaseIndex::Info(const char *Type
, string
const &Section
, string
const &Arch
) const
18 string Info
= ::URI::SiteOnly(URI
) + ' ';
19 if (Dist
[Dist
.size() - 1] == '/')
26 Info
+= Dist
+ '/' + Section
;
27 if (Arch
.empty() != true)
35 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
37 string Info
= ::URI::SiteOnly(URI
) + ' ';
38 if (Dist
[Dist
.size() - 1] == '/')
50 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
52 return _config
->FindDir("Dir::State::lists") +
53 URItoFileName(MetaIndexURI(Type
));
56 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
62 else if (Dist
[Dist
.size()-1] == '/')
65 Res
= URI
+ "dists/" + Dist
+ "/";
71 string
debReleaseIndex::IndexURISuffix(const char *Type
, string
const &Section
, string
const &Arch
) const
74 if (Dist
[Dist
.size() - 1] != '/')
77 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
79 Res
+= Section
+ "/binary-" + Arch
+ '/';
85 string
debReleaseIndex::IndexURI(const char *Type
, string
const &Section
, string
const &Arch
) const
87 if (Dist
[Dist
.size() - 1] == '/')
97 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
, Arch
);
100 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string
&Section
) const
103 if (Dist
[Dist
.size() - 1] != '/')
104 Res
+= Section
+ "/source/";
108 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string
&Section
) const
111 if (Dist
[Dist
.size() - 1] == '/')
120 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
123 string
debReleaseIndex::TranslationIndexURISuffix(const char *Type
, const string
&Section
) const
126 if (Dist
[Dist
.size() - 1] != '/')
127 Res
+= Section
+ "/i18n/";
131 string
debReleaseIndex::TranslationIndexURI(const char *Type
, const string
&Section
) const
134 if (Dist
[Dist
.size() - 1] == '/')
143 return URI
+ "dists/" + Dist
+ "/" + TranslationIndexURISuffix(Type
, Section
);
146 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) {
149 this->Indexes
= NULL
;
153 debReleaseIndex::~debReleaseIndex() {
154 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
155 A
!= ArchEntries
.end(); ++A
)
156 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
157 S
!= A
->second
.end(); ++S
)
161 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
162 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
164 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
165 if (src
!= ArchEntries
.end()) {
166 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
167 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
168 I
!= SectionEntries
.end(); ++I
) {
169 IndexTarget
* Target
= new IndexTarget();
170 Target
->ShortDesc
= "Sources";
171 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
172 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
173 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
174 IndexTargets
->push_back (Target
);
178 // Only source release
179 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
182 std::set
<std::string
> sections
;
183 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
184 a
!= ArchEntries
.end(); ++a
) {
185 if (a
->first
== "source")
187 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
188 I
!= a
->second
.end(); ++I
) {
189 IndexTarget
* Target
= new IndexTarget();
190 Target
->ShortDesc
= "Packages";
191 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
192 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
193 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
194 IndexTargets
->push_back (Target
);
195 sections
.insert((*I
)->Section
);
199 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
200 std::vector
<std::string
>::iterator lend
= std::remove(lang
.begin(), lang
.end(), "none");
201 if (lend
!= lang
.end())
204 if (lang
.empty() == true)
207 // get the Translations:
208 // - if its a dists-style repository get the i18n/Index first
209 // - if its flat try to acquire files by guessing
210 if (Dist
[Dist
.size() - 1] == '/') {
211 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
212 s
!= sections
.end(); ++s
) {
213 for (std::vector
<std::string
>::const_iterator l
= lang
.begin();
214 l
!= lang
.end(); ++l
) {
215 IndexTarget
* Target
= new OptionalIndexTarget();
216 Target
->ShortDesc
= "Translation-" + *l
;
217 Target
->MetaKey
= TranslationIndexURISuffix(l
->c_str(), *s
);
218 Target
->URI
= TranslationIndexURI(l
->c_str(), *s
);
219 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
220 IndexTargets
->push_back(Target
);
224 for (std::set
<std::string
>::const_iterator s
= sections
.begin();
225 s
!= sections
.end(); ++s
) {
226 IndexTarget
* Target
= new OptionalIndexTarget();
227 Target
->ShortDesc
= "TranslationIndex";
228 Target
->MetaKey
= TranslationIndexURISuffix("Index", *s
);
229 Target
->URI
= TranslationIndexURI("Index", *s
);
230 Target
->Description
= Info (Target
->ShortDesc
.c_str(), *s
);
231 IndexTargets
->push_back (Target
);
238 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
240 // special case for --print-uris
242 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
243 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
) {
244 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
245 (*Target
)->ShortDesc
, HashString());
249 new pkgAcqMetaClearSig(Owner
, MetaIndexURI("InRelease"),
250 MetaIndexInfo("InRelease"), "InRelease",
251 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
252 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
253 ComputeIndexTargets(),
254 new indexRecords (Dist
));
259 bool debReleaseIndex::IsTrusted() const
261 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
262 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
265 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
266 URItoFileName(MetaIndexURI("Release")) + ".gpg";
268 if (FileExists(VerifiedSigFile
))
271 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
272 URItoFileName(MetaIndexURI("InRelease"));
274 return FileExists(VerifiedSigFile
);
277 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
281 Indexes
= new vector
<pkgIndexFile
*>;
282 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
283 if (src
!= ArchEntries
.end()) {
284 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
285 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
286 I
!= SectionEntries
.end(); ++I
)
287 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
290 // Only source release
291 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
294 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
295 map
<string
, set
<string
> > sections
;
296 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
297 a
!= ArchEntries
.end(); ++a
) {
298 if (a
->first
== "source")
300 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
301 I
!= a
->second
.end(); ++I
) {
302 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
303 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
307 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
308 s
!= sections
.end(); ++s
)
309 for (set
<string
>::const_iterator l
= s
->second
.begin();
310 l
!= s
->second
.end(); ++l
) {
311 if (*l
== "none") continue;
312 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
318 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
319 for (vector
<string
>::const_iterator a
= Archs
.begin();
320 a
!= Archs
.end(); ++a
)
321 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
325 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
326 ArchEntries
[Arch
].push_back(Entry
);
329 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
330 if (Entry
->IsSrc
== true)
331 PushSectionEntry("source", Entry
);
333 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
334 a
!= ArchEntries
.end(); ++a
) {
335 a
->second
.push_back(Entry
);
340 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
341 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
344 class debSLTypeDebian
: public pkgSourceList::Type
348 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
349 string
const &Dist
, string
const &Section
,
350 bool const &IsSrc
, map
<string
, string
> const &Options
) const
352 map
<string
, string
>::const_iterator
const arch
= Options
.find("arch");
353 vector
<string
> const Archs
=
354 (arch
!= Options
.end()) ? VectorizeString(arch
->second
, ',') :
355 APT::Configuration::getArchitectures();
357 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
358 I
!= List
.end(); ++I
)
360 // We only worry about debian entries here
361 if (strcmp((*I
)->GetType(), "deb") != 0)
364 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
365 /* This check insures that there will be only one Release file
366 queued for all the Packages files and Sources files it
368 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
371 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
374 if (Dist
[Dist
.size() - 1] == '/')
375 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
377 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
382 // No currently created Release file indexes this entry, so we create a new one.
383 // XXX determine whether this release is trusted or not
384 debReleaseIndex
*Deb
= new debReleaseIndex(URI
, Dist
);
386 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
389 if (Dist
[Dist
.size() - 1] == '/')
390 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
392 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
399 class debSLTypeDeb
: public debSLTypeDebian
403 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
404 string
const &Dist
, string
const &Section
,
405 std::map
<string
, string
> const &Options
) const
407 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
413 Label
= "Standard Debian binary tree";
417 class debSLTypeDebSrc
: public debSLTypeDebian
421 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
422 string
const &Dist
, string
const &Section
,
423 std::map
<string
, string
> const &Options
) const
425 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
431 Label
= "Standard Debian source tree";
435 debSLTypeDeb _apt_DebType
;
436 debSLTypeDebSrc _apt_DebSrcType
;