3 #include <apt-pkg/debmetaindex.h>
4 #include <apt-pkg/debindexfile.h>
5 #include <apt-pkg/strutl.h>
6 #include <apt-pkg/fileutl.h>
7 #include <apt-pkg/acquire-item.h>
8 #include <apt-pkg/configuration.h>
9 #include <apt-pkg/aptconfiguration.h>
10 #include <apt-pkg/indexrecords.h>
11 #include <apt-pkg/sourcelist.h>
12 #include <apt-pkg/hashes.h>
13 #include <apt-pkg/macros.h>
14 #include <apt-pkg/metaindex.h>
26 string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
28 string Info
= ::URI::SiteOnly(URI
) + ' ';
29 if (Dist
[Dist
.size() - 1] == '/')
41 string
debReleaseIndex::MetaIndexFile(const char *Type
) const
43 return _config
->FindDir("Dir::State::lists") +
44 URItoFileName(MetaIndexURI(Type
));
47 string
debReleaseIndex::MetaIndexURI(const char *Type
) const
53 else if (Dist
[Dist
.size()-1] == '/')
56 Res
= URI
+ "dists/" + Dist
+ "/";
62 std::string
debReleaseIndex::LocalFileName() const
64 // see if we have a InRelease file
65 std::string PathInRelease
= MetaIndexFile("InRelease");
66 if (FileExists(PathInRelease
))
69 // and if not return the normal one
70 if (FileExists(PathInRelease
))
71 return MetaIndexFile("Release");
76 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
) :
77 metaIndex(URI
, Dist
, "deb"), Trusted(CHECK_TRUST
)
80 debReleaseIndex::debReleaseIndex(string
const &URI
, string
const &Dist
, bool const Trusted
) :
81 metaIndex(URI
, Dist
, "deb") {
85 debReleaseIndex::~debReleaseIndex() {
86 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator A
= ArchEntries
.begin();
87 A
!= ArchEntries
.end(); ++A
)
88 for (vector
<const debSectionEntry
*>::const_iterator S
= A
->second
.begin();
89 S
!= A
->second
.end(); ++S
)
93 vector
<IndexTarget
*>* debReleaseIndex::ComputeIndexTargets() const
95 vector
<IndexTarget
*>* IndexTargets
= new vector
<IndexTarget
*>;
97 bool const flatArchive
= (Dist
[Dist
.length() - 1] == '/');
98 std::string baseURI
= URI
;
105 baseURI
+= "dists/" + Dist
+ "/";
106 std::string
const Release
= (Dist
== "/") ? "" : Dist
;
107 std::string
const Site
= ::URI::SiteOnly(URI
);
108 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
110 lang
.push_back("none");
111 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
112 if (src
!= ArchEntries
.end())
114 std::vector
<std::string
> const targets
= _config
->FindVector("APT::Acquire::Targets::deb-src", "", true);
115 for (std::vector
<std::string
>::const_iterator T
= targets
.begin(); T
!= targets
.end(); ++T
)
117 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X))
118 std::string
const URI
= APT_T_CONFIG(flatArchive
? "flatURI" : "URI");
119 std::string
const ShortDesc
= APT_T_CONFIG("ShortDescription");
120 std::string
const LongDesc
= APT_T_CONFIG(flatArchive
? "flatDescription" : "Description");
121 bool const IsOptional
= _config
->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T
+ "::Optional", true);
126 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
127 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
128 I
!= SectionEntries
.end(); ++I
)
130 for (vector
<std::string
>::const_iterator l
= lang
.begin(); l
!= lang
.end(); ++l
)
132 if (*l
== "none" && URI
.find("$(LANGUAGE)") != std::string::npos
)
135 struct SubstVar subst
[] = {
136 { "$(SITE)", &Site
},
137 { "$(RELEASE)", &Release
},
138 { "$(COMPONENT)", &((*I
)->Section
) },
139 { "$(LANGUAGE)", &(*l
) },
142 std::string
const name
= SubstVar(URI
, subst
);
143 IndexTarget
* Target
;
144 if (IsOptional
== true)
146 Target
= new OptionalIndexTarget(
148 SubstVar(ShortDesc
, subst
),
149 SubstVar(LongDesc
, subst
),
155 Target
= new IndexTarget(
157 SubstVar(ShortDesc
, subst
),
158 SubstVar(LongDesc
, subst
),
162 IndexTargets
->push_back(Target
);
164 if (URI
.find("$(LANGUAGE)") == std::string::npos
)
168 if (URI
.find("$(COMPONENT)") == std::string::npos
)
174 // Only source release
175 if (IndexTargets
->empty() == false && ArchEntries
.size() == 1)
178 std::vector
<std::string
> const targets
= _config
->FindVector("APT::Acquire::Targets::deb", "", true);
179 for (std::vector
<std::string
>::const_iterator T
= targets
.begin(); T
!= targets
.end(); ++T
)
181 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X))
182 std::string
const URI
= APT_T_CONFIG(flatArchive
? "flatURI" : "URI");
183 std::string
const ShortDesc
= APT_T_CONFIG("ShortDescription");
184 std::string
const LongDesc
= APT_T_CONFIG(flatArchive
? "flatDescription" : "Description");
185 bool const IsOptional
= _config
->FindB(std::string("APT::Acquire::Targets::deb::") + *T
+ "::Optional", true);
190 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
191 a
!= ArchEntries
.end(); ++a
)
193 if (a
->first
== "source")
196 for (vector
<const debSectionEntry
*>::const_iterator I
= a
->second
.begin();
197 I
!= a
->second
.end(); ++I
) {
199 for (vector
<std::string
>::const_iterator l
= lang
.begin(); l
!= lang
.end(); ++l
)
201 if (*l
== "none" && URI
.find("$(LANGUAGE)") != std::string::npos
)
204 struct SubstVar subst
[] = {
205 { "$(SITE)", &Site
},
206 { "$(RELEASE)", &Release
},
207 { "$(COMPONENT)", &((*I
)->Section
) },
208 { "$(LANGUAGE)", &(*l
) },
209 { "$(ARCHITECTURE)", &(a
->first
) },
212 std::string
const name
= SubstVar(URI
, subst
);
213 IndexTarget
* Target
;
214 if (IsOptional
== true)
216 Target
= new OptionalIndexTarget(
218 SubstVar(ShortDesc
, subst
),
219 SubstVar(LongDesc
, subst
),
225 Target
= new IndexTarget(
227 SubstVar(ShortDesc
, subst
),
228 SubstVar(LongDesc
, subst
),
232 IndexTargets
->push_back(Target
);
234 if (URI
.find("$(LANGUAGE)") == std::string::npos
)
238 if (URI
.find("$(COMPONENT)") == std::string::npos
)
242 if (URI
.find("$(ARCHITECTURE)") == std::string::npos
)
250 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
) const
252 indexRecords
* const iR
= new indexRecords(Dist
);
253 if (Trusted
== ALWAYS_TRUSTED
)
254 iR
->SetTrusted(true);
255 else if (Trusted
== NEVER_TRUSTED
)
256 iR
->SetTrusted(false);
258 // special case for --print-uris
259 vector
<IndexTarget
*> const * const targets
= ComputeIndexTargets();
260 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X))
261 pkgAcqMetaBase
* const TransactionManager
= new pkgAcqMetaClearSig(Owner
,
262 APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
267 for (vector
<IndexTarget
*>::const_iterator Target
= targets
->begin(); Target
!= targets
->end(); ++Target
)
268 new pkgAcqIndex(Owner
, TransactionManager
, *Target
);
274 void debReleaseIndex::SetTrusted(bool const Trusted
)
277 this->Trusted
= ALWAYS_TRUSTED
;
279 this->Trusted
= NEVER_TRUSTED
;
282 bool debReleaseIndex::IsTrusted() const
284 if (Trusted
== ALWAYS_TRUSTED
)
286 else if (Trusted
== NEVER_TRUSTED
)
290 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
291 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
294 string VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
295 URItoFileName(MetaIndexURI("Release")) + ".gpg";
297 if (FileExists(VerifiedSigFile
))
300 VerifiedSigFile
= _config
->FindDir("Dir::State::lists") +
301 URItoFileName(MetaIndexURI("InRelease"));
303 return FileExists(VerifiedSigFile
);
306 vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() {
310 Indexes
= new vector
<pkgIndexFile
*>;
311 map
<string
, vector
<debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
312 if (src
!= ArchEntries
.end()) {
313 vector
<debSectionEntry
const*> const SectionEntries
= src
->second
;
314 for (vector
<debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
315 I
!= SectionEntries
.end(); ++I
)
316 Indexes
->push_back(new debSourcesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted()));
319 // Only source release
320 if (Indexes
->empty() == false && ArchEntries
.size() == 1)
323 std::vector
<std::string
> const lang
= APT::Configuration::getLanguages(true);
324 map
<string
, set
<string
> > sections
;
325 for (map
<string
, vector
<debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
326 a
!= ArchEntries
.end(); ++a
) {
327 if (a
->first
== "source")
329 for (vector
<debSectionEntry
const*>::const_iterator I
= a
->second
.begin();
330 I
!= a
->second
.end(); ++I
) {
331 Indexes
->push_back(new debPackagesIndex (URI
, Dist
, (*I
)->Section
, IsTrusted(), a
->first
));
332 sections
[(*I
)->Section
].insert(lang
.begin(), lang
.end());
336 for (map
<string
, set
<string
> >::const_iterator s
= sections
.begin();
337 s
!= sections
.end(); ++s
)
338 for (set
<string
>::const_iterator l
= s
->second
.begin();
339 l
!= s
->second
.end(); ++l
) {
340 if (*l
== "none") continue;
341 Indexes
->push_back(new debTranslationsIndex(URI
,Dist
,s
->first
,(*l
).c_str()));
347 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
348 for (vector
<string
>::const_iterator a
= Archs
.begin();
349 a
!= Archs
.end(); ++a
)
350 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
354 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
355 ArchEntries
[Arch
].push_back(Entry
);
358 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
359 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
362 class APT_HIDDEN debSLTypeDebian
: public pkgSourceList::Type
366 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
367 string
const &Dist
, string
const &Section
,
368 bool const &IsSrc
, map
<string
, string
> const &Options
) const
370 // parse arch=, arch+= and arch-= settings
371 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
372 vector
<string
> Archs
;
373 if (arch
!= Options
.end())
374 Archs
= VectorizeString(arch
->second
, ',');
376 Archs
= APT::Configuration::getArchitectures();
378 if ((arch
= Options
.find("arch+")) != Options
.end())
380 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
381 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
382 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
383 Archs
.push_back(*plus
);
385 if ((arch
= Options
.find("arch-")) != Options
.end())
387 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
388 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
390 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
391 if (kill
!= Archs
.end())
396 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
398 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
399 I
!= List
.end(); ++I
)
401 // We only worry about debian entries here
402 if (strcmp((*I
)->GetType(), "deb") != 0)
405 debReleaseIndex
*Deb
= (debReleaseIndex
*) (*I
);
406 if (trusted
!= Options
.end())
407 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
409 /* This check insures that there will be only one Release file
410 queued for all the Packages files and Sources files it
412 if (Deb
->GetURI() == URI
&& Deb
->GetDist() == Dist
)
415 Deb
->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
418 if (Dist
[Dist
.size() - 1] == '/')
419 Deb
->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
421 Deb
->PushSectionEntry(Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
427 // No currently created Release file indexes this entry, so we create a new one.
428 debReleaseIndex
*Deb
;
429 if (trusted
!= Options
.end())
430 Deb
= new debReleaseIndex(URI
, Dist
, StringToBool(trusted
->second
, false));
432 Deb
= new debReleaseIndex(URI
, Dist
);
435 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
438 if (Dist
[Dist
.size() - 1] == '/')
439 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
441 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
448 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
)
449 : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
)
451 DebIndex
= new debDebPkgFileIndex(DebFile
);
452 Indexes
= new vector
<pkgIndexFile
*>();
453 Indexes
->push_back(DebIndex
);
457 class APT_HIDDEN debSLTypeDeb
: public debSLTypeDebian
461 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
462 string
const &Dist
, string
const &Section
,
463 std::map
<string
, string
> const &Options
) const
465 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
471 Label
= "Standard Debian binary tree";
475 class APT_HIDDEN debSLTypeDebSrc
: public debSLTypeDebian
479 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
480 string
const &Dist
, string
const &Section
,
481 std::map
<string
, string
> const &Options
) const
483 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
489 Label
= "Standard Debian source tree";
493 class APT_HIDDEN debSLTypeDebFile
: public pkgSourceList::Type
497 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
498 string
const &/*Dist*/, string
const &/*Section*/,
499 std::map
<string
, string
> const &/*Options*/) const
501 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
509 Label
= "Debian Deb File";
513 APT_HIDDEN debSLTypeDeb _apt_DebType
;
514 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType
;
515 APT_HIDDEN debSLTypeDebFile _apt_DebFileType
;