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 debReleaseIndex::~debReleaseIndex()
120 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
121 I
!= SectionEntries
.end(); I
++)
125 vector
<struct IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const
127 vector
<struct IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
128 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
129 I
!= SectionEntries
.end();
132 IndexTarget
* Target
= new IndexTarget();
133 Target
->ShortDesc
= (*I
)->IsSrc
? "Sources" : "Packages";
135 = (*I
)->IsSrc
? SourceIndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
)
136 : IndexURISuffix(Target
->ShortDesc
.c_str(), (*I
)->Section
);
138 = (*I
)->IsSrc
? SourceIndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
)
139 : IndexURI(Target
->ShortDesc
.c_str(), (*I
)->Section
);
141 Target
->Description
= Info (Target
->ShortDesc
.c_str(), (*I
)->Section
);
142 IndexTargets
->push_back (Target
);
147 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool GetAll
) const
149 // special case for --print-uris
151 vector
<struct IndexTarget
*> *targets
= ComputeIndexTargets();
152 for (vector
<struct IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); Target
++) {
153 new pkgAcqIndex(Owner
, (*Target
)->URI
, (*Target
)->Description
,
154 (*Target
)->ShortDesc
, HashString());
156 // this is normally created in pkgAcqMetaSig, but if we run
157 // in --print-uris mode, we add it here
158 new pkgAcqMetaIndex(Owner
, MetaIndexURI("Release"),
159 MetaIndexInfo("Release"), "Release",
160 MetaIndexURI("Release.gpg"),
161 ComputeIndexTargets(),
162 new indexRecords (Dist
));
166 new pkgAcqMetaSig(Owner
, MetaIndexURI("Release.gpg"),
167 MetaIndexInfo("Release.gpg"), "Release.gpg",
168 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
169 ComputeIndexTargets(),
170 new indexRecords (Dist
));
172 // Queue the translations
173 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
174 I
!= SectionEntries
.end(); I
++) {
178 debTranslationsIndex i
= debTranslationsIndex(URI
,Dist
,(*I
)->Section
);
185 bool debReleaseIndex::IsTrusted() const
187 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
188 URItoFileName(MetaIndexURI("Release")) + ".gpg";
190 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
191 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
194 if (FileExists(VerifiedSigFile
))
199 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles()
204 Indexes
= new vector
<pkgIndexFile
*>;
205 for (vector
<const debSectionEntry
*>::const_iterator I
= SectionEntries
.begin();
206 I
!= SectionEntries
.end(); I
++) {
208 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
211 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
212 Indexes
->push_back(new debTranslationsIndex(URI
, Dist
, (*I
)->Section
));
219 void debReleaseIndex::PushSectionEntry(const debSectionEntry
*Entry
)
221 SectionEntries
.push_back(Entry
);
224 debReleaseIndex::debSectionEntry::debSectionEntry (string Section
, bool IsSrc
): Section(Section
)
229 class debSLTypeDebian
: public pkgSourceList::Type
233 bool CreateItemInternal(vector
<metaIndex
*> &List
,string URI
,
234 string Dist
,string Section
,
237 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
238 I
!= List
.end(); I
++)
240 // This check insures that there will be only one Release file
241 // queued for all the Packages files and Sources files it
243 if (strcmp((*I
)->GetType(), "deb") == 0)
245 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
246 // This check insures that there will be only one Release file
247 // queued for all the Packages files and Sources files it
249 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
251 Deb
->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
256 // No currently created Release file indexes this entry, so we create a new one.
257 // XXX determine whether this release is trusted or not
258 debReleaseIndex
*Deb
= new debReleaseIndex(URI
,Dist
);
259 Deb
->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
265 class debSLTypeDeb
: public debSLTypeDebian
269 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
270 string Dist
,string Section
) const
272 return CreateItemInternal(List
, URI
, Dist
, Section
, false);
278 Label
= "Standard Debian binary tree";
282 class debSLTypeDebSrc
: public debSLTypeDebian
286 bool CreateItem(vector
<metaIndex
*> &List
,string URI
,
287 string Dist
,string Section
) const
289 return CreateItemInternal(List
, URI
, Dist
, Section
, true);
295 Label
= "Standard Debian source tree";
299 debSLTypeDeb _apt_DebType
;
300 debSLTypeDebSrc _apt_DebSrcType
;