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>
13 string
debReleaseIndex::Info(const char *Type
, const string Section
) const
15 string Info
= ::URI::SiteOnly(URI
) + ' ';
16 if (Dist
[Dist
.size() - 1] == '/')
22 Info
+= Dist
+ '/' + Section
;
28 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
30 string Info
= ::URI::SiteOnly(URI
) + ' ';
31 if (Dist
[Dist
.size() - 1] == '/')
43 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
45 return _config
->FindDir("Dir::State::lists") +
46 URItoFileName(MetaIndexURI(Type
));
49 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
55 else if (Dist
[Dist
.size()-1] == '/')
58 Res
= URI
+ "dists/" + Dist
+ "/";
64 string
debReleaseIndex::IndexURISuffix(const char *Type
, const string Section
) const
67 if (Dist
[Dist
.size() - 1] != '/')
68 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
73 string
debReleaseIndex::IndexURI(const char *Type
, const string Section
) const
75 if (Dist
[Dist
.size() - 1] == '/')
85 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
);
88 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string Section
) const
91 if (Dist
[Dist
.size() - 1] != '/')
92 Res
+= Section
+ "/source/";
96 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string Section
) const
99 if (Dist
[Dist
.size() - 1] == '/')
108 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
111 debReleaseIndex::debReleaseIndex(string URI
,string Dist
)
115 this->Indexes
= NULL
;
119 debReleaseIndex::~debReleaseIndex()
121 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
122 I
!= SectionEntries
.end(); I
++)
126 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const
128 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
129 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
130 I
!= SectionEntries
.end();
133 IndexTarget
* Target
= new IndexTarget();
134 Target
->ShortDesc
= (*I
)->IsSrc
? "Sources" : "Packages";
136 = (*I
)->IsSrc
? SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
)
137 : IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
139 = (*I
)->IsSrc
? SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
)
140 : IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
142 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
143 IndexTargets
->push_back (Target
);
148 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool GetAll
) const
150 // special case for --print-uris
152 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
153 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); Target
++) {
154 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
155 (*Target
)->ShortDesc
, HashString());
157 // this is normally created in pkgAcqMetaSig, but if we run
158 // in --print-uris mode, we add it here
159 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
160 MetaIndexInfo("Release"), "Release",
161 MetaIndexURI("Release.gpg"),
162 ComputeIndexTargets(),
163 new indexRecords (Dist
));
167 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
168 MetaIndexInfo("Release.gpg"), "Release.gpg",
169 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
170 ComputeIndexTargets(),
171 new indexRecords (Dist
));
173 // Queue the translations
174 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
175 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
176 I
!= SectionEntries
.end(); I
++) {
181 for (vector
<string
>::const_iterator l
= lang
.begin();
182 l
!= lang
.end(); l
++)
184 if (*l
== "none") continue;
185 debTranslationsIndex i
= debTranslationsIndex(URI
,Dist
,(*I
)->Section
,(*l
).c_str());
193 bool debReleaseIndex::IsTrusted() const
195 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
196 URItoFileName(MetaIndexURI("Release")) + ".gpg";
198 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
199 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
202 if (FileExists(VerifiedSigFile
))
207 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles()
212 Indexes
= new vector
<pkgIndexFile
*>;
213 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
214 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
215 I
!= SectionEntries
.end(); I
++) {
217 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
220 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
222 for (vector
<string
>::const_iterator l
= lang
.begin();
223 l
!= lang
.end(); l
++) {
224 if (*l
== "none") continue;
225 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,(*I
)->Section
,(*l
).c_str()));
233 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
)
235 SectionEntries
.push_back(Entry
);
238 debReleaseIndex::debSectionEntry::debSectionEntry (string Section
, bool IsSrc
): Section(Section
)
243 class debSLTypeDebian
: public pkgSourceList::Type
247 bool CreateItemInternal(vector
<metaIndex
*> &List
,string URI
,
248 string Dist
,string Section
,
251 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
252 I
!= List
.end(); I
++)
254 // This check insures that there will be only one Release file
255 // queued for all the Packages files and Sources files it
257 if (strcmp((*I
)->GetType(), "deb") == 0)
259 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
260 // This check insures that there will be only one Release file
261 // queued for all the Packages files and Sources files it
263 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
265 Deb
->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
270 // No currently created Release file indexes this entry, so we create a new one.
271 // XXX determine whether this release is trusted or not
272 debReleaseIndex
*Deb
= new debReleaseIndex(URI
,Dist
);
273 Deb
->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
279 class debSLTypeDeb
: public debSLTypeDebian
283 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
284 string Dist
,string Section
) const
286 return CreateItemInternal(List
, URI
, Dist
, Section
, false);
292 Label
= "Standard Debian binary tree";
296 class debSLTypeDebSrc
: public debSLTypeDebian
300 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
301 string Dist
,string Section
) const
303 return CreateItemInternal(List
, URI
, Dist
, Section
, true);
309 Label
= "Standard Debian source tree";
313 debSLTypeDeb _apt_DebType
;
314 debSLTypeDebSrc _apt_DebSrcType
;