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 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) {
125 this->Indexes
= NULL
;
129 debReleaseIndex::~debReleaseIndex() {
130 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
131 A
!= ArchEntries
.end(); ++A
)
132 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
133 S
!= A
->second
.end(); ++S
)
137 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const {
138 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
140 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
141 if (src
!= ArchEntries
.end()) {
142 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
143 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
144 I
!= SectionEntries
.end(); ++I
) {
145 IndexTarget
* Target
= new IndexTarget();
146 Target
->ShortDesc
= "Sources";
147 Target
->MetaKey
= SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
148 Target
->URI
= SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
149 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
150 IndexTargets
->push_back (Target
);
154 // Only source release
155 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
158 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
159 a
!= ArchEntries
.end(); ++a
) {
160 if (a
->first
== "source")
162 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
163 I
!= a
->second
.end(); ++I
) {
164 IndexTarget
* Target
= new IndexTarget();
165 Target
->ShortDesc
= "Packages";
166 Target
->MetaKey
= IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
167 Target
->URI
= IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
168 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
, a
->first
);
169 IndexTargets
->push_back (Target
);
176 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
178 // special case for --print-uris
180 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
181 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); Target
++) {
182 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
183 (*Target
)->ShortDesc
, HashString());
185 // this is normally created in pkgAcqMetaSig, but if we run
186 // in --print-uris mode, we add it here
187 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
188 MetaIndexInfo("Release"), "Release",
189 MetaIndexURI("Release.gpg"),
190 ComputeIndexTargets(),
191 new indexRecords (Dist
));
195 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
196 MetaIndexInfo("Release.gpg"), "Release.gpg",
197 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
198 ComputeIndexTargets(),
199 new indexRecords (Dist
));
201 // Queue the translations
202 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
203 map
<string
, set
<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
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
209 I
!= a
->second
.end(); I
++)
210 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
213 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
214 s
!= sections
.end(); ++s
)
215 for (set
<string
>::const_iterator l
= s
->second
.begin();
216 l
!= s
->second
.end(); l
++) {
217 debTranslationsIndex i
= debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str());
224 bool debReleaseIndex::IsTrusted() const
226 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
227 URItoFileName(MetaIndexURI("Release")) + ".gpg";
229 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
230 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
233 if (FileExists(VerifiedSigFile
))
238 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
242 Indexes
= new vector
<pkgIndexFile
*>;
243 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
244 if (src
!= ArchEntries
.end()) {
245 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
246 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
247 I
!= SectionEntries
.end(); I
++)
248 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
251 // Only source release
252 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
255 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
256 map
<string
, set
<string
> > sections
;
257 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
258 a
!= ArchEntries
.end(); ++a
) {
259 if (a
->first
== "source")
261 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
262 I
!= a
->second
.end(); I
++) {
263 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
264 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
268 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
269 s
!= sections
.end(); ++s
)
270 for (set
<string
>::const_iterator l
= s
->second
.begin();
271 l
!= s
->second
.end(); l
++)
272 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
277 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
278 for (vector
<string
>::const_iterator a
= Archs
.begin();
279 a
!= Archs
.end(); ++a
)
280 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
284 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
285 ArchEntries
[Arch
].push_back(Entry
);
288 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
) {
289 if (Entry
->IsSrc
== true)
290 PushSectionEntry("source", Entry
);
292 for (map
<string
, vector
<const debSectionEntry
*> >::iterator a
= ArchEntries
.begin();
293 a
!= ArchEntries
.end(); ++a
) {
294 a
->second
.push_back(Entry
);
299 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
300 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
303 class debSLTypeDebian
: public pkgSourceList::Type
307 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
308 string
const &Dist
, string
const &Section
,
309 bool const &IsSrc
, map
<string
, string
> const &Options
) const
311 map
<string
, string
>::const_iterator
const arch
= Options
.find("arch");
312 vector
<string
> const Archs
=
313 (arch
!= Options
.end()) ? ExplodeString(arch
->second
) :
314 APT::Configuration::getArchitectures();
316 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
317 I
!= List
.end(); I
++)
319 // We only worry about debian entries here
320 if (strcmp((*I
)->GetType(), "deb") != 0)
323 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
324 /* This check insures that there will be only one Release file
325 queued for all the Packages files and Sources files it
327 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
330 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
332 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
336 // No currently created Release file indexes this entry, so we create a new one.
337 // XXX determine whether this release is trusted or not
338 debReleaseIndex
*Deb
= new debReleaseIndex(URI
, Dist
);
340 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
342 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
348 class debSLTypeDeb
: public debSLTypeDebian
352 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
353 string
const &Dist
, string
const &Section
,
354 std::map
<string
, string
> const &Options
) const
356 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
362 Label
= "Standard Debian binary tree";
366 class debSLTypeDebSrc
: public debSLTypeDebian
370 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
371 string
const &Dist
, string
const &Section
,
372 std::map
<string
, string
> const &Options
) const
374 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
380 Label
= "Standard Debian source tree";
384 debSLTypeDeb _apt_DebType
;
385 debSLTypeDebSrc _apt_DebSrcType
;