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/error.h>
12 string
debReleaseIndex::Info(const char *Type
, const string Section
) const
14 string Info
= ::URI::SiteOnly(URI
) + ' ';
15 if (Dist
[Dist
.size() - 1] == '/')
21 Info
+= Dist
+ '/' + Section
;
27 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
29 string Info
= ::URI::SiteOnly(URI
) + ' ';
30 if (Dist
[Dist
.size() - 1] == '/')
42 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
44 return _config
->FindDir("Dir::State::lists") +
45 URItoFileName(MetaIndexURI(Type
));
48 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
54 else if (Dist
[Dist
.size()-1] == '/')
57 Res
= URI
+ "dists/" + Dist
+ "/";
63 string
debReleaseIndex::IndexURISuffix(const char *Type
, const string Section
) const
66 if (Dist
[Dist
.size() - 1] != '/')
67 Res
+= Section
+ "/binary-" + _config
->Find("APT::Architecture") + '/';
72 string
debReleaseIndex::IndexURI(const char *Type
, const string Section
) const
74 if (Dist
[Dist
.size() - 1] == '/')
84 return URI
+ "dists/" + Dist
+ '/' + IndexURISuffix(Type
, Section
);
87 string
debReleaseIndex::SourceIndexURISuffix(const char *Type
, const string Section
) const
90 if (Dist
[Dist
.size() - 1] != '/')
91 Res
+= Section
+ "/source/";
95 string
debReleaseIndex::SourceIndexURI(const char *Type
, const string Section
) const
98 if (Dist
[Dist
.size() - 1] == '/')
107 return URI
+ "dists/" + Dist
+ "/" + SourceIndexURISuffix(Type
, Section
);
110 debReleaseIndex::debReleaseIndex(string URI
,string Dist
)
114 this->Indexes
= NULL
;
118 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const
120 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
121 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
122 I
!= SectionEntries
.end();
125 IndexTarget
* Target
= new IndexTarget();
126 Target
->ShortDesc
= (*I
)->IsSrc
? "Sources" : "Packages";
128 = (*I
)->IsSrc
? SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
)
129 : IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
131 = (*I
)->IsSrc
? SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
)
132 : IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
134 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
135 IndexTargets
->push_back (Target
);
140 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool GetAll
) const
142 // special case for --print-uris
144 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
145 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); Target
++) {
146 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
147 (*Target
)->ShortDesc
, HashString());
149 // this is normally created in pkgAcqMetaSig, but if we run
150 // in --print-uris mode, we add it here
151 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
152 MetaIndexInfo("Release"), "Release",
153 MetaIndexURI("Release.gpg"),
154 ComputeIndexTargets(),
155 new indexRecords (Dist
));
159 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
160 MetaIndexInfo("Release.gpg"), "Release.gpg",
161 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
162 ComputeIndexTargets(),
163 new indexRecords (Dist
));
165 // Queue the translations
166 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
167 I
!= SectionEntries
.end(); I
++) {
171 debTranslationsIndex i
= debTranslationsIndex(URI
,Dist
,(*I
)->Section
);
178 bool debReleaseIndex::IsTrusted() const
180 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
181 URItoFileName(MetaIndexURI("Release")) + ".gpg";
183 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
184 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
187 if (FileExists(VerifiedSigFile
))
192 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles()
197 Indexes
= new vector
<pkgIndexFile
*>;
198 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
199 I
!= SectionEntries
.end(); I
++) {
201 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
204 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
205 Indexes
->push_back(new debTranslationsIndex(URI
, Dist
, (*I
)->Section
));
212 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
)
214 SectionEntries
.push_back(Entry
);
217 debReleaseIndex::debSectionEntry::debSectionEntry (string Section
, bool IsSrc
): Section(Section
)
222 class debSLTypeDebian
: public pkgSourceList::Type
226 bool CreateItemInternal(vector
<metaIndex
*> &List
,string URI
,
227 string Dist
,string Section
,
230 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
231 I
!= List
.end(); I
++)
233 // This check insures that there will be only one Release file
234 // queued for all the Packages files and Sources files it
236 if (strcmp((*I
)->GetType(), "deb") == 0)
238 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
239 // This check insures that there will be only one Release file
240 // queued for all the Packages files and Sources files it
242 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
244 Deb
->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
249 // No currently created Release file indexes this entry, so we create a new one.
250 // XXX determine whether this release is trusted or not
251 debReleaseIndex
*Deb
= new debReleaseIndex(URI
,Dist
);
252 Deb
->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
258 class debSLTypeDeb
: public debSLTypeDebian
262 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
263 string Dist
,string Section
) const
265 return CreateItemInternal(List
, URI
, Dist
, Section
, false);
271 Label
= "Standard Debian binary tree";
275 class debSLTypeDebSrc
: public debSLTypeDebian
279 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
280 string Dist
,string Section
) const
282 return CreateItemInternal(List
, URI
, Dist
, Section
, true);
288 Label
= "Standard Debian source tree";
292 debSLTypeDeb _apt_DebType
;
293 debSLTypeDebSrc _apt_DebSrcType
;