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::ArchiveOnly(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 template<typename CallC
>
94 void foreachTarget(std::string
const URI
, std::string
const Dist
,
95 std::map
<std::string
, std::vector
<debReleaseIndex::debSectionEntry
const *> > const &ArchEntries
,
98 bool const flatArchive
= (Dist
[Dist
.length() - 1] == '/');
99 std::string baseURI
= URI
;
106 baseURI
+= "dists/" + Dist
+ "/";
107 std::string
const Release
= (Dist
== "/") ? "" : Dist
;
108 std::string
const Site
= ::URI::ArchiveOnly(URI
);
109 std::vector
<std::string
> lang
= APT::Configuration::getLanguages(true);
111 lang
.push_back("none");
112 map
<string
, vector
<debReleaseIndex::debSectionEntry
const*> >::const_iterator
const src
= ArchEntries
.find("source");
113 if (src
!= ArchEntries
.end())
115 std::vector
<std::string
> const targets
= _config
->FindVector("APT::Acquire::Targets::deb-src", "", true);
116 for (std::vector
<std::string
>::const_iterator T
= targets
.begin(); T
!= targets
.end(); ++T
)
118 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X))
119 std::string
const MetaKey
= APT_T_CONFIG(flatArchive
? "flatMetaKey" : "MetaKey");
120 std::string
const ShortDesc
= APT_T_CONFIG("ShortDescription");
121 std::string
const LongDesc
= APT_T_CONFIG(flatArchive
? "flatDescription" : "Description");
122 bool const IsOptional
= _config
->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T
+ "::Optional", true);
127 vector
<debReleaseIndex::debSectionEntry
const*> const SectionEntries
= src
->second
;
128 for (vector
<debReleaseIndex::debSectionEntry
const*>::const_iterator I
= SectionEntries
.begin();
129 I
!= SectionEntries
.end(); ++I
)
131 for (vector
<std::string
>::const_iterator l
= lang
.begin(); l
!= lang
.end(); ++l
)
133 if (*l
== "none" && MetaKey
.find("$(LANGUAGE)") != std::string::npos
)
136 std::map
<std::string
, std::string
> Options
;
137 Options
.insert(std::make_pair("SITE", Site
));
138 Options
.insert(std::make_pair("RELEASE", Release
));
139 if (MetaKey
.find("$(COMPONENT)") != std::string::npos
)
140 Options
.insert(std::make_pair("COMPONENT", (*I
)->Section
));
141 if (MetaKey
.find("$(LANGUAGE)") != std::string::npos
)
142 Options
.insert(std::make_pair("LANGUAGE", *l
));
143 Options
.insert(std::make_pair("ARCHITECTURE", "source"));
144 Options
.insert(std::make_pair("BASE_URI", baseURI
));
145 Options
.insert(std::make_pair("REPO_URI", URI
));
146 Options
.insert(std::make_pair("TARGET_OF", "deb-src"));
147 Options
.insert(std::make_pair("CREATED_BY", *T
));
148 Call(MetaKey
, ShortDesc
, LongDesc
, IsOptional
, Options
);
150 if (MetaKey
.find("$(LANGUAGE)") == std::string::npos
)
154 if (MetaKey
.find("$(COMPONENT)") == std::string::npos
)
160 std::vector
<std::string
> const targets
= _config
->FindVector("APT::Acquire::Targets::deb", "", true);
161 for (std::vector
<std::string
>::const_iterator T
= targets
.begin(); T
!= targets
.end(); ++T
)
163 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X))
164 std::string
const MetaKey
= APT_T_CONFIG(flatArchive
? "flatMetaKey" : "MetaKey");
165 std::string
const ShortDesc
= APT_T_CONFIG("ShortDescription");
166 std::string
const LongDesc
= APT_T_CONFIG(flatArchive
? "flatDescription" : "Description");
167 bool const IsOptional
= _config
->FindB(std::string("APT::Acquire::Targets::deb::") + *T
+ "::Optional", true);
172 for (map
<string
, vector
<debReleaseIndex::debSectionEntry
const*> >::const_iterator a
= ArchEntries
.begin();
173 a
!= ArchEntries
.end(); ++a
)
175 if (a
->first
== "source")
178 for (vector
<const debReleaseIndex::debSectionEntry
*>::const_iterator I
= a
->second
.begin();
179 I
!= a
->second
.end(); ++I
) {
181 for (vector
<std::string
>::const_iterator l
= lang
.begin(); l
!= lang
.end(); ++l
)
183 if (*l
== "none" && MetaKey
.find("$(LANGUAGE)") != std::string::npos
)
186 std::map
<std::string
, std::string
> Options
;
187 Options
.insert(std::make_pair("SITE", Site
));
188 Options
.insert(std::make_pair("RELEASE", Release
));
189 if (MetaKey
.find("$(COMPONENT)") != std::string::npos
)
190 Options
.insert(std::make_pair("COMPONENT", (*I
)->Section
));
191 if (MetaKey
.find("$(LANGUAGE)") != std::string::npos
)
192 Options
.insert(std::make_pair("LANGUAGE", *l
));
193 if (MetaKey
.find("$(ARCHITECTURE)") != std::string::npos
)
194 Options
.insert(std::make_pair("ARCHITECTURE", a
->first
));
195 Options
.insert(std::make_pair("BASE_URI", baseURI
));
196 Options
.insert(std::make_pair("REPO_URI", URI
));
197 Options
.insert(std::make_pair("TARGET_OF", "deb"));
198 Options
.insert(std::make_pair("CREATED_BY", *T
));
199 Call(MetaKey
, ShortDesc
, LongDesc
, IsOptional
, Options
);
201 if (MetaKey
.find("$(LANGUAGE)") == std::string::npos
)
205 if (MetaKey
.find("$(COMPONENT)") == std::string::npos
)
209 if (MetaKey
.find("$(ARCHITECTURE)") == std::string::npos
)
216 struct ComputeIndexTargetsClass
218 vector
<IndexTarget
> IndexTargets
;
220 void operator()(std::string MetaKey
, std::string ShortDesc
, std::string LongDesc
,
221 bool const IsOptional
, std::map
<std::string
, std::string
> Options
)
223 for (std::map
<std::string
, std::string
>::const_iterator O
= Options
.begin(); O
!= Options
.end(); ++O
)
225 MetaKey
= SubstVar(MetaKey
, std::string("$(") + O
->first
+ ")", O
->second
);
226 ShortDesc
= SubstVar(ShortDesc
, std::string("$(") + O
->first
+ ")", O
->second
);
227 LongDesc
= SubstVar(LongDesc
, std::string("$(") + O
->first
+ ")", O
->second
);
233 Options
.find("BASE_URI")->second
+ MetaKey
,
237 IndexTargets
.push_back(Target
);
241 std::vector
<IndexTarget
> debReleaseIndex::GetIndexTargets() const
243 ComputeIndexTargetsClass comp
;
244 foreachTarget(URI
, Dist
, ArchEntries
, comp
);
245 return comp
.IndexTargets
;
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 std::vector
<IndexTarget
> const targets
= GetIndexTargets();
260 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>())
261 pkgAcqMetaBase
* const TransactionManager
= new pkgAcqMetaClearSig(Owner
,
262 APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
267 for (std::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 std::vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles()
311 Indexes
= new std::vector
<pkgIndexFile
*>();
312 std::vector
<IndexTarget
> const Targets
= GetIndexTargets();
313 bool const istrusted
= IsTrusted();
314 for (std::vector
<IndexTarget
>::const_iterator T
= Targets
.begin(); T
!= Targets
.end(); ++T
)
316 std::string
const TargetName
= T
->Option(IndexTarget::CREATED_BY
);
317 if (TargetName
== "Packages")
318 Indexes
->push_back(new debPackagesIndex(*T
, istrusted
));
319 else if (TargetName
== "Sources")
320 Indexes
->push_back(new debSourcesIndex(*T
, istrusted
));
321 else if (TargetName
== "Translations")
322 Indexes
->push_back(new debTranslationsIndex(*T
));
327 void debReleaseIndex::PushSectionEntry(vector
<string
> const &Archs
, const debSectionEntry
*Entry
) {
328 for (vector
<string
>::const_iterator a
= Archs
.begin();
329 a
!= Archs
.end(); ++a
)
330 ArchEntries
[*a
].push_back(new debSectionEntry(Entry
->Section
, Entry
->IsSrc
));
334 void debReleaseIndex::PushSectionEntry(string
const &Arch
, const debSectionEntry
*Entry
) {
335 ArchEntries
[Arch
].push_back(Entry
);
338 debReleaseIndex::debSectionEntry::debSectionEntry (string
const &Section
,
339 bool const &IsSrc
): Section(Section
), IsSrc(IsSrc
)
342 class APT_HIDDEN debSLTypeDebian
: public pkgSourceList::Type
346 bool CreateItemInternal(vector
<metaIndex
*> &List
, string
const &URI
,
347 string
const &Dist
, string
const &Section
,
348 bool const &IsSrc
, map
<string
, string
> const &Options
) const
350 // parse arch=, arch+= and arch-= settings
351 map
<string
, string
>::const_iterator arch
= Options
.find("arch");
352 vector
<string
> Archs
;
353 if (arch
!= Options
.end())
354 Archs
= VectorizeString(arch
->second
, ',');
356 Archs
= APT::Configuration::getArchitectures();
358 if ((arch
= Options
.find("arch+")) != Options
.end())
360 std::vector
<std::string
> const plusArch
= VectorizeString(arch
->second
, ',');
361 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
362 if (std::find(Archs
.begin(), Archs
.end(), *plus
) == Archs
.end())
363 Archs
.push_back(*plus
);
365 if ((arch
= Options
.find("arch-")) != Options
.end())
367 std::vector
<std::string
> const minusArch
= VectorizeString(arch
->second
, ',');
368 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
370 std::vector
<std::string
>::iterator kill
= std::find(Archs
.begin(), Archs
.end(), *minus
);
371 if (kill
!= Archs
.end())
376 map
<string
, string
>::const_iterator
const trusted
= Options
.find("trusted");
378 debReleaseIndex
*Deb
= NULL
;
379 for (vector
<metaIndex
*>::const_iterator I
= List
.begin();
380 I
!= List
.end(); ++I
)
382 // We only worry about debian entries here
383 if (strcmp((*I
)->GetType(), "deb") != 0)
386 /* This check insures that there will be only one Release file
387 queued for all the Packages files and Sources files it
389 if ((*I
)->GetURI() == URI
&& (*I
)->GetDist() == Dist
)
391 Deb
= dynamic_cast<debReleaseIndex
*>(*I
);
397 // No currently created Release file indexes this entry, so we create a new one.
400 Deb
= new debReleaseIndex(URI
, Dist
);
405 Deb
->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
408 if (Dist
[Dist
.size() - 1] == '/')
409 Deb
->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
411 Deb
->PushSectionEntry (Archs
, new debReleaseIndex::debSectionEntry(Section
, IsSrc
));
414 if (trusted
!= Options
.end())
415 Deb
->SetTrusted(StringToBool(trusted
->second
, false));
421 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
)
422 : metaIndex(DebFile
, "local-uri", "deb-dist"), DebFile(DebFile
)
424 DebIndex
= new debDebPkgFileIndex(DebFile
);
425 Indexes
= new vector
<pkgIndexFile
*>();
426 Indexes
->push_back(DebIndex
);
430 class APT_HIDDEN debSLTypeDeb
: public debSLTypeDebian
434 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
435 string
const &Dist
, string
const &Section
,
436 std::map
<string
, string
> const &Options
) const
438 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
444 Label
= "Standard Debian binary tree";
448 class APT_HIDDEN debSLTypeDebSrc
: public debSLTypeDebian
452 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
453 string
const &Dist
, string
const &Section
,
454 std::map
<string
, string
> const &Options
) const
456 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
462 Label
= "Standard Debian source tree";
466 class APT_HIDDEN debSLTypeDebFile
: public pkgSourceList::Type
470 bool CreateItem(vector
<metaIndex
*> &List
, string
const &URI
,
471 string
const &/*Dist*/, string
const &/*Section*/,
472 std::map
<string
, string
> const &/*Options*/) const
474 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
482 Label
= "Debian Deb File";
486 APT_HIDDEN debSLTypeDeb _apt_DebType
;
487 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType
;
488 APT_HIDDEN debSLTypeDebFile _apt_DebFileType
;