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 debTranslationsIndex i
= debTranslationsIndex(URI
,Dist
,(*I
)->Section
,(*l
).c_str());
192 bool debReleaseIndex::IsTrusted() const
194 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
195 URItoFileName(MetaIndexURI("Release")) + ".gpg";
197 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
198 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
201 if (FileExists(VerifiedSigFile
))
206 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles()
211 Indexes
= new vector
<pkgIndexFile
*>;
212 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
213 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
214 I
!= SectionEntries
.end(); I
++) {
216 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
219 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
221 for (vector
<string
>::const_iterator l
= lang
.begin();
222 l
!= lang
.end(); l
++)
223 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,(*I
)->Section
,(*l
).c_str()));
230 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
)
232 SectionEntries
.push_back(Entry
);
235 debReleaseIndex::debSectionEntry::debSectionEntry (string Section
, bool IsSrc
): Section(Section
)
240 class debSLTypeDebian
: public pkgSourceList::Type
244 bool CreateItemInternal(vector
<metaIndex
*> &List
,string URI
,
245 string Dist
,string Section
,
248 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
249 I
!= List
.end(); I
++)
251 // This check insures that there will be only one Release file
252 // queued for all the Packages files and Sources files it
254 if (strcmp((*I
)->GetType(), "deb") == 0)
256 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
257 // This check insures that there will be only one Release file
258 // queued for all the Packages files and Sources files it
260 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
262 Deb
->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
267 // No currently created Release file indexes this entry, so we create a new one.
268 // XXX determine whether this release is trusted or not
269 debReleaseIndex
*Deb
= new debReleaseIndex(URI
,Dist
);
270 Deb
->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
276 class debSLTypeDeb
: public debSLTypeDebian
280 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
281 string Dist
,string Section
) const
283 return CreateItemInternal(List
, URI
, Dist
, Section
, false);
289 Label
= "Standard Debian binary tree";
293 class debSLTypeDebSrc
: public debSLTypeDebian
297 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
298 string Dist
,string Section
) const
300 return CreateItemInternal(List
, URI
, Dist
, Section
, true);
306 Label
= "Standard Debian source tree";
310 debSLTypeDeb _apt_DebType
;
311 debSLTypeDebSrc _apt_DebSrcType
;