From 448c38bdcd72b52f11ec5f326f822cf57653f81c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 6 Jun 2015 12:28:00 +0200 Subject: rework hashsum verification in the acquire system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having every item having its own code to verify the file(s) it handles is an errorprune process and easy to break, especially if items move through various stages (download, uncompress, patching, …). With a giant rework we centralize (most of) the verification to have a better enforcement rate and (hopefully) less chance for bugs, but it breaks the ABI bigtime in exchange – and as we break it anyway, it is broken even harder. It shouldn't effect most frontends as they don't deal with the acquire system at all or implement their own items, but some do and will need to be patched (might be an opportunity to use apt on-board material). The theory is simple: Items implement methods to decide if hashes need to be checked (in this stage) and to return the expected hashes for this item (in this stage). The verification itself is done in worker message passing which has the benefit that a hashsum error is now a proper error for the acquire system rather than a Done() which is later revised to a Failed(). --- apt-pkg/deb/debindexfile.cc | 4 +-- apt-pkg/deb/debmetaindex.cc | 78 ++++++++++++++++++--------------------------- 2 files changed, 33 insertions(+), 49 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index d672b4fd8..185248619 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -742,13 +742,13 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const // and give it to the list parser debDebFileParser Parser(DebControl, DebFile); - if(Gen.SelectFile(DebFile, "local", *this) == false) + if(Gen.SelectFile(DebFile, "local", *this, pkgCache::Flag::LocalSource) == false) return _error->Error("Problem with SelectFile %s", DebFile.c_str()); pkgCache::PkgFileIterator File = Gen.GetCurFile(); File->Size = DebControl->Size(); File->mtime = DebControl->ModificationTime(); - + if (Gen.MergeList(Parser) == false) return _error->Error("Problem with MergeLister for %s", DebFile.c_str()); diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index aa2db8149..eb5e78e3b 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -192,11 +192,13 @@ vector * debReleaseIndex::ComputeIndexTargets() const { vector const SectionEntries = src->second; for (vector::const_iterator I = SectionEntries.begin(); I != SectionEntries.end(); ++I) { - IndexTarget * Target = new IndexTarget(); - Target->ShortDesc = "Sources"; - Target->MetaKey = SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section); - Target->URI = SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section); - Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section); + char const * const ShortDesc = "Sources"; + IndexTarget * const Target = new IndexTarget( + SourceIndexURISuffix(ShortDesc, (*I)->Section), + ShortDesc, + Info(ShortDesc, (*I)->Section), + SourceIndexURI(ShortDesc, (*I)->Section) + ); IndexTargets->push_back (Target); } } @@ -212,11 +214,13 @@ vector * debReleaseIndex::ComputeIndexTargets() const { continue; for (vector ::const_iterator I = a->second.begin(); I != a->second.end(); ++I) { - IndexTarget * Target = new IndexTarget(); - Target->ShortDesc = "Packages"; - Target->MetaKey = IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section, a->first); - Target->URI = IndexURI(Target->ShortDesc.c_str(), (*I)->Section, a->first); - Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section, a->first); + char const * const ShortDesc = "Packages"; + IndexTarget * const Target = new IndexTarget( + IndexURISuffix(ShortDesc, (*I)->Section, a->first), + ShortDesc, + Info (ShortDesc, (*I)->Section, a->first), + IndexURI(ShortDesc, (*I)->Section, a->first) + ); IndexTargets->push_back (Target); sections.insert((*I)->Section); } @@ -235,11 +239,13 @@ vector * debReleaseIndex::ComputeIndexTargets() const { s != sections.end(); ++s) { for (std::vector::const_iterator l = lang.begin(); l != lang.end(); ++l) { - IndexTarget * Target = new OptionalIndexTarget(); - Target->ShortDesc = "Translation-" + *l; - Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s); - Target->URI = TranslationIndexURI(l->c_str(), *s); - Target->Description = Info (Target->ShortDesc.c_str(), *s); + std::string const ShortDesc = "Translation-" + *l; + IndexTarget * const Target = new OptionalIndexTarget( + TranslationIndexURISuffix(l->c_str(), *s), + ShortDesc, + Info (ShortDesc.c_str(), *s), + TranslationIndexURI(l->c_str(), *s) + ); IndexTargets->push_back(Target); } } @@ -249,8 +255,6 @@ vector * debReleaseIndex::ComputeIndexTargets() const { /*}}}*/ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const { - bool const tryInRelease = _config->FindB("Acquire::TryInRelease", true); - indexRecords * const iR = new indexRecords(Dist); if (Trusted == ALWAYS_TRUSTED) iR->SetTrusted(true); @@ -258,37 +262,17 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const iR->SetTrusted(false); // special case for --print-uris - if (GetAll) { - vector *targets = ComputeIndexTargets(); - for (vector ::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) { - new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description, - (*Target)->ShortDesc, HashStringList()); - } - delete targets; - - // this is normally created in pkgAcqMetaSig, but if we run - // in --print-uris mode, we add it here - if (tryInRelease == false) - new pkgAcqMetaIndex(Owner, NULL, - MetaIndexURI("Release"), - MetaIndexInfo("Release"), "Release", - MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg", - ComputeIndexTargets(), - iR); + vector const * const targets = ComputeIndexTargets(); +#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X)) + pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, + APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), + targets, iR); +#undef APT_TARGET + if (GetAll) + { + for (vector ::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) + new pkgAcqIndex(Owner, TransactionManager, *Target); } - if (tryInRelease == true) - new pkgAcqMetaClearSig(Owner, - MetaIndexURI("InRelease"), MetaIndexInfo("InRelease"), "InRelease", - MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release", - MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg", - ComputeIndexTargets(), - iR); - else - new pkgAcqMetaIndex(Owner, NULL, - MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release", - MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg", - ComputeIndexTargets(), - iR); return true; } -- cgit v1.2.3 From 1e0f0f28e1025f42a8172eb72f3e87984eb2b939 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 9 Jun 2015 11:59:22 +0200 Subject: configureable acquire targets to download additional files First pass at making the acquire system capable of downloading files based on configuration rather than hardcoded entries. It is now possible to instruct 'deb' and 'deb-src' sources.list lines to download more than just Packages/Translation-* and Sources files. Details on how to do that can be found in the included documentation file. --- apt-pkg/deb/debmetaindex.cc | 317 +++++++++++++++++++++----------------------- apt-pkg/deb/debmetaindex.h | 8 -- 2 files changed, 150 insertions(+), 175 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index eb5e78e3b..8fef05ab0 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -23,25 +23,6 @@ using namespace std; -string debReleaseIndex::Info(const char *Type, string const &Section, string const &Arch) const -{ - string Info = ::URI::SiteOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Info += Dist; - } - else - { - Info += Dist + '/' + Section; - if (Arch.empty() != true) - Info += " " + Arch; - } - Info += " "; - Info += Type; - return Info; -} - string debReleaseIndex::MetaIndexInfo(const char *Type) const { string Info = ::URI::SiteOnly(URI) + ' '; @@ -92,81 +73,6 @@ std::string debReleaseIndex::LocalFileName() const return ""; } -string debReleaseIndex::IndexURISuffix(const char *Type, string const &Section, string const &Arch) const -{ - string Res =""; - if (Dist[Dist.size() - 1] != '/') - { - if (Arch == "native") - Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/'; - else - Res += Section + "/binary-" + Arch + '/'; - } - return Res + Type; -} - - -string debReleaseIndex::IndexURI(const char *Type, string const &Section, string const &Arch) const -{ - if (Dist[Dist.size() - 1] == '/') - { - string Res; - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - return Res + Type; - } - else - return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section, Arch); - } - -string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string &Section) const -{ - string Res =""; - if (Dist[Dist.size() - 1] != '/') - Res += Section + "/source/"; - return Res + Type; -} - -string debReleaseIndex::SourceIndexURI(const char *Type, const string &Section) const -{ - string Res; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - return Res + Type; - } - else - return URI + "dists/" + Dist + "/" + SourceIndexURISuffix(Type, Section); -} - -string debReleaseIndex::TranslationIndexURISuffix(const char *Type, const string &Section) const -{ - string Res =""; - if (Dist[Dist.size() - 1] != '/') - Res += Section + "/i18n/Translation-"; - return Res + Type; -} - -string debReleaseIndex::TranslationIndexURI(const char *Type, const string &Section) const -{ - string Res; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - return Res + Type; - } - else - return URI + "dists/" + Dist + "/" + TranslationIndexURISuffix(Type, Section); -} - debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) : metaIndex(URI, Dist, "deb"), Trusted(CHECK_TRUST) {} @@ -184,73 +90,161 @@ debReleaseIndex::~debReleaseIndex() { delete *S; } -vector * debReleaseIndex::ComputeIndexTargets() const { - vector * IndexTargets = new vector ; +vector * debReleaseIndex::ComputeIndexTargets() const +{ + vector * IndexTargets = new vector ; - map >::const_iterator const src = ArchEntries.find("source"); - if (src != ArchEntries.end()) { - vector const SectionEntries = src->second; - for (vector::const_iterator I = SectionEntries.begin(); - I != SectionEntries.end(); ++I) { - char const * const ShortDesc = "Sources"; - IndexTarget * const Target = new IndexTarget( - SourceIndexURISuffix(ShortDesc, (*I)->Section), - ShortDesc, - Info(ShortDesc, (*I)->Section), - SourceIndexURI(ShortDesc, (*I)->Section) - ); - IndexTargets->push_back (Target); - } - } + bool const flatArchive = (Dist[Dist.length() - 1] == '/'); + std::string baseURI = URI; + if (flatArchive) + { + if (Dist != "/") + baseURI += Dist; + } + else + baseURI += "dists/" + Dist + "/"; + std::string const Release = (Dist == "/") ? "" : Dist; + std::string const Site = ::URI::SiteOnly(URI); + std::vector lang = APT::Configuration::getLanguages(true); + if (lang.empty()) + lang.push_back("none"); + map >::const_iterator const src = ArchEntries.find("source"); + if (src != ArchEntries.end()) + { + std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb-src", "", true); + for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) + { +#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X)) + std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI"); + std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); + std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); + bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true); +#undef APT_T_CONFIG + if (URI.empty()) + continue; - // Only source release - if (IndexTargets->empty() == false && ArchEntries.size() == 1) - return IndexTargets; + vector const SectionEntries = src->second; + for (vector::const_iterator I = SectionEntries.begin(); + I != SectionEntries.end(); ++I) + { + for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) + { + if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos) + continue; + + struct SubstVar subst[] = { + { "$(SITE)", &Site }, + { "$(RELEASE)", &Release }, + { "$(COMPONENT)", &((*I)->Section) }, + { "$(LANGUAGE)", &(*l) }, + { NULL, NULL } + }; + std::string const name = SubstVar(URI, subst); + IndexTarget * Target; + if (IsOptional == true) + { + Target = new OptionalIndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + else + { + Target = new IndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + IndexTargets->push_back(Target); + + if (URI.find("$(LANGUAGE)") == std::string::npos) + break; + } - std::set sections; - for (map >::const_iterator a = ArchEntries.begin(); - a != ArchEntries.end(); ++a) { - if (a->first == "source") - continue; - for (vector ::const_iterator I = a->second.begin(); - I != a->second.end(); ++I) { - char const * const ShortDesc = "Packages"; - IndexTarget * const Target = new IndexTarget( - IndexURISuffix(ShortDesc, (*I)->Section, a->first), - ShortDesc, - Info (ShortDesc, (*I)->Section, a->first), - IndexURI(ShortDesc, (*I)->Section, a->first) - ); - IndexTargets->push_back (Target); - sections.insert((*I)->Section); - } - } + if (URI.find("$(COMPONENT)") == std::string::npos) + break; + } + } + } - std::vector lang = APT::Configuration::getLanguages(true); - std::vector::iterator lend = std::remove(lang.begin(), lang.end(), "none"); - if (lend != lang.end()) - lang.erase(lend); - - if (lang.empty() == true) - return IndexTargets; - - // get the Translation-* files, later we will skip download of non-existent if we have an index - for (std::set::const_iterator s = sections.begin(); - s != sections.end(); ++s) { - for (std::vector::const_iterator l = lang.begin(); - l != lang.end(); ++l) { - std::string const ShortDesc = "Translation-" + *l; - IndexTarget * const Target = new OptionalIndexTarget( - TranslationIndexURISuffix(l->c_str(), *s), - ShortDesc, - Info (ShortDesc.c_str(), *s), - TranslationIndexURI(l->c_str(), *s) - ); - IndexTargets->push_back(Target); - } - } + // Only source release + if (IndexTargets->empty() == false && ArchEntries.size() == 1) + return IndexTargets; - return IndexTargets; + std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb", "", true); + for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) + { +#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X)) + std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI"); + std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); + std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); + bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb::") + *T + "::Optional", true); +#undef APT_T_CONFIG + if (URI.empty()) + continue; + + for (map >::const_iterator a = ArchEntries.begin(); + a != ArchEntries.end(); ++a) + { + if (a->first == "source") + continue; + + for (vector ::const_iterator I = a->second.begin(); + I != a->second.end(); ++I) { + + for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) + { + if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos) + continue; + + struct SubstVar subst[] = { + { "$(SITE)", &Site }, + { "$(RELEASE)", &Release }, + { "$(COMPONENT)", &((*I)->Section) }, + { "$(LANGUAGE)", &(*l) }, + { "$(ARCHITECTURE)", &(a->first) }, + { NULL, NULL } + }; + std::string const name = SubstVar(URI, subst); + IndexTarget * Target; + if (IsOptional == true) + { + Target = new OptionalIndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + else + { + Target = new IndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + IndexTargets->push_back(Target); + + if (URI.find("$(LANGUAGE)") == std::string::npos) + break; + } + + if (URI.find("$(COMPONENT)") == std::string::npos) + break; + } + + if (URI.find("$(ARCHITECTURE)") == std::string::npos) + break; + } + } + + return IndexTargets; } /*}}}*/ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const @@ -361,17 +355,6 @@ void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry ArchEntries[Arch].push_back(Entry); } -void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry) { - if (Entry->IsSrc == true) - PushSectionEntry("source", Entry); - else { - for (map >::iterator a = ArchEntries.begin(); - a != ArchEntries.end(); ++a) { - a->second.push_back(Entry); - } - } -} - debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section, bool const &IsSrc): Section(Section), IsSrc(IsSrc) {} diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 94d005760..e1c1d91ef 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -47,7 +47,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; std::vector * ComputeIndexTargets() const; - std::string Info(const char *Type, std::string const &Section, std::string const &Arch="") const; std::string MetaIndexInfo(const char *Type) const; std::string MetaIndexFile(const char *Types) const; @@ -58,12 +57,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { #endif std::string LocalFileName() const; - std::string IndexURI(const char *Type, std::string const &Section, std::string const &Arch="native") const; - std::string IndexURISuffix(const char *Type, std::string const &Section, std::string const &Arch="native") const; - std::string SourceIndexURI(const char *Type, const std::string &Section) const; - std::string SourceIndexURISuffix(const char *Type, const std::string &Section) const; - std::string TranslationIndexURI(const char *Type, const std::string &Section) const; - std::string TranslationIndexURISuffix(const char *Type, const std::string &Section) const; virtual std::vector *GetIndexFiles(); void SetTrusted(bool const Trusted); @@ -71,7 +64,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { void PushSectionEntry(std::vector const &Archs, const debSectionEntry *Entry); void PushSectionEntry(std::string const &Arch, const debSectionEntry *Entry); - void PushSectionEntry(const debSectionEntry *Entry); }; class APT_HIDDEN debDebFileMetaIndex : public metaIndex -- cgit v1.2.3 From 59148d9630bbbd53c6aa10da0fcdbd579797502a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 10 Jun 2015 19:22:41 +0200 Subject: abstract the code to iterate over all targets a bit We have two places in the code which need to iterate over targets and do certain things with it. The first one is actually creating these targets for download and the second instance pepares certain targets for reading. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 197 +++++++++++++++++++++++--------------------- 1 file changed, 103 insertions(+), 94 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 8fef05ab0..c35f3b0a4 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -90,10 +90,11 @@ debReleaseIndex::~debReleaseIndex() { delete *S; } -vector * debReleaseIndex::ComputeIndexTargets() const +template +void foreachTarget(std::string const URI, std::string const Dist, + std::map > const &ArchEntries, + CallC Call) { - vector * IndexTargets = new vector ; - bool const flatArchive = (Dist[Dist.length() - 1] == '/'); std::string baseURI = URI; if (flatArchive) @@ -108,7 +109,7 @@ vector * debReleaseIndex::ComputeIndexTargets() const std::vector lang = APT::Configuration::getLanguages(true); if (lang.empty()) lang.push_back("none"); - map >::const_iterator const src = ArchEntries.find("source"); + map >::const_iterator const src = ArchEntries.find("source"); if (src != ArchEntries.end()) { std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb-src", "", true); @@ -123,8 +124,8 @@ vector * debReleaseIndex::ComputeIndexTargets() const if (URI.empty()) continue; - vector const SectionEntries = src->second; - for (vector::const_iterator I = SectionEntries.begin(); + vector const SectionEntries = src->second; + for (vector::const_iterator I = SectionEntries.begin(); I != SectionEntries.end(); ++I) { for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) @@ -139,27 +140,7 @@ vector * debReleaseIndex::ComputeIndexTargets() const { "$(LANGUAGE)", &(*l) }, { NULL, NULL } }; - std::string const name = SubstVar(URI, subst); - IndexTarget * Target; - if (IsOptional == true) - { - Target = new OptionalIndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); - } - else - { - Target = new IndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); - } - IndexTargets->push_back(Target); + Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst); if (URI.find("$(LANGUAGE)") == std::string::npos) break; @@ -171,10 +152,6 @@ vector * debReleaseIndex::ComputeIndexTargets() const } } - // Only source release - if (IndexTargets->empty() == false && ArchEntries.size() == 1) - return IndexTargets; - std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb", "", true); for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) { @@ -187,13 +164,13 @@ vector * debReleaseIndex::ComputeIndexTargets() const if (URI.empty()) continue; - for (map >::const_iterator a = ArchEntries.begin(); + for (map >::const_iterator a = ArchEntries.begin(); a != ArchEntries.end(); ++a) { if (a->first == "source") continue; - for (vector ::const_iterator I = a->second.begin(); + for (vector ::const_iterator I = a->second.begin(); I != a->second.end(); ++I) { for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) @@ -209,27 +186,7 @@ vector * debReleaseIndex::ComputeIndexTargets() const { "$(ARCHITECTURE)", &(a->first) }, { NULL, NULL } }; - std::string const name = SubstVar(URI, subst); - IndexTarget * Target; - if (IsOptional == true) - { - Target = new OptionalIndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); - } - else - { - Target = new IndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); - } - IndexTargets->push_back(Target); + Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst); if (URI.find("$(LANGUAGE)") == std::string::npos) break; @@ -243,9 +200,51 @@ vector * debReleaseIndex::ComputeIndexTargets() const break; } } +} + + +struct ComputeIndexTargetsClass +{ + vector * const IndexTargets; + + void operator()(std::string const &baseURI, std::string const &/*TargetName*/, + std::string const &URI, std::string const &ShortDesc, std::string const &LongDesc, + bool const IsOptional, struct SubstVar const * const subst) + { + std::string const name = SubstVar(URI, subst); + IndexTarget * Target; + if (IsOptional == true) + { + Target = new OptionalIndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + else + { + Target = new IndexTarget( + name, + SubstVar(ShortDesc, subst), + SubstVar(LongDesc, subst), + baseURI + name + ); + } + IndexTargets->push_back(Target); + } - return IndexTargets; + ComputeIndexTargetsClass() : IndexTargets(new vector ) {} +}; + +vector * debReleaseIndex::ComputeIndexTargets() const +{ + ComputeIndexTargetsClass comp; + foreachTarget(URI, Dist, ArchEntries, comp); + return comp.IndexTargets; } + + /*}}}*/ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const { @@ -303,45 +302,55 @@ bool debReleaseIndex::IsTrusted() const return FileExists(VerifiedSigFile); } -vector *debReleaseIndex::GetIndexFiles() { - if (Indexes != NULL) - return Indexes; - - Indexes = new vector ; - map >::const_iterator const src = ArchEntries.find("source"); - if (src != ArchEntries.end()) { - vector const SectionEntries = src->second; - for (vector::const_iterator I = SectionEntries.begin(); - I != SectionEntries.end(); ++I) - Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted())); - } - - // Only source release - if (Indexes->empty() == false && ArchEntries.size() == 1) - return Indexes; - - std::vector const lang = APT::Configuration::getLanguages(true); - map > sections; - for (map >::const_iterator a = ArchEntries.begin(); - a != ArchEntries.end(); ++a) { - if (a->first == "source") - continue; - for (vector::const_iterator I = a->second.begin(); - I != a->second.end(); ++I) { - Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first)); - sections[(*I)->Section].insert(lang.begin(), lang.end()); - } - } - - for (map >::const_iterator s = sections.begin(); - s != sections.end(); ++s) - for (set::const_iterator l = s->second.begin(); - l != s->second.end(); ++l) { - if (*l == "none") continue; - Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str())); - } - - return Indexes; +struct GetIndexFilesClass +{ + vector * const Indexes; + std::string const URI; + std::string const Release; + bool const IsTrusted; + + void operator()(std::string const &/*baseURI*/, std::string const &TargetName, + std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/, + bool const /*IsOptional*/, struct SubstVar const * const subst) + { + if (TargetName == "Packages") + { + Indexes->push_back(new debPackagesIndex( + URI, + Release, + SubstVar("$(COMPONENT)", subst), + IsTrusted, + SubstVar("$(ARCHITECTURE)", subst) + )); + } + else if (TargetName == "Sources") + Indexes->push_back(new debSourcesIndex( + URI, + Release, + SubstVar("$(COMPONENT)", subst), + IsTrusted + )); + else if (TargetName == "Translations") + Indexes->push_back(new debTranslationsIndex( + URI, + Release, + SubstVar("$(COMPONENT)", subst), + SubstVar("$(LANGUAGE)", subst) + )); + } + + GetIndexFilesClass(std::string const &URI, std::string const &Release, bool const IsTrusted) : + Indexes(new vector ), URI(URI), Release(Release), IsTrusted(IsTrusted) {} +}; + +std::vector *debReleaseIndex::GetIndexFiles() +{ + if (Indexes != NULL) + return Indexes; + + GetIndexFilesClass comp(URI, Dist, IsTrusted()); + foreachTarget(URI, Dist, ArchEntries, comp); + return Indexes = comp.Indexes; } void debReleaseIndex::PushSectionEntry(vector const &Archs, const debSectionEntry *Entry) { -- cgit v1.2.3 From d3a869e35503638e3483228fbfc95b7143568ad0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 10 Jun 2015 21:24:47 +0200 Subject: store all targets data in IndexTarget struct We still need an API for the targets, so slowly prepare the IndexTargets to let them take this job. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 114 +++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index c35f3b0a4..f038f12f5 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -116,12 +116,12 @@ void foreachTarget(std::string const URI, std::string const Dist, for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) { #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X)) - std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI"); + std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true); #undef APT_T_CONFIG - if (URI.empty()) + if (MetaKey.empty()) continue; vector const SectionEntries = src->second; @@ -130,23 +130,24 @@ void foreachTarget(std::string const URI, std::string const Dist, { for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) { - if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos) + if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) continue; - struct SubstVar subst[] = { - { "$(SITE)", &Site }, - { "$(RELEASE)", &Release }, - { "$(COMPONENT)", &((*I)->Section) }, - { "$(LANGUAGE)", &(*l) }, - { NULL, NULL } - }; - Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst); - - if (URI.find("$(LANGUAGE)") == std::string::npos) + std::map Options; + Options.insert(std::make_pair("SITE", Site)); + Options.insert(std::make_pair("RELEASE", Release)); + Options.insert(std::make_pair("COMPONENT", (*I)->Section)); + Options.insert(std::make_pair("LANGUAGE", *l)); + Options.insert(std::make_pair("ARCHITECTURE", "source")); + Options.insert(std::make_pair("BASE_URI", baseURI)); + Options.insert(std::make_pair("CREATED_BY", *T)); + Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); + + if (MetaKey.find("$(LANGUAGE)") == std::string::npos) break; } - if (URI.find("$(COMPONENT)") == std::string::npos) + if (MetaKey.find("$(COMPONENT)") == std::string::npos) break; } } @@ -156,12 +157,12 @@ void foreachTarget(std::string const URI, std::string const Dist, for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) { #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X)) - std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI"); + std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb::") + *T + "::Optional", true); #undef APT_T_CONFIG - if (URI.empty()) + if (MetaKey.empty()) continue; for (map >::const_iterator a = ArchEntries.begin(); @@ -175,28 +176,28 @@ void foreachTarget(std::string const URI, std::string const Dist, for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) { - if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos) + if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) continue; - struct SubstVar subst[] = { - { "$(SITE)", &Site }, - { "$(RELEASE)", &Release }, - { "$(COMPONENT)", &((*I)->Section) }, - { "$(LANGUAGE)", &(*l) }, - { "$(ARCHITECTURE)", &(a->first) }, - { NULL, NULL } - }; - Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst); - - if (URI.find("$(LANGUAGE)") == std::string::npos) + std::map Options; + Options.insert(std::make_pair("SITE", Site)); + Options.insert(std::make_pair("RELEASE", Release)); + Options.insert(std::make_pair("COMPONENT", (*I)->Section)); + Options.insert(std::make_pair("LANGUAGE", *l)); + Options.insert(std::make_pair("ARCHITECTURE", a->first)); + Options.insert(std::make_pair("BASE_URI", baseURI)); + Options.insert(std::make_pair("CREATED_BY", *T)); + Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); + + if (MetaKey.find("$(LANGUAGE)") == std::string::npos) break; } - if (URI.find("$(COMPONENT)") == std::string::npos) + if (MetaKey.find("$(COMPONENT)") == std::string::npos) break; } - if (URI.find("$(ARCHITECTURE)") == std::string::npos) + if (MetaKey.find("$(ARCHITECTURE)") == std::string::npos) break; } } @@ -207,30 +208,23 @@ struct ComputeIndexTargetsClass { vector * const IndexTargets; - void operator()(std::string const &baseURI, std::string const &/*TargetName*/, - std::string const &URI, std::string const &ShortDesc, std::string const &LongDesc, - bool const IsOptional, struct SubstVar const * const subst) + void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc, + bool const IsOptional, std::map Options) { - std::string const name = SubstVar(URI, subst); - IndexTarget * Target; - if (IsOptional == true) - { - Target = new OptionalIndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); - } - else + for (std::map::const_iterator O = Options.begin(); O != Options.end(); ++O) { - Target = new IndexTarget( - name, - SubstVar(ShortDesc, subst), - SubstVar(LongDesc, subst), - baseURI + name - ); + MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second); + ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); + LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); } + IndexTarget * Target = new IndexTarget( + MetaKey, + ShortDesc, + LongDesc, + Options.find("BASE_URI")->second + MetaKey, + IsOptional, + Options + ); IndexTargets->push_back(Target); } @@ -256,7 +250,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const // special case for --print-uris vector const * const targets = ComputeIndexTargets(); -#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X)) +#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), targets, iR); @@ -309,33 +303,33 @@ struct GetIndexFilesClass std::string const Release; bool const IsTrusted; - void operator()(std::string const &/*baseURI*/, std::string const &TargetName, - std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/, - bool const /*IsOptional*/, struct SubstVar const * const subst) + void operator()(std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/, + bool const /*IsOptional*/, std::map Options) { + std::string const TargetName = Options.find("CREATED_BY")->second; if (TargetName == "Packages") { Indexes->push_back(new debPackagesIndex( URI, Release, - SubstVar("$(COMPONENT)", subst), + Options.find("COMPONENT")->second, IsTrusted, - SubstVar("$(ARCHITECTURE)", subst) + Options.find("ARCHITECTURE")->second )); } else if (TargetName == "Sources") Indexes->push_back(new debSourcesIndex( URI, Release, - SubstVar("$(COMPONENT)", subst), + Options.find("COMPONENT")->second, IsTrusted )); else if (TargetName == "Translations") Indexes->push_back(new debTranslationsIndex( URI, Release, - SubstVar("$(COMPONENT)", subst), - SubstVar("$(LANGUAGE)", subst) + Options.find("COMPONENT")->second, + Options.find("LANGUAGE")->second )); } -- cgit v1.2.3 From dcbbb14df8c9a8a146697720874e9425c4b33792 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 10 Jun 2015 22:10:48 +0200 Subject: stop using IndexTarget pointers which are never freed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creating and passing around a bunch of pointers of IndexTargets (and of a vector of pointers of IndexTargets) is probably done to avoid the 'costly' copy of container, but we are really not in a timecritical operation here and move semantics will help us even further in the future. On the other hand we never do a proper cleanup of these pointers, which is very dirty, even if structures aren't that big… The changes will effecting many items only effect our own hidden class, so we can do that without fearing breaking interfaces or anything. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 16 +++++++--------- apt-pkg/deb/debmetaindex.h | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index f038f12f5..44d66a725 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -93,7 +93,7 @@ debReleaseIndex::~debReleaseIndex() { template void foreachTarget(std::string const URI, std::string const Dist, std::map > const &ArchEntries, - CallC Call) + CallC &Call) { bool const flatArchive = (Dist[Dist.length() - 1] == '/'); std::string baseURI = URI; @@ -206,7 +206,7 @@ void foreachTarget(std::string const URI, std::string const Dist, struct ComputeIndexTargetsClass { - vector * const IndexTargets; + vector IndexTargets; void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc, bool const IsOptional, std::map Options) @@ -217,7 +217,7 @@ struct ComputeIndexTargetsClass ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); } - IndexTarget * Target = new IndexTarget( + IndexTarget Target( MetaKey, ShortDesc, LongDesc, @@ -225,13 +225,11 @@ struct ComputeIndexTargetsClass IsOptional, Options ); - IndexTargets->push_back(Target); + IndexTargets.push_back(Target); } - - ComputeIndexTargetsClass() : IndexTargets(new vector ) {} }; -vector * debReleaseIndex::ComputeIndexTargets() const +std::vector debReleaseIndex::ComputeIndexTargets() const { ComputeIndexTargetsClass comp; foreachTarget(URI, Dist, ArchEntries, comp); @@ -249,7 +247,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const iR->SetTrusted(false); // special case for --print-uris - vector const * const targets = ComputeIndexTargets(); + std::vector const targets = ComputeIndexTargets(); #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), @@ -257,7 +255,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const #undef APT_TARGET if (GetAll) { - for (vector ::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) + for (std::vector::const_iterator Target = targets.begin(); Target != targets.end(); ++Target) new pkgAcqIndex(Owner, TransactionManager, *Target); } diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index e1c1d91ef..4e630cf5d 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -46,7 +46,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; - std::vector * ComputeIndexTargets() const; + std::vector ComputeIndexTargets() const; std::string MetaIndexInfo(const char *Type) const; std::string MetaIndexFile(const char *Types) const; -- cgit v1.2.3 From 261727f05ca7ff7d9d6d9b8927cb5c6ad293ebce Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 10 Jun 2015 23:53:36 +0200 Subject: rename Calculate- to GetIndexTargets and use it as official API We need a general way to get from a sources.list entry to IndexTargets and with this change we can move from pkgSourceList over the list of metaIndexes it includes to the IndexTargets each metaIndex can have. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 37 +++++++++++++++---------------------- apt-pkg/deb/debmetaindex.h | 5 ++++- 2 files changed, 19 insertions(+), 23 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 44d66a725..e1f86d20f 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -229,7 +229,7 @@ struct ComputeIndexTargetsClass } }; -std::vector debReleaseIndex::ComputeIndexTargets() const +std::vector debReleaseIndex::GetIndexTargets() const { ComputeIndexTargetsClass comp; foreachTarget(URI, Dist, ArchEntries, comp); @@ -247,7 +247,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const iR->SetTrusted(false); // special case for --print-uris - std::vector const targets = ComputeIndexTargets(); + std::vector const targets = GetIndexTargets(); #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), @@ -396,6 +396,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type map::const_iterator const trusted = Options.find("trusted"); + debReleaseIndex *Deb = NULL; for (vector::const_iterator I = List.begin(); I != List.end(); ++I) { @@ -403,34 +404,23 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type if (strcmp((*I)->GetType(), "deb") != 0) continue; - debReleaseIndex *Deb = (debReleaseIndex *) (*I); - if (trusted != Options.end()) - Deb->SetTrusted(StringToBool(trusted->second, false)); - /* This check insures that there will be only one Release file queued for all the Packages files and Sources files it corresponds to. */ - if (Deb->GetURI() == URI && Deb->GetDist() == Dist) + if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist) { - if (IsSrc == true) - Deb->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); - else - { - if (Dist[Dist.size() - 1] == '/') - Deb->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section, IsSrc)); - else - Deb->PushSectionEntry(Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); - } - return true; + Deb = dynamic_cast(*I); + if (Deb != NULL) + break; } } // No currently created Release file indexes this entry, so we create a new one. - debReleaseIndex *Deb; - if (trusted != Options.end()) - Deb = new debReleaseIndex(URI, Dist, StringToBool(trusted->second, false)); - else + if (Deb == NULL) + { Deb = new debReleaseIndex(URI, Dist); + List.push_back(Deb); + } if (IsSrc == true) Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); @@ -441,7 +431,10 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type else Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); } - List.push_back(Deb); + + if (trusted != Options.end()) + Deb->SetTrusted(StringToBool(trusted->second, false)); + return true; } }; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 4e630cf5d..0b1b08432 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -46,7 +46,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; - std::vector ComputeIndexTargets() const; + virtual std::vector GetIndexTargets() const; std::string MetaIndexInfo(const char *Type) const; std::string MetaIndexFile(const char *Types) const; @@ -78,6 +78,9 @@ class APT_HIDDEN debDebFileMetaIndex : public metaIndex virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) const { return true; } + virtual std::vector GetIndexTargets() const { + return std::vector(); + } virtual std::vector *GetIndexFiles() { return Indexes; } -- cgit v1.2.3 From 1da3b7b8e15b642135b54684e70a0c271471f07a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 10:56:31 +0200 Subject: show URI.Path in all acquire item descriptions It is a rather strange sight that index items use SiteOnly which strips the Path, while e.g. deb files are downloaded with NoUserPassword which does not. Important to note here is that for the file transport Path is pretty important as there is no Host which would be displayed by Site, which always resulted in "interesting" unspecific errors for "file:". Adding a 'middle' ground between the two which does show the Path but potentially modifies it (it strips a pending / at the end if existing) solves this "file:" issue, syncs the output and in the end helps to identify which file is meant exactly in progress output and co as a single site can have multiple repositories in different paths. --- apt-pkg/deb/debindexfile.cc | 10 +++++----- apt-pkg/deb/debmetaindex.cc | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 185248619..20bf5ae50 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -57,7 +57,7 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const { string Res; - Res = ::URI::NoUserPassword(URI) + ' '; + Res = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -116,7 +116,7 @@ string debSourcesIndex::Describe(bool Short) const /* */ string debSourcesIndex::Info(const char *Type) const { - string Info = ::URI::NoUserPassword(URI) + ' '; + string Info = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -210,7 +210,7 @@ debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string /* This is a shorter version that is designed to be < 60 chars or so */ string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const { - string Res = ::URI::NoUserPassword(URI) + ' '; + string Res = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -248,7 +248,7 @@ string debPackagesIndex::Describe(bool Short) const /* */ string debPackagesIndex::Info(const char *Type) const { - string Info = ::URI::NoUserPassword(URI) + ' '; + string Info = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -473,7 +473,7 @@ string debTranslationsIndex::Describe(bool Short) const /* */ string debTranslationsIndex::Info(const char *Type) const { - string Info = ::URI::NoUserPassword(URI) + ' '; + string Info = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index e1f86d20f..d4e340be0 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -25,7 +25,7 @@ using namespace std; string debReleaseIndex::MetaIndexInfo(const char *Type) const { - string Info = ::URI::SiteOnly(URI) + ' '; + string Info = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -105,7 +105,7 @@ void foreachTarget(std::string const URI, std::string const Dist, else baseURI += "dists/" + Dist + "/"; std::string const Release = (Dist == "/") ? "" : Dist; - std::string const Site = ::URI::SiteOnly(URI); + std::string const Site = ::URI::ArchiveOnly(URI); std::vector lang = APT::Configuration::getLanguages(true); if (lang.empty()) lang.push_back("none"); -- cgit v1.2.3 From e3c1cfc767f17f5e9b2cd99f2658db3d6ac8edd9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 11:38:04 +0200 Subject: use IndexTarget to get to IndexFile Removes a bunch of duplicated code in the deb-specific parts. Especially the Description part is now handled centrally by IndexTarget instead of being duplicated to the derivations of IndexFile. Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 381 ++++---------------------------------------- apt-pkg/deb/debindexfile.h | 84 ++-------- apt-pkg/deb/debmetaindex.cc | 56 ++----- 3 files changed, 62 insertions(+), 459 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 20bf5ae50..3e60423ff 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -44,8 +44,8 @@ using std::string; // SourcesIndex::debSourcesIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trusted) : - pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section) +debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) : + pkgIndexTargetFile(Target, Trusted) { } /*}}}*/ @@ -56,16 +56,9 @@ debSourcesIndex::debSourcesIndex(string URI,string Dist,string Section,bool Trus string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const { - string Res; - Res = ::URI::ArchiveOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res += Dist; - } - else - Res += Dist + '/' + Section; - + string Res = Target.Description; + Res.erase(Target.Description.rfind(' ')); + Res += " "; Res += Record.Package(); Res += " "; @@ -80,129 +73,19 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, /* */ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const { - string SourcesURI = _config->FindDir("Dir::State::lists") + - URItoFileName(IndexURI("Sources")); - - std::vector types = APT::Configuration::getCompressionTypes(); - for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) - { - string p; - p = SourcesURI + '.' + *t; - if (FileExists(p)) - return new debSrcRecordParser(p, this); - } + string const SourcesURI = IndexFileName(); if (FileExists(SourcesURI)) return new debSrcRecordParser(SourcesURI, this); return NULL; } /*}}}*/ -// SourcesIndex::Describe - Give a descriptive path to the index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debSourcesIndex::Describe(bool Short) const -{ - char S[300]; - if (Short == true) - snprintf(S,sizeof(S),"%s",Info("Sources").c_str()); - else - snprintf(S,sizeof(S),"%s (%s)",Info("Sources").c_str(), - IndexFile("Sources").c_str()); - - return S; -} - /*}}}*/ -// SourcesIndex::Info - One liner describing the index URI /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debSourcesIndex::Info(const char *Type) const -{ - string Info = ::URI::ArchiveOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Info += Dist; - } - else - Info += Dist + '/' + Section; - Info += " "; - Info += Type; - return Info; -} - /*}}}*/ -// SourcesIndex::Index* - Return the URI to the index files /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debSourcesIndex::IndexFile(const char *Type) const -{ - string s = URItoFileName(IndexURI(Type)); - - std::vector types = APT::Configuration::getCompressionTypes(); - for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) - { - string p = s + '.' + *t; - if (FileExists(p)) - return p; - } - return s; -} - -string debSourcesIndex::IndexURI(const char *Type) const -{ - string Res; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - } - else - Res = URI + "dists/" + Dist + '/' + Section + - "/source/"; - - Res += Type; - return Res; -} - /*}}}*/ -// SourcesIndex::Exists - Check if the index is available /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debSourcesIndex::Exists() const -{ - return FileExists(IndexFile("Sources")); -} - /*}}}*/ -// SourcesIndex::Size - Return the size of the index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -unsigned long debSourcesIndex::Size() const -{ - unsigned long size = 0; - - /* we need to ignore errors here; if the lists are absent, just return 0 */ - _error->PushToStack(); - - FileFd f(IndexFile("Sources"), FileFd::ReadOnly, FileFd::Extension); - if (!f.Failed()) - size = f.Size(); - - if (_error->PendingError() == true) - size = 0; - _error->RevertToStack(); - - return size; -} - /*}}}*/ // PackagesIndex::debPackagesIndex - Contructor /*{{{*/ // --------------------------------------------------------------------- /* */ -debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string const &Section, - bool const &Trusted, string const &Arch) : - pkgIndexFile(Trusted), URI(URI), Dist(Dist), Section(Section), Architecture(Arch) +debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) : + pkgIndexTargetFile(Target, Trusted) { - if (Architecture == "native") - Architecture = _config->Find("APT::Architecture"); } /*}}}*/ // PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/ @@ -210,135 +93,40 @@ debPackagesIndex::debPackagesIndex(string const &URI, string const &Dist, string /* This is a shorter version that is designed to be < 60 chars or so */ string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const { - string Res = ::URI::ArchiveOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res += Dist; - } - else - Res += Dist + '/' + Section; - + std::string const Dist = Target.Option("RELEASE"); + string Res = Target.Option("SITE") + " " + Dist; + std::string const Component = Target.Option("COMPONENT"); + if (Component.empty() == false) + Res += "/" + Component; + Res += " "; Res += Ver.ParentPkg().Name(); Res += " "; - if (Dist[Dist.size() - 1] != '/') + if (Dist.empty() == false && Dist[Dist.size() - 1] != '/') Res.append(Ver.Arch()).append(" "); Res += Ver.VerStr(); return Res; } /*}}}*/ -// PackagesIndex::Describe - Give a descriptive path to the index /*{{{*/ -// --------------------------------------------------------------------- -/* This should help the user find the index in the sources.list and - in the filesystem for problem solving */ -string debPackagesIndex::Describe(bool Short) const -{ - char S[300]; - if (Short == true) - snprintf(S,sizeof(S),"%s",Info("Packages").c_str()); - else - snprintf(S,sizeof(S),"%s (%s)",Info("Packages").c_str(), - IndexFile("Packages").c_str()); - return S; -} - /*}}}*/ -// PackagesIndex::Info - One liner describing the index URI /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debPackagesIndex::Info(const char *Type) const -{ - string Info = ::URI::ArchiveOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Info += Dist; - } - else - Info += Dist + '/' + Section; - Info += " "; - if (Dist[Dist.size() - 1] != '/') - Info += Architecture + " "; - Info += Type; - return Info; -} - /*}}}*/ -// PackagesIndex::Index* - Return the URI to the index files /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debPackagesIndex::IndexFile(const char *Type) const -{ - string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); - - std::vector types = APT::Configuration::getCompressionTypes(); - for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) - { - string p = s + '.' + *t; - if (FileExists(p)) - return p; - } - return s; -} -string debPackagesIndex::IndexURI(const char *Type) const -{ - string Res; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - } - else - Res = URI + "dists/" + Dist + '/' + Section + - "/binary-" + Architecture + '/'; - - Res += Type; - return Res; -} - /*}}}*/ -// PackagesIndex::Exists - Check if the index is available /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debPackagesIndex::Exists() const -{ - return FileExists(IndexFile("Packages")); -} - /*}}}*/ -// PackagesIndex::Size - Return the size of the index /*{{{*/ -// --------------------------------------------------------------------- -/* This is really only used for progress reporting. */ -unsigned long debPackagesIndex::Size() const -{ - unsigned long size = 0; - - /* we need to ignore errors here; if the lists are absent, just return 0 */ - _error->PushToStack(); - - FileFd f(IndexFile("Packages"), FileFd::ReadOnly, FileFd::Extension); - if (!f.Failed()) - size = f.Size(); - - if (_error->PendingError() == true) - size = 0; - _error->RevertToStack(); - - return size; -} - /*}}}*/ // PackagesIndex::Merge - Load the index file into a cache /*{{{*/ // --------------------------------------------------------------------- /* */ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { - string PackageFile = IndexFile("Packages"); + string const PackageFile = IndexFileName(); FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); - debListParser Parser(&Pkg, Architecture); + debListParser Parser(&Pkg, Target.Option("ARCHITECTURE")); if (_error->PendingError() == true) return _error->Error("Problem opening %s",PackageFile.c_str()); if (Prog != NULL) - Prog->SubProgress(0,Info("Packages")); + Prog->SubProgress(0, Target.Description); + + + std::string const URI = Target.Option("REPO_URI"); + std::string Dist = Target.Option("RELEASE"); + if (Dist.empty()) + Dist = "/"; ::URI Tmp(URI); if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false) return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); @@ -370,7 +158,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (_error->PendingError() == true) return false; - Parser.LoadReleaseInfo(File,Rel,Section); + Parser.LoadReleaseInfo(File, Rel, Target.Option("COMPONENT")); } return true; @@ -381,7 +169,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const /* */ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const { - string FileName = IndexFile("Packages"); + string const FileName = IndexFileName(); pkgCache::PkgFileIterator File = Cache.FileBegin(); for (; File.end() == false; ++File) { @@ -411,113 +199,13 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const /*}}}*/ // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ -// --------------------------------------------------------------------- -/* */ -debTranslationsIndex::debTranslationsIndex(std::string const &URI, std::string const &Dist, - std::string const &Section, std::string const &Translation) : - pkgIndexFile(true), URI(URI), Dist(Dist), Section(Section), - Language(Translation) +debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) : + pkgIndexTargetFile(Target, true) {} /*}}}*/ -// TranslationIndex::Trans* - Return the URI to the translation files /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debTranslationsIndex::IndexFile(const char *Type) const -{ - string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type)); - - std::vector types = APT::Configuration::getCompressionTypes(); - for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) - { - string p = s + '.' + *t; - if (FileExists(p)) - return p; - } - return s; -} -string debTranslationsIndex::IndexURI(const char *Type) const -{ - string Res; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Res = URI + Dist; - else - Res = URI; - } - else - Res = URI + "dists/" + Dist + '/' + Section + - "/i18n/Translation-"; - - Res += Type; - return Res; -} - /*}}}*/ -// TranslationsIndex::Describe - Give a descriptive path to the index /*{{{*/ -// --------------------------------------------------------------------- -/* This should help the user find the index in the sources.list and - in the filesystem for problem solving */ -string debTranslationsIndex::Describe(bool Short) const -{ - std::string S; - if (Short == true) - strprintf(S,"%s",Info(TranslationFile().c_str()).c_str()); - else - strprintf(S,"%s (%s)",Info(TranslationFile().c_str()).c_str(), - IndexFile(Language.c_str()).c_str()); - return S; -} - /*}}}*/ -// TranslationsIndex::Info - One liner describing the index URI /*{{{*/ -// --------------------------------------------------------------------- -/* */ -string debTranslationsIndex::Info(const char *Type) const -{ - string Info = ::URI::ArchiveOnly(URI) + ' '; - if (Dist[Dist.size() - 1] == '/') - { - if (Dist != "/") - Info += Dist; - } - else - Info += Dist + '/' + Section; - Info += " "; - Info += Type; - return Info; -} - /*}}}*/ bool debTranslationsIndex::HasPackages() const /*{{{*/ { - return FileExists(IndexFile(Language.c_str())); -} - /*}}}*/ -// TranslationsIndex::Exists - Check if the index is available /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debTranslationsIndex::Exists() const -{ - return FileExists(IndexFile(Language.c_str())); -} - /*}}}*/ -// TranslationsIndex::Size - Return the size of the index /*{{{*/ -// --------------------------------------------------------------------- -/* This is really only used for progress reporting. */ -unsigned long debTranslationsIndex::Size() const -{ - unsigned long size = 0; - - /* we need to ignore errors here; if the lists are absent, just return 0 */ - _error->PushToStack(); - - FileFd f(IndexFile(Language.c_str()), FileFd::ReadOnly, FileFd::Extension); - if (!f.Failed()) - size = f.Size(); - - if (_error->PendingError() == true) - size = 0; - _error->RevertToStack(); - - return size; + return Exists(); } /*}}}*/ // TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ @@ -526,7 +214,7 @@ unsigned long debTranslationsIndex::Size() const bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { // Check the translation file, if in use - string TranslationFile = IndexFile(Language.c_str()); + string const TranslationFile = IndexFileName(); if (FileExists(TranslationFile)) { FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); @@ -535,7 +223,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const return false; if (Prog != NULL) - Prog->SubProgress(0, Info(TranslationFile.c_str())); + Prog->SubProgress(0, Target.Description); if (Gen.SelectFile(TranslationFile,string(),*this) == false) return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); @@ -556,8 +244,8 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const /* */ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const { - string FileName = IndexFile(Language.c_str()); - + string FileName = IndexFileName(); + pkgCache::PkgFileIterator File = Cache.FileBegin(); for (; File.end() == false; ++File) { @@ -580,10 +268,11 @@ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) con return pkgCache::PkgFileIterator(Cache); } return File; - } + } return File; } /*}}}*/ + // StatusIndex::debStatusIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 1e5882071..dd3f212b2 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -30,19 +30,16 @@ class pkgCacheGenerator; class APT_HIDDEN debStatusIndex : public pkgIndexFile { - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; - protected: std::string File; public: virtual const Type *GetType() const APT_CONST; - + // Interface for acquire virtual std::string Describe(bool /*Short*/) const {return File;}; - + // Interface for the Cache Generator virtual bool Exists() const; virtual bool HasPackages() const {return true;}; @@ -54,91 +51,42 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile debStatusIndex(std::string File); virtual ~debStatusIndex(); }; - -class APT_HIDDEN debPackagesIndex : public pkgIndexFile -{ - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; - - std::string URI; - std::string Dist; - std::string Section; - std::string Architecture; - - APT_HIDDEN std::string Info(const char *Type) const; - APT_HIDDEN std::string IndexFile(const char *Type) const; - APT_HIDDEN std::string IndexURI(const char *Type) const; +class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile +{ public: - + virtual const Type *GetType() const APT_CONST; // Stuff for accessing files on remote items virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const; - virtual std::string ArchiveURI(std::string File) const {return URI + File;}; - - // Interface for acquire - virtual std::string Describe(bool Short) const; - + // Interface for the Cache Generator - virtual bool Exists() const; virtual bool HasPackages() const {return true;}; - virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - debPackagesIndex(std::string const &URI, std::string const &Dist, std::string const &Section, - bool const &Trusted, std::string const &Arch = "native"); + debPackagesIndex(IndexTarget const &Target, bool const Trusted); virtual ~debPackagesIndex(); }; -class APT_HIDDEN debTranslationsIndex : public pkgIndexFile +class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile { - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; - - std::string const URI; - std::string const Dist; - std::string const Section; - std::string const Language; - - APT_HIDDEN std::string Info(const char *Type) const; - APT_HIDDEN std::string IndexFile(const char *Type) const; - APT_HIDDEN std::string IndexURI(const char *Type) const; - - APT_HIDDEN std::string TranslationFile() const {return std::string("Translation-").append(Language);}; - public: virtual const Type *GetType() const APT_CONST; - // Interface for acquire - virtual std::string Describe(bool Short) const; - // Interface for the Cache Generator - virtual bool Exists() const; virtual bool HasPackages() const; - virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; - debTranslationsIndex(std::string const &URI,std::string const &Dist,std::string const &Section, std::string const &Language); + debTranslationsIndex(IndexTarget const &Target); virtual ~debTranslationsIndex(); }; -class APT_HIDDEN debSourcesIndex : public pkgIndexFile +class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile { - /** \brief dpointer placeholder (for later in case we need it) */ - void *d; - - std::string URI; - std::string Dist; - std::string Section; - - APT_HIDDEN std::string Info(const char *Type) const; - APT_HIDDEN std::string IndexFile(const char *Type) const; - APT_HIDDEN std::string IndexURI(const char *Type) const; - public: virtual const Type *GetType() const APT_CONST; @@ -146,20 +94,14 @@ class APT_HIDDEN debSourcesIndex : public pkgIndexFile // Stuff for accessing files on remote items virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const; - virtual std::string ArchiveURI(std::string File) const {return URI + File;}; - - // Interface for acquire - virtual std::string Describe(bool Short) const; // Interface for the record parsers virtual pkgSrcRecords::Parser *CreateSrcParser() const; - + // Interface for the Cache Generator - virtual bool Exists() const; virtual bool HasPackages() const {return false;}; - virtual unsigned long Size() const; - - debSourcesIndex(std::string URI,std::string Dist,std::string Section,bool Trusted); + + debSourcesIndex(IndexTarget const &Target, bool const Trusted); virtual ~debSourcesIndex(); }; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index d4e340be0..9108a5097 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -140,6 +140,7 @@ void foreachTarget(std::string const URI, std::string const Dist, Options.insert(std::make_pair("LANGUAGE", *l)); Options.insert(std::make_pair("ARCHITECTURE", "source")); Options.insert(std::make_pair("BASE_URI", baseURI)); + Options.insert(std::make_pair("REPO_URI", URI)); Options.insert(std::make_pair("CREATED_BY", *T)); Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); @@ -186,6 +187,7 @@ void foreachTarget(std::string const URI, std::string const Dist, Options.insert(std::make_pair("LANGUAGE", *l)); Options.insert(std::make_pair("ARCHITECTURE", a->first)); Options.insert(std::make_pair("BASE_URI", baseURI)); + Options.insert(std::make_pair("REPO_URI", URI)); Options.insert(std::make_pair("CREATED_BY", *T)); Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); @@ -294,55 +296,25 @@ bool debReleaseIndex::IsTrusted() const return FileExists(VerifiedSigFile); } -struct GetIndexFilesClass +std::vector *debReleaseIndex::GetIndexFiles() { - vector * const Indexes; - std::string const URI; - std::string const Release; - bool const IsTrusted; + if (Indexes != NULL) + return Indexes; - void operator()(std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/, - bool const /*IsOptional*/, std::map Options) + Indexes = new std::vector(); + std::vector const Targets = GetIndexTargets(); + bool const istrusted = IsTrusted(); + for (std::vector::const_iterator T = Targets.begin(); T != Targets.end(); ++T) { - std::string const TargetName = Options.find("CREATED_BY")->second; + std::string const TargetName = T->Options.find("CREATED_BY")->second; if (TargetName == "Packages") - { - Indexes->push_back(new debPackagesIndex( - URI, - Release, - Options.find("COMPONENT")->second, - IsTrusted, - Options.find("ARCHITECTURE")->second - )); - } + Indexes->push_back(new debPackagesIndex(*T, istrusted)); else if (TargetName == "Sources") - Indexes->push_back(new debSourcesIndex( - URI, - Release, - Options.find("COMPONENT")->second, - IsTrusted - )); + Indexes->push_back(new debSourcesIndex(*T, istrusted)); else if (TargetName == "Translations") - Indexes->push_back(new debTranslationsIndex( - URI, - Release, - Options.find("COMPONENT")->second, - Options.find("LANGUAGE")->second - )); + Indexes->push_back(new debTranslationsIndex(*T)); } - - GetIndexFilesClass(std::string const &URI, std::string const &Release, bool const IsTrusted) : - Indexes(new vector ), URI(URI), Release(Release), IsTrusted(IsTrusted) {} -}; - -std::vector *debReleaseIndex::GetIndexFiles() -{ - if (Indexes != NULL) - return Indexes; - - GetIndexFilesClass comp(URI, Dist, IsTrusted()); - foreachTarget(URI, Dist, ArchEntries, comp); - return Indexes = comp.Indexes; + return Indexes; } void debReleaseIndex::PushSectionEntry(vector const &Archs, const debSectionEntry *Entry) { -- cgit v1.2.3 From 001c76fe204e17916a6c8b351ff30b67d32cb779 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 11:59:16 +0200 Subject: use an enum instead of strings as IndexTarget::Option interface Strings are easy to typo and we can keep the extensibility we require here with a simple enum we can append to without endangering ABI. Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 14 +++++++------- apt-pkg/deb/debmetaindex.cc | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 3e60423ff..7aad65c0e 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -93,9 +93,9 @@ debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted /* This is a shorter version that is designed to be < 60 chars or so */ string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const { - std::string const Dist = Target.Option("RELEASE"); - string Res = Target.Option("SITE") + " " + Dist; - std::string const Component = Target.Option("COMPONENT"); + std::string const Dist = Target.Option(IndexTarget::RELEASE); + string Res = Target.Option(IndexTarget::SITE) + " " + Dist; + std::string const Component = Target.Option(IndexTarget::COMPONENT); if (Component.empty() == false) Res += "/" + Component; @@ -115,7 +115,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const { string const PackageFile = IndexFileName(); FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); - debListParser Parser(&Pkg, Target.Option("ARCHITECTURE")); + debListParser Parser(&Pkg, Target.Option(IndexTarget::ARCHITECTURE)); if (_error->PendingError() == true) return _error->Error("Problem opening %s",PackageFile.c_str()); @@ -123,8 +123,8 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const Prog->SubProgress(0, Target.Description); - std::string const URI = Target.Option("REPO_URI"); - std::string Dist = Target.Option("RELEASE"); + std::string const URI = Target.Option(IndexTarget::REPO_URI); + std::string Dist = Target.Option(IndexTarget::RELEASE); if (Dist.empty()) Dist = "/"; ::URI Tmp(URI); @@ -158,7 +158,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (_error->PendingError() == true) return false; - Parser.LoadReleaseInfo(File, Rel, Target.Option("COMPONENT")); + Parser.LoadReleaseInfo(File, Rel, Target.Option(IndexTarget::COMPONENT)); } return true; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 9108a5097..c05e7cdae 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -306,7 +306,7 @@ std::vector *debReleaseIndex::GetIndexFiles() bool const istrusted = IsTrusted(); for (std::vector::const_iterator T = Targets.begin(); T != Targets.end(); ++T) { - std::string const TargetName = T->Options.find("CREATED_BY")->second; + std::string const TargetName = T->Option(IndexTarget::CREATED_BY); if (TargetName == "Packages") Indexes->push_back(new debPackagesIndex(*T, istrusted)); else if (TargetName == "Sources") -- cgit v1.2.3 From 8881b11eacd735148d087c8c0f53827cb537b582 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 16:40:45 +0200 Subject: implement 'apt-get files' to access index targets Downloading additional files is only half the job. We still need a way to allow external tools to know where the files are they requested for download given that we don't want them to choose their own location. 'apt-get files' is our answer to this showing by default in a deb822 format information about each IndexTarget with the potential to filter the records based on lines and an option to change the output format. The command serves also as an example on how to get to this information via libapt. --- apt-pkg/deb/debmetaindex.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index c05e7cdae..8e4c2be2d 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -136,11 +136,14 @@ void foreachTarget(std::string const URI, std::string const Dist, std::map Options; Options.insert(std::make_pair("SITE", Site)); Options.insert(std::make_pair("RELEASE", Release)); - Options.insert(std::make_pair("COMPONENT", (*I)->Section)); - Options.insert(std::make_pair("LANGUAGE", *l)); + if (MetaKey.find("$(COMPONENT)") != std::string::npos) + Options.insert(std::make_pair("COMPONENT", (*I)->Section)); + if (MetaKey.find("$(LANGUAGE)") != std::string::npos) + Options.insert(std::make_pair("LANGUAGE", *l)); Options.insert(std::make_pair("ARCHITECTURE", "source")); Options.insert(std::make_pair("BASE_URI", baseURI)); Options.insert(std::make_pair("REPO_URI", URI)); + Options.insert(std::make_pair("TARGET_OF", "deb-src")); Options.insert(std::make_pair("CREATED_BY", *T)); Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); @@ -183,11 +186,15 @@ void foreachTarget(std::string const URI, std::string const Dist, std::map Options; Options.insert(std::make_pair("SITE", Site)); Options.insert(std::make_pair("RELEASE", Release)); - Options.insert(std::make_pair("COMPONENT", (*I)->Section)); - Options.insert(std::make_pair("LANGUAGE", *l)); - Options.insert(std::make_pair("ARCHITECTURE", a->first)); + if (MetaKey.find("$(COMPONENT)") != std::string::npos) + Options.insert(std::make_pair("COMPONENT", (*I)->Section)); + if (MetaKey.find("$(LANGUAGE)") != std::string::npos) + Options.insert(std::make_pair("LANGUAGE", *l)); + if (MetaKey.find("$(ARCHITECTURE)") != std::string::npos) + Options.insert(std::make_pair("ARCHITECTURE", a->first)); Options.insert(std::make_pair("BASE_URI", baseURI)); Options.insert(std::make_pair("REPO_URI", URI)); + Options.insert(std::make_pair("TARGET_OF", "deb")); Options.insert(std::make_pair("CREATED_BY", *T)); Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); -- cgit v1.2.3 From b07aeb1a6e24825e534167a737043441e871de9f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Jun 2015 02:08:53 +0200 Subject: store Release files data in the Cache We used to read the Release file for each Packages file and store the data in the PackageFile struct even through potentially many Packages (and Translation-*) files could use the same data. The point of the exercise isn't the duplicated data through. Having the Release files as first-class citizens in the Cache allows us to properly track their state as well as allows us to use the information also for files which aren't in the cache, but where we know to which Release file they belong (Sources are an example for this). This modifies the pkgCache structs, especially the PackagesFile struct which depending on how libapt users access the data in these structs can mean huge breakage or no visible change. As a single data point: aptitude seems to be fine with this. Even if there is breakage it is trivial to fix in a backportable way while avoiding breakage for everyone would be a huge pain for us. Note that not all PackageFile structs have a corresponding ReleaseFile. In particular the dpkg/status file as well as *.deb files have not. As these have only a Archive property need, the Component property takes over this duty and the ReleaseFile remains zero. This is also the reason why it isn't needed nor particularily recommended to change from PackagesFile to ReleaseFile blindly. Sticking with the earlier is usually the better option. --- apt-pkg/deb/debindexfile.cc | 42 ++++----------- apt-pkg/deb/debindexfile.h | 1 - apt-pkg/deb/deblistparser.cc | 37 ------------- apt-pkg/deb/deblistparser.h | 6 +-- apt-pkg/deb/debmetaindex.cc | 124 ++++++++++++++++++++++++++++++++++++++++++- apt-pkg/deb/debmetaindex.h | 6 +++ apt-pkg/deb/dpkgpm.cc | 4 +- 7 files changed, 144 insertions(+), 76 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 7aad65c0e..3a79cbc58 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -128,7 +128,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Dist.empty()) Dist = "/"; ::URI Tmp(URI); - if (Gen.SelectFile(PackageFile,Tmp.Host,*this) == false) + if (Gen.SelectFile(PackageFile, *this, Target.Option(IndexTarget::COMPONENT)) == false) return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); // Store the IMS information @@ -136,31 +136,10 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const pkgCacheGenerator::Dynamic DynFile(File); File->Size = Pkg.FileSize(); File->mtime = Pkg.ModificationTime(); - + if (Gen.MergeList(Parser) == false) return _error->Error("Problem with MergeList %s",PackageFile.c_str()); - // Check the release file - string ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("InRelease"); - bool releaseExists = false; - if (FileExists(ReleaseFile) == true) - releaseExists = true; - else - ReleaseFile = debReleaseIndex(URI,Dist).MetaIndexFile("Release"); - - if (releaseExists == true || FileExists(ReleaseFile) == true) - { - FileFd Rel; - // Beware: The 'Release' file might be clearsigned in case the - // signature for an 'InRelease' file couldn't be checked - if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) - return false; - - if (_error->PendingError() == true) - return false; - Parser.LoadReleaseInfo(File, Rel, Target.Option(IndexTarget::COMPONENT)); - } - return true; } /*}}}*/ @@ -221,17 +200,17 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const debTranslationsParser TransParser(&Trans); if (_error->PendingError() == true) return false; - + if (Prog != NULL) Prog->SubProgress(0, Target.Description); - if (Gen.SelectFile(TranslationFile,string(),*this) == false) + if (Gen.SelectFile(TranslationFile, *this, Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource) == false) return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); // Store the IMS information pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); TransFile->Size = Trans.FileSize(); TransFile->mtime = Trans.ModificationTime(); - + if (Gen.MergeList(TransParser) == false) return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); } @@ -305,18 +284,17 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Prog != NULL) Prog->SubProgress(0,File); - if (Gen.SelectFile(File,string(),*this,pkgCache::Flag::NotSource) == false) + if (Gen.SelectFile(File, *this, "now", pkgCache::Flag::NotSource) == false) return _error->Error("Problem with SelectFile %s",File.c_str()); // Store the IMS information pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); + pkgCacheGenerator::Dynamic DynFile(CFile); CFile->Size = Pkg.FileSize(); CFile->mtime = Pkg.ModificationTime(); - map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "now"); - CFile->Archive = storage; - + if (Gen.MergeList(Parser) == false) - return _error->Error("Problem with MergeList %s",File.c_str()); + return _error->Error("Problem with MergeList %s",File.c_str()); return true; } /*}}}*/ @@ -431,7 +409,7 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const // and give it to the list parser debDebFileParser Parser(DebControl, DebFile); - if(Gen.SelectFile(DebFile, "local", *this, pkgCache::Flag::LocalSource) == false) + if(Gen.SelectFile(DebFile, *this, "now", pkgCache::Flag::LocalSource) == false) return _error->Error("Problem with SelectFile %s", DebFile.c_str()); pkgCache::PkgFileIterator File = Gen.GetCurFile(); diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index dd3f212b2..6b8c78e5a 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -45,7 +45,6 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile virtual bool HasPackages() const {return true;}; virtual unsigned long Size() const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog, unsigned long const Flag) const; virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; debStatusIndex(std::string File); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index b80b57bc4..c5e77b0ff 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -951,43 +951,6 @@ bool debListParser::Step() return false; } /*}}}*/ -// ListParser::LoadReleaseInfo - Load the release information /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, - FileFd &File, string component) -{ - // apt-secure does no longer download individual (per-section) Release - // file. to provide Component pinning we use the section name now - map_stringitem_t const storage = StoreString(pkgCacheGenerator::MIXED, component); - FileI->Component = storage; - - pkgTagFile TagFile(&File, File.Size()); - pkgTagSection Section; - if (_error->PendingError() == true || TagFile.Step(Section) == false) - return false; - - std::string data; - #define APT_INRELEASE(TYPE, TAG, STORE) \ - data = Section.FindS(TAG); \ - if (data.empty() == false) \ - { \ - map_stringitem_t const storage = StoreString(pkgCacheGenerator::TYPE, data); \ - STORE = storage; \ - } - APT_INRELEASE(MIXED, "Suite", FileI->Archive) - APT_INRELEASE(MIXED, "Component", FileI->Component) - APT_INRELEASE(VERSIONNUMBER, "Version", FileI->Version) - APT_INRELEASE(MIXED, "Origin", FileI->Origin) - APT_INRELEASE(MIXED, "Codename", FileI->Codename) - APT_INRELEASE(MIXED, "Label", FileI->Label) - #undef APT_INRELEASE - Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic); - Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades); - - return !_error->PendingError(); -} - /*}}}*/ // ListParser::GetPrio - Convert the priority from a string /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 6279d8399..420d5ff08 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -80,9 +80,9 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser virtual map_filesize_t Size() {return Section.size();}; virtual bool Step(); - - bool LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,FileFd &File, - std::string section); + + bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File, + std::string const §ion); APT_PUBLIC static const char *ParseDepends(const char *Start,const char *Stop, std::string &Package,std::string &Ver,unsigned int &Op); diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 8e4c2be2d..994b95849 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -10,10 +11,12 @@ #include #include #include -#include #include +#include +#include +#include +#include -#include #include #include #include @@ -21,6 +24,11 @@ #include #include +#include +#include +#include +#include + using namespace std; string debReleaseIndex::MetaIndexInfo(const char *Type) const @@ -37,6 +45,10 @@ string debReleaseIndex::MetaIndexInfo(const char *Type) const Info += Type; return Info; } +std::string debReleaseIndex::Describe() const +{ + return MetaIndexInfo("Release"); +} string debReleaseIndex::MetaIndexFile(const char *Type) const { @@ -339,6 +351,114 @@ debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section, bool const &IsSrc): Section(Section), IsSrc(IsSrc) {} +static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile) +{ + ReleaseFile = That->MetaIndexFile("InRelease"); + bool releaseExists = false; + if (FileExists(ReleaseFile) == true) + releaseExists = true; + else + { + ReleaseFile = That->MetaIndexFile("Release"); + if (FileExists(ReleaseFile)) + releaseExists = true; + } + return releaseExists; +} + +bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/ +{ + std::string ReleaseFile; + bool const releaseExists = ReleaseFileName(this, ReleaseFile); + + ::URI Tmp(URI); + if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false) + return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str()); + + if (releaseExists == false) + return true; + + FileFd Rel; + // Beware: The 'Release' file might be clearsigned in case the + // signature for an 'InRelease' file couldn't be checked + if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) + return false; + if (_error->PendingError() == true) + return false; + + // Store the IMS information + pkgCache::RlsFileIterator File = Gen.GetCurRlsFile(); + pkgCacheGenerator::Dynamic DynFile(File); + // Rel can't be used as this is potentially a temporary file + struct stat Buf; + if (stat(ReleaseFile.c_str(), &Buf) != 0) + return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str()); + File->Size = Buf.st_size; + File->mtime = Buf.st_mtime; + + pkgTagFile TagFile(&Rel, Rel.Size()); + pkgTagSection Section; + if (_error->PendingError() == true || TagFile.Step(Section) == false) + return false; + + std::string data; + #define APT_INRELEASE(TYPE, TAG, STORE) \ + data = Section.FindS(TAG); \ + if (data.empty() == false) \ + { \ + map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \ + STORE = storage; \ + } + APT_INRELEASE(MIXED, "Suite", File->Archive) + APT_INRELEASE(VERSIONNUMBER, "Version", File->Version) + APT_INRELEASE(MIXED, "Origin", File->Origin) + APT_INRELEASE(MIXED, "Codename", File->Codename) + APT_INRELEASE(MIXED, "Label", File->Label) + #undef APT_INRELEASE + Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic); + Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades); + + return !_error->PendingError(); +} + /*}}}*/ +// ReleaseIndex::FindInCache - Find this index /*{{{*/ +pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache) const +{ + std::string ReleaseFile; + bool const releaseExists = ReleaseFileName(this, ReleaseFile); + + pkgCache::RlsFileIterator File = Cache.RlsFileBegin(); + for (; File.end() == false; ++File) + { + if (File->FileName == 0 || ReleaseFile != File.FileName()) + continue; + + // empty means the file does not exist by "design" + if (releaseExists == false && File->Size == 0) + return File; + + struct stat St; + if (stat(File.FileName(),&St) != 0) + { + if (_config->FindB("Debug::pkgCacheGen", false)) + std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl; + return pkgCache::RlsFileIterator(Cache); + } + if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) + { + if (_config->FindB("Debug::pkgCacheGen", false)) + std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size + << ") or mtime (" << St.st_mtime << " <> " << File->mtime + << ") doesn't match for " << File.FileName() << std::endl; + return pkgCache::RlsFileIterator(Cache); + } + return File; + } + + return File; +} + /*}}}*/ + class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type { protected: diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 0b1b08432..7e9942710 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -20,6 +20,8 @@ class pkgAcquire; class pkgIndexFile; class debDebPkgFileIndex; class IndexTarget; +class pkgCacheGenerator; +class OpProgress; class APT_HIDDEN debReleaseIndex : public metaIndex { public: @@ -48,6 +50,10 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; virtual std::vector GetIndexTargets() const; + virtual std::string Describe() const; + virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache) const; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; + std::string MetaIndexInfo(const char *Type) const; std::string MetaIndexFile(const char *Types) const; std::string MetaIndexURI(const char *Type) const; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index a7a66c75d..6ee939edd 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -205,8 +205,10 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) for (pkgCache::VerFileIterator Vf = Ver.FileList(); Vf.end() == false; ++Vf) for (pkgCache::PkgFileIterator F = Vf.File(); F.end() == false; ++F) - if (F->Archive != 0 && strcmp(F.Archive(), "now") == 0) + { + if (F.Archive() != 0 && strcmp(F.Archive(), "now") == 0) return Ver; + } return Ver; } /*}}}*/ -- cgit v1.2.3 From 3fd89e62e985c89b1f9a545ab72c20987b756aff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Jun 2015 12:06:29 +0200 Subject: implement default apt-get file --release-info mode Selecting targets based on the Release they belong to isn't to unrealistic. In fact, it is assumed to be the most used case so it is made the default especially as this allows to bundle another thing we have to be careful with: Filenames and only showing targets we have acquired. Closes: 752702 --- apt-pkg/deb/debmetaindex.cc | 4 ++-- apt-pkg/deb/debmetaindex.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 994b95849..b328fcea8 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -422,7 +422,7 @@ bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/ } /*}}}*/ // ReleaseIndex::FindInCache - Find this index /*{{{*/ -pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache) const +pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const { std::string ReleaseFile; bool const releaseExists = ReleaseFileName(this, ReleaseFile); @@ -434,7 +434,7 @@ pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache) const continue; // empty means the file does not exist by "design" - if (releaseExists == false && File->Size == 0) + if (ModifyCheck == false || (releaseExists == false && File->Size == 0)) return File; struct stat St; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 7e9942710..b448ecc53 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -51,7 +51,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual std::vector GetIndexTargets() const; virtual std::string Describe() const; - virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache) const; + virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; std::string MetaIndexInfo(const char *Type) const; -- cgit v1.2.3 From e185d8b3e39e3840f439cab7d5d265fd96d84c6f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Jun 2015 14:42:17 +0200 Subject: populate the Architecture field for PackageFiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is mainly visible in the policy, so that you can now pin by b= and let it only effect Packages files of this architecture and hence the packages coming from it (which do not need to be from this architecture, but very likely are in a normal repository setup). If you should pin by architecture in this way is a different question… Closes: 687255 --- apt-pkg/deb/debindexfile.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 3a79cbc58..f089cda81 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -128,7 +128,7 @@ bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Dist.empty()) Dist = "/"; ::URI Tmp(URI); - if (Gen.SelectFile(PackageFile, *this, Target.Option(IndexTarget::COMPONENT)) == false) + if (Gen.SelectFile(PackageFile, *this, Target.Option(IndexTarget::ARCHITECTURE), Target.Option(IndexTarget::COMPONENT)) == false) return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); // Store the IMS information @@ -203,7 +203,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Prog != NULL) Prog->SubProgress(0, Target.Description); - if (Gen.SelectFile(TranslationFile, *this, Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource) == false) + if (Gen.SelectFile(TranslationFile, *this, "", Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource) == false) return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); // Store the IMS information @@ -284,7 +284,7 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Prog != NULL) Prog->SubProgress(0,File); - if (Gen.SelectFile(File, *this, "now", pkgCache::Flag::NotSource) == false) + if (Gen.SelectFile(File, *this, "", "now", pkgCache::Flag::NotSource) == false) return _error->Error("Problem with SelectFile %s",File.c_str()); // Store the IMS information @@ -409,7 +409,7 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const // and give it to the list parser debDebFileParser Parser(DebControl, DebFile); - if(Gen.SelectFile(DebFile, *this, "now", pkgCache::Flag::LocalSource) == false) + if(Gen.SelectFile(DebFile, *this, "", "now", pkgCache::Flag::LocalSource) == false) return _error->Error("Problem with SelectFile %s", DebFile.c_str()); pkgCache::PkgFileIterator File = Gen.GetCurFile(); -- cgit v1.2.3 From d2cb5b153fb13d587b1ff632cab34ce0c403326e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Jun 2015 15:48:00 +0200 Subject: hide Translation-* in 'apt-cache policy' output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translation-* files are internally handled as PackageFiles which isn't super nice, but giving them their own struct is a bit overkill so let it be for the moment. They always appeared in the policy output because of this through and now that they are properly linked to a ReleaseFile they even display all the pinning information on them, but they don't contain any packages which could be pinned… No problem, but useless and potentially confusing output. Adding a 'NoPackages' flag which can be set on those files and be used in applications seems like a simple way to fix this display issue. --- apt-pkg/deb/debindexfile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index f089cda81..944cbe0bf 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -203,7 +203,7 @@ bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const if (Prog != NULL) Prog->SubProgress(0, Target.Description); - if (Gen.SelectFile(TranslationFile, *this, "", Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource) == false) + if (Gen.SelectFile(TranslationFile, *this, "", Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages) == false) return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); // Store the IMS information -- cgit v1.2.3 From c8a4ce6cbed57ae108dc955d4a850f9b129a0693 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 16 Jun 2015 16:22:46 +0200 Subject: add d-pointer, virtual destructors and de-inline de/constructors To have a chance to keep the ABI for a while we need all three to team up. One of them missing and we might loose, so ensuring that they are available is a very tedious but needed task once in a while. Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 1 + apt-pkg/deb/debindexfile.h | 8 ++++++-- apt-pkg/deb/debmetaindex.cc | 2 ++ apt-pkg/deb/debmetaindex.h | 3 ++- apt-pkg/deb/debrecords.cc | 7 +++++++ apt-pkg/deb/debrecords.h | 15 +++++++++------ apt-pkg/deb/debsrcrecords.cc | 4 ++++ apt-pkg/deb/debsrcrecords.h | 4 +--- apt-pkg/deb/debversion.h | 1 - 9 files changed, 32 insertions(+), 13 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 944cbe0bf..0fffa52b0 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -576,3 +576,4 @@ debTranslationsIndex::~debTranslationsIndex() {} debSourcesIndex::~debSourcesIndex() {} debDebPkgFileIndex::~debDebPkgFileIndex() {} +debDscFileIndex::~debDscFileIndex() {} diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 6b8c78e5a..6285a9e5c 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -1,6 +1,5 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debindexfile.h,v 1.3.2.1 2003/12/24 23:09:17 mdz Exp $ /* ###################################################################### Debian Index Files @@ -30,6 +29,7 @@ class pkgCacheGenerator; class APT_HIDDEN debStatusIndex : public pkgIndexFile { + void *d; protected: std::string File; @@ -53,6 +53,7 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile { + void *d; public: virtual const Type *GetType() const APT_CONST; @@ -71,6 +72,7 @@ class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile { + void *d; public: virtual const Type *GetType() const APT_CONST; @@ -86,6 +88,7 @@ class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile { + void *d; public: virtual const Type *GetType() const APT_CONST; @@ -145,6 +148,7 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile class APT_HIDDEN debDscFileIndex : public pkgIndexFile { private: + void *d; std::string DscFile; public: virtual const Type *GetType() const APT_CONST; @@ -157,7 +161,7 @@ class APT_HIDDEN debDscFileIndex : public pkgIndexFile }; debDscFileIndex(std::string &DscFile); - virtual ~debDscFileIndex() {}; + virtual ~debDscFileIndex(); }; class APT_HIDDEN debDebianSourceDirIndex : public debDscFileIndex diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index b328fcea8..34fc98838 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -459,6 +459,8 @@ pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool con } /*}}}*/ +debDebFileMetaIndex::~debDebFileMetaIndex() {} + class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type { protected: diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index b448ecc53..f2706e08a 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -75,6 +75,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { class APT_HIDDEN debDebFileMetaIndex : public metaIndex { private: + void *d; std::string DebFile; debDebPkgFileIndex *DebIndex; public: @@ -94,7 +95,7 @@ class APT_HIDDEN debDebFileMetaIndex : public metaIndex return true; } debDebFileMetaIndex(std::string const &DebFile); - virtual ~debDebFileMetaIndex() {}; + virtual ~debDebFileMetaIndex(); }; diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 335bcfda0..f527042e4 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -51,6 +51,7 @@ bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) /*}}}*/ debRecordParser::~debRecordParser() {} +debRecordParserBase::debRecordParserBase() : Parser() {} // RecordParserBase::FileName - Return the archive filename on the site /*{{{*/ string debRecordParserBase::FileName() { @@ -207,3 +208,9 @@ bool debDebFileRecordParser::LoadContent() return _error->Error(_("Unable to parse package file %s (%d)"), debFileName.c_str(), 3); return true; } +bool debDebFileRecordParser::Jump(pkgCache::VerFileIterator const &) { return LoadContent(); } +bool debDebFileRecordParser::Jump(pkgCache::DescFileIterator const &) { return LoadContent(); } +std::string debDebFileRecordParser::FileName() { return debFileName; } + +debDebFileRecordParser::debDebFileRecordParser(std::string FileName) : debRecordParserBase(), debFileName(FileName) {} +debDebFileRecordParser::~debDebFileRecordParser() {} diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 38e071940..8efcec8cd 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -27,6 +27,7 @@ class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser { + void *d; protected: pkgTagSection Section; @@ -50,12 +51,13 @@ class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser virtual void GetRec(const char *&Start,const char *&Stop); - debRecordParserBase() : Parser() {} + debRecordParserBase(); virtual ~debRecordParserBase(); }; class APT_HIDDEN debRecordParser : public debRecordParserBase { + void *d; protected: FileFd File; pkgTagFile Tags; @@ -71,20 +73,21 @@ class APT_HIDDEN debRecordParser : public debRecordParserBase // custom record parser that reads deb files directly class APT_HIDDEN debDebFileRecordParser : public debRecordParserBase { + void *d; std::string debFileName; std::string controlContent; APT_HIDDEN bool LoadContent(); protected: // single file files, so no jumping whatsoever - bool Jump(pkgCache::VerFileIterator const &) { return LoadContent(); } - bool Jump(pkgCache::DescFileIterator const &) { return LoadContent(); } + bool Jump(pkgCache::VerFileIterator const &); + bool Jump(pkgCache::DescFileIterator const &); public: - virtual std::string FileName() { return debFileName; } + virtual std::string FileName(); - debDebFileRecordParser(std::string FileName) - : debRecordParserBase(), debFileName(FileName) {}; + debDebFileRecordParser(std::string FileName); + virtual ~debDebFileRecordParser(); }; #endif diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index ca6d09896..21a4ff8ea 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -32,6 +32,10 @@ using std::max; using std::string; +debSrcRecordParser::debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) + : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), + iOffset(0), Buffer(NULL) {} + // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ // --------------------------------------------------------------------- /* This member parses the binaries field into a pair of class arrays and diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index cd246d624..7aeb2db88 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -56,9 +56,7 @@ class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser virtual bool Files(std::vector &F); bool Files2(std::vector &F); - debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) - : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), - iOffset(0), Buffer(NULL) {} + debSrcRecordParser(std::string const &File,pkgIndexFile const *Index); virtual ~debSrcRecordParser(); }; diff --git a/apt-pkg/deb/debversion.h b/apt-pkg/deb/debversion.h index 434ff4a2e..7befe6372 100644 --- a/apt-pkg/deb/debversion.h +++ b/apt-pkg/deb/debversion.h @@ -1,6 +1,5 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: debversion.h,v 1.3 2001/05/03 05:25:04 jgg Exp $ /* ###################################################################### Debian Version - Versioning system for Debian -- cgit v1.2.3 From e8afd16892e87a6e2f17c1019ee455f5583387c2 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Jun 2015 00:14:10 +0200 Subject: apply various style suggestions by cppcheck Some of them modify the ABI, but given that we prepare a big one already, these few hardly count for much. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 34fc98838..430a5021b 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -103,7 +103,7 @@ debReleaseIndex::~debReleaseIndex() { } template -void foreachTarget(std::string const URI, std::string const Dist, +void foreachTarget(std::string const &URI, std::string const &Dist, std::map > const &ArchEntries, CallC &Call) { -- cgit v1.2.3 From 6c55f07a5fa3612a5d59c61a17da5fe640eadc8b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Jun 2015 09:29:00 +0200 Subject: make all d-pointer * const pointers Doing this disables the implicit copy assignment operator (among others) which would cause hovac if used on the classes as it would just copy the pointer, not the data the d-pointer points to. For most of the classes we don't need a copy assignment operator anyway and in many classes it was broken before as many contain a pointer of some sort. Only for our Cacheset Container interfaces we define an explicit copy assignment operator which could later be implemented to copy the data from one d-pointer to the other if we need it. Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 12 ++++++------ apt-pkg/deb/debindexfile.h | 12 ++++++------ apt-pkg/deb/deblistparser.cc | 2 +- apt-pkg/deb/deblistparser.h | 2 +- apt-pkg/deb/debmetaindex.cc | 6 +++--- apt-pkg/deb/debmetaindex.h | 4 ++-- apt-pkg/deb/debrecords.cc | 6 +++--- apt-pkg/deb/debrecords.h | 6 +++--- apt-pkg/deb/debsrcrecords.cc | 2 +- apt-pkg/deb/debsrcrecords.h | 2 +- apt-pkg/deb/debsystem.cc | 5 +---- apt-pkg/deb/debsystem.h | 2 +- apt-pkg/deb/dpkgpm.cc | 5 ++--- apt-pkg/deb/dpkgpm.h | 2 +- 14 files changed, 32 insertions(+), 36 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 0fffa52b0..29a9a941c 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -45,7 +45,7 @@ using std::string; // --------------------------------------------------------------------- /* */ debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) : - pkgIndexTargetFile(Target, Trusted) + pkgIndexTargetFile(Target, Trusted), d(NULL) { } /*}}}*/ @@ -84,7 +84,7 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const // --------------------------------------------------------------------- /* */ debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) : - pkgIndexTargetFile(Target, Trusted) + pkgIndexTargetFile(Target, Trusted), d(NULL) { } /*}}}*/ @@ -179,7 +179,7 @@ pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const // TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) : - pkgIndexTargetFile(Target, true) + pkgIndexTargetFile(Target, true), d(NULL) {} /*}}}*/ bool debTranslationsIndex::HasPackages() const /*{{{*/ @@ -255,7 +255,7 @@ pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) con // StatusIndex::debStatusIndex - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), File(File) +debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), d(NULL), File(File) { } /*}}}*/ @@ -341,7 +341,7 @@ APT_CONST bool debStatusIndex::Exists() const // debDebPkgFile - Single .deb file /*{{{*/ debDebPkgFileIndex::debDebPkgFileIndex(std::string DebFile) - : pkgIndexFile(true), DebFile(DebFile) + : pkgIndexFile(true), d(NULL), DebFile(DebFile) { DebFileFullPath = flAbsPath(DebFile); } @@ -445,7 +445,7 @@ unsigned long debDebPkgFileIndex::Size() const // debDscFileIndex stuff debDscFileIndex::debDscFileIndex(std::string &DscFile) - : pkgIndexFile(true), DscFile(DscFile) + : pkgIndexFile(true), d(NULL), DscFile(DscFile) { } diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 6285a9e5c..1de609a7b 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -29,7 +29,7 @@ class pkgCacheGenerator; class APT_HIDDEN debStatusIndex : public pkgIndexFile { - void *d; + void * const d; protected: std::string File; @@ -53,7 +53,7 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile { - void *d; + void * const d; public: virtual const Type *GetType() const APT_CONST; @@ -72,7 +72,7 @@ class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile { - void *d; + void * const d; public: virtual const Type *GetType() const APT_CONST; @@ -88,7 +88,7 @@ class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile { - void *d; + void * const d; public: virtual const Type *GetType() const APT_CONST; @@ -110,7 +110,7 @@ class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile { private: - void *d; + void * const d; std::string DebFile; std::string DebFileFullPath; @@ -148,7 +148,7 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile class APT_HIDDEN debDscFileIndex : public pkgIndexFile { private: - void *d; + void * const d; std::string DscFile; public: virtual const Type *GetType() const APT_CONST; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index c5e77b0ff..4e49e1c78 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -50,7 +50,7 @@ static debListParser::WordList PrioList[] = { /* Provide an architecture and only this one and "all" will be accepted in Step(), if no Architecture is given we will accept every arch we would accept in general with checkArchitecture() */ -debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File), +debListParser::debListParser(FileFd *File, string const &Arch) : d(NULL), Tags(File), Arch(Arch) { if (Arch == "native") this->Arch = _config->Find("APT::Architecture"); diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 420d5ff08..3fd040bdd 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -39,7 +39,7 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser private: /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; protected: pkgTagFile Tags; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 430a5021b..026af077f 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -86,11 +86,11 @@ std::string debReleaseIndex::LocalFileName() const } debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) : - metaIndex(URI, Dist, "deb"), Trusted(CHECK_TRUST) + metaIndex(URI, Dist, "deb"), d(NULL), Trusted(CHECK_TRUST) {} debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist, bool const Trusted) : - metaIndex(URI, Dist, "deb") { + metaIndex(URI, Dist, "deb"), d(NULL) { SetTrusted(Trusted); } @@ -541,7 +541,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type }; debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile) - : metaIndex(DebFile, "local-uri", "deb-dist"), DebFile(DebFile) + : metaIndex(DebFile, "local-uri", "deb-dist"), d(NULL), DebFile(DebFile) { DebIndex = new debDebPkgFileIndex(DebFile); Indexes = new vector(); diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index f2706e08a..648c22436 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -36,7 +36,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { private: /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; std::map > ArchEntries; enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted; @@ -75,7 +75,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { class APT_HIDDEN debDebFileMetaIndex : public metaIndex { private: - void *d; + void * const d; std::string DebFile; debDebPkgFileIndex *DebIndex; public: diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index f527042e4..326102d08 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -34,7 +34,7 @@ using std::string; // RecordParser::debRecordParser - Constructor /*{{{*/ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : - debRecordParserBase(), File(FileName, FileFd::ReadOnly, FileFd::Extension), + debRecordParserBase(), d(NULL), File(FileName, FileFd::ReadOnly, FileFd::Extension), Tags(&File, std::max(Cache.Head().MaxVerFileSize, Cache.Head().MaxDescFileSize) + 200) { } @@ -51,7 +51,7 @@ bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) /*}}}*/ debRecordParser::~debRecordParser() {} -debRecordParserBase::debRecordParserBase() : Parser() {} +debRecordParserBase::debRecordParserBase() : Parser(), d(NULL) {} // RecordParserBase::FileName - Return the archive filename on the site /*{{{*/ string debRecordParserBase::FileName() { @@ -212,5 +212,5 @@ bool debDebFileRecordParser::Jump(pkgCache::VerFileIterator const &) { return Lo bool debDebFileRecordParser::Jump(pkgCache::DescFileIterator const &) { return LoadContent(); } std::string debDebFileRecordParser::FileName() { return debFileName; } -debDebFileRecordParser::debDebFileRecordParser(std::string FileName) : debRecordParserBase(), debFileName(FileName) {} +debDebFileRecordParser::debDebFileRecordParser(std::string FileName) : debRecordParserBase(), d(NULL), debFileName(FileName) {} debDebFileRecordParser::~debDebFileRecordParser() {} diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 8efcec8cd..4d0b713d4 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -27,7 +27,7 @@ class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser { - void *d; + void * const d; protected: pkgTagSection Section; @@ -57,7 +57,7 @@ class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser class APT_HIDDEN debRecordParser : public debRecordParserBase { - void *d; + void * const d; protected: FileFd File; pkgTagFile Tags; @@ -73,7 +73,7 @@ class APT_HIDDEN debRecordParser : public debRecordParserBase // custom record parser that reads deb files directly class APT_HIDDEN debDebFileRecordParser : public debRecordParserBase { - void *d; + void * const d; std::string debFileName; std::string controlContent; diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 21a4ff8ea..9404b6421 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -33,7 +33,7 @@ using std::max; using std::string; debSrcRecordParser::debSrcRecordParser(std::string const &File,pkgIndexFile const *Index) - : Parser(Index), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), + : Parser(Index), d(NULL), Fd(File,FileFd::ReadOnly, FileFd::Extension), Tags(&Fd,102400), iOffset(0), Buffer(NULL) {} // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index 7aeb2db88..64b07a1ec 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -24,7 +24,7 @@ class pkgIndexFile; class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser { /** \brief dpointer placeholder (for later in case we need it) */ - void *d; + void * const d; protected: FileFd Fd; diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc index 9a5da9da1..465e13b9e 100644 --- a/apt-pkg/deb/debsystem.cc +++ b/apt-pkg/deb/debsystem.cc @@ -53,11 +53,8 @@ public: // System::debSystem - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -debSystem::debSystem() +debSystem::debSystem() : pkgSystem("Debian dpkg interface", &debVS), d(new debSystemPrivate()) { - d = new debSystemPrivate(); - Label = "Debian dpkg interface"; - VS = &debVS; } /*}}}*/ // System::~debSystem - Destructor /*{{{*/ diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index 226cd60bf..e59bbebed 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -28,7 +28,7 @@ class debStatusIndex; class debSystem : public pkgSystem { // private d-pointer - debSystemPrivate *d; + debSystemPrivate * const d; APT_HIDDEN bool CheckUpdates(); public: diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 6ee939edd..1991a4a66 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -216,10 +216,9 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) - : pkgPackageManager(Cache), pkgFailures(0), PackagesDone(0), PackagesTotal(0) +pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) + : pkgPackageManager(Cache),d(new pkgDPkgPMPrivate()), pkgFailures(0), PackagesDone(0), PackagesTotal(0) { - d = new pkgDPkgPMPrivate(); } /*}}}*/ // DPkgPM::pkgDPkgPM - Destructor /*{{{*/ diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 2a6e7e004..a1b36c6c0 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -37,7 +37,7 @@ class pkgDPkgPMPrivate; class pkgDPkgPM : public pkgPackageManager { private: - pkgDPkgPMPrivate *d; + pkgDPkgPMPrivate * const d; /** \brief record the disappear action and handle accordingly -- cgit v1.2.3 From 3d8232bf97ce11818fb07813a71136484ea1a44a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 18 Jun 2015 17:33:15 +0200 Subject: fix memory leaks reported by -fsanitize Various small leaks here and there. Nothing particularily big, but still good to fix. Found by the sanitizers while running our testcases. Reported-By: gcc -fsanitize Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 2 +- apt-pkg/deb/debrecords.cc | 4 ++++ apt-pkg/deb/dpkgpm.cc | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 026af077f..5a517b290 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -270,7 +270,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const // special case for --print-uris std::vector const targets = GetIndexTargets(); #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) - pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, + pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), targets, iR); #undef APT_TARGET diff --git a/apt-pkg/deb/debrecords.cc b/apt-pkg/deb/debrecords.cc index 326102d08..d78a7e2e0 100644 --- a/apt-pkg/deb/debrecords.cc +++ b/apt-pkg/deb/debrecords.cc @@ -42,10 +42,14 @@ debRecordParser::debRecordParser(string FileName,pkgCache &Cache) : // RecordParser::Jump - Jump to a specific record /*{{{*/ bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver) { + if (Ver.end() == true) + return false; return Tags.Jump(Section,Ver->Offset); } bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc) { + if (Desc.end() == true) + return false; return Tags.Jump(Section,Desc->Offset); } /*}}}*/ diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 1991a4a66..3594a6efe 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1484,6 +1484,10 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) a != Args.end(); ++a) clog << *a << ' '; clog << endl; + for (std::vector::const_iterator p = Packages.begin(); + p != Packages.end(); ++p) + free(*p); + Packages.clear(); continue; } Args.push_back(NULL); -- cgit v1.2.3 From 463c8d801595ce5ac94d7c032264820be7434232 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 21 Jun 2015 16:47:53 +0200 Subject: support lang= and target= sources.list options We support arch= for a while, now we finally add lang= as well and as a first simple way of controlling which targets to acquire also target=. This asked for a redesign of the internal API of parsing and storing information about 'deb' and 'deb-src' lines. As this API isn't visible to the outside no damage done through. Beside being a nice cleanup (= it actually does more in less lines) it also provides us with a predictable order of architectures as provides in the configuration rather than based on string sorting-order, so that now the native architecture is parsed/displayed first. Observeable e.g. in apt-get output. --- apt-pkg/deb/debindexfile.cc | 6 +- apt-pkg/deb/debmetaindex.cc | 430 +++++++++++++++++++------------------------- apt-pkg/deb/debmetaindex.h | 38 ++-- 3 files changed, 202 insertions(+), 272 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 29a9a941c..c5086b04b 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -510,7 +510,7 @@ class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type { return new debDebFileRecordParser(File.FileName()); }; - debIFTypeDebPkgFile() {Label = "deb Package file";}; + debIFTypeDebPkgFile() {Label = "Debian deb file";}; }; class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type { @@ -519,7 +519,7 @@ class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type { return new debDscRecordParser(DscFile, NULL); }; - debIFTypeDscFile() {Label = "dsc File Source Index";}; + debIFTypeDscFile() {Label = "Debian dsc file";}; }; class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type { @@ -528,7 +528,7 @@ class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type { return new debDscRecordParser(SourceDir + string("/debian/control"), NULL); }; - debIFTypeDebianSourceDir() {Label = "debian/control File Source Index";}; + debIFTypeDebianSourceDir() {Label = "Debian control file";}; }; APT_HIDDEN debIFTypeSrc _apt_Src; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 5a517b290..f690a8d64 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -29,11 +29,25 @@ #include #include -using namespace std; - -string debReleaseIndex::MetaIndexInfo(const char *Type) const +class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ +{ + public: + struct APT_HIDDEN debSectionEntry + { + std::string Name; + std::vector Targets; + std::vector Architectures; + std::vector Languages; + }; + + std::vector DebEntries; + std::vector DebSrcEntries; +}; + /*}}}*/ +// ReleaseIndex::MetaIndex* - display helpers /*{{{*/ +std::string debReleaseIndex::MetaIndexInfo(const char *Type) const { - string Info = ::URI::ArchiveOnly(URI) + ' '; + std::string Info = ::URI::ArchiveOnly(URI) + ' '; if (Dist[Dist.size() - 1] == '/') { if (Dist != "/") @@ -50,15 +64,15 @@ std::string debReleaseIndex::Describe() const return MetaIndexInfo("Release"); } -string debReleaseIndex::MetaIndexFile(const char *Type) const +std::string debReleaseIndex::MetaIndexFile(const char *Type) const { return _config->FindDir("Dir::State::lists") + URItoFileName(MetaIndexURI(Type)); } -string debReleaseIndex::MetaIndexURI(const char *Type) const +std::string debReleaseIndex::MetaIndexURI(const char *Type) const { - string Res; + std::string Res; if (Dist == "/") Res = URI; @@ -70,8 +84,8 @@ string debReleaseIndex::MetaIndexURI(const char *Type) const Res += Type; return Res; } - -std::string debReleaseIndex::LocalFileName() const + /*}}}*/ +std::string debReleaseIndex::LocalFileName() const /*{{{*/ { // see if we have a InRelease file std::string PathInRelease = MetaIndexFile("InRelease"); @@ -84,28 +98,24 @@ std::string debReleaseIndex::LocalFileName() const return ""; } - -debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) : - metaIndex(URI, Dist, "deb"), d(NULL), Trusted(CHECK_TRUST) + /*}}}*/ +// ReleaseIndex Con- and Destructors /*{{{*/ +debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) : + metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()), Trusted(CHECK_TRUST) {} - -debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist, bool const Trusted) : - metaIndex(URI, Dist, "deb"), d(NULL) { +debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted) : + metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) { SetTrusted(Trusted); } - debReleaseIndex::~debReleaseIndex() { - for (map >::const_iterator A = ArchEntries.begin(); - A != ArchEntries.end(); ++A) - for (vector::const_iterator S = A->second.begin(); - S != A->second.end(); ++S) - delete *S; + if (d != NULL) + delete d; } - -template -void foreachTarget(std::string const &URI, std::string const &Dist, - std::map > const &ArchEntries, - CallC &Call) + /*}}}*/ +// ReleaseIndex::GetIndexTargets /*{{{*/ +static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist, + std::vector const &entries, + std::vector &IndexTargets) { bool const flatArchive = (Dist[Dist.length() - 1] == '/'); std::string baseURI = URI; @@ -118,148 +128,101 @@ void foreachTarget(std::string const &URI, std::string const &Dist, baseURI += "dists/" + Dist + "/"; std::string const Release = (Dist == "/") ? "" : Dist; std::string const Site = ::URI::ArchiveOnly(URI); - std::vector lang = APT::Configuration::getLanguages(true); - if (lang.empty()) - lang.push_back("none"); - map >::const_iterator const src = ArchEntries.find("source"); - if (src != ArchEntries.end()) + + for (std::vector::const_iterator E = entries.begin(); E != entries.end(); ++E) { - std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb-src", "", true); - for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) + for (std::vector::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T) { -#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X)) - std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); - std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); - std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); +#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::" + (X)) + std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); + std::string const tplShortDesc = APT_T_CONFIG("ShortDescription"); + std::string const tplLongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true); #undef APT_T_CONFIG - if (MetaKey.empty()) + if (tplMetaKey.empty()) continue; - vector const SectionEntries = src->second; - for (vector::const_iterator I = SectionEntries.begin(); - I != SectionEntries.end(); ++I) + for (std::vector::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L) { - for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) + if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos) + continue; + + for (std::vector::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A) { - if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) - continue; std::map Options; Options.insert(std::make_pair("SITE", Site)); Options.insert(std::make_pair("RELEASE", Release)); - if (MetaKey.find("$(COMPONENT)") != std::string::npos) - Options.insert(std::make_pair("COMPONENT", (*I)->Section)); - if (MetaKey.find("$(LANGUAGE)") != std::string::npos) - Options.insert(std::make_pair("LANGUAGE", *l)); - Options.insert(std::make_pair("ARCHITECTURE", "source")); + if (tplMetaKey.find("$(COMPONENT)") != std::string::npos) + Options.insert(std::make_pair("COMPONENT", E->Name)); + if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos) + Options.insert(std::make_pair("LANGUAGE", *L)); + if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos) + Options.insert(std::make_pair("ARCHITECTURE", *A)); Options.insert(std::make_pair("BASE_URI", baseURI)); Options.insert(std::make_pair("REPO_URI", URI)); Options.insert(std::make_pair("TARGET_OF", "deb-src")); Options.insert(std::make_pair("CREATED_BY", *T)); - Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); - if (MetaKey.find("$(LANGUAGE)") == std::string::npos) + std::string MetaKey = tplMetaKey; + std::string ShortDesc = tplShortDesc; + std::string LongDesc = tplLongDesc; + for (std::map::const_iterator O = Options.begin(); O != Options.end(); ++O) + { + MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second); + ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); + LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); + } + IndexTarget Target( + MetaKey, + ShortDesc, + LongDesc, + Options.find("BASE_URI")->second + MetaKey, + IsOptional, + Options + ); + IndexTargets.push_back(Target); + + if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos) break; - } - - if (MetaKey.find("$(COMPONENT)") == std::string::npos) - break; - } - } - } - - std::vector const targets = _config->FindVector("APT::Acquire::Targets::deb", "", true); - for (std::vector::const_iterator T = targets.begin(); T != targets.end(); ++T) - { -#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X)) - std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); - std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); - std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); - bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb::") + *T + "::Optional", true); -#undef APT_T_CONFIG - if (MetaKey.empty()) - continue; - - for (map >::const_iterator a = ArchEntries.begin(); - a != ArchEntries.end(); ++a) - { - if (a->first == "source") - continue; - - for (vector ::const_iterator I = a->second.begin(); - I != a->second.end(); ++I) { - - for (vector::const_iterator l = lang.begin(); l != lang.end(); ++l) - { - if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) - continue; - - std::map Options; - Options.insert(std::make_pair("SITE", Site)); - Options.insert(std::make_pair("RELEASE", Release)); - if (MetaKey.find("$(COMPONENT)") != std::string::npos) - Options.insert(std::make_pair("COMPONENT", (*I)->Section)); - if (MetaKey.find("$(LANGUAGE)") != std::string::npos) - Options.insert(std::make_pair("LANGUAGE", *l)); - if (MetaKey.find("$(ARCHITECTURE)") != std::string::npos) - Options.insert(std::make_pair("ARCHITECTURE", a->first)); - Options.insert(std::make_pair("BASE_URI", baseURI)); - Options.insert(std::make_pair("REPO_URI", URI)); - Options.insert(std::make_pair("TARGET_OF", "deb")); - Options.insert(std::make_pair("CREATED_BY", *T)); - Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); - if (MetaKey.find("$(LANGUAGE)") == std::string::npos) - break; } - if (MetaKey.find("$(COMPONENT)") == std::string::npos) + if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos) break; + } - if (MetaKey.find("$(ARCHITECTURE)") == std::string::npos) - break; } } } - - -struct ComputeIndexTargetsClass -{ - vector IndexTargets; - - void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc, - bool const IsOptional, std::map Options) - { - for (std::map::const_iterator O = Options.begin(); O != Options.end(); ++O) - { - MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second); - ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); - LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); - } - IndexTarget Target( - MetaKey, - ShortDesc, - LongDesc, - Options.find("BASE_URI")->second + MetaKey, - IsOptional, - Options - ); - IndexTargets.push_back(Target); - } -}; - std::vector debReleaseIndex::GetIndexTargets() const { - ComputeIndexTargetsClass comp; - foreachTarget(URI, Dist, ArchEntries, comp); - return comp.IndexTargets; + std::vector IndexTargets; + GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets); + GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets); + return IndexTargets; } + /*}}}*/ +void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{{{*/ + std::vector const &Targets, + std::vector const &Architectures, + std::vector Languages) +{ + if (Languages.empty() == true) + Languages.push_back("none"); + debReleaseIndexPrivate::debSectionEntry const entry = { + Name, Targets, Architectures, Languages + }; + if (isSrc) + d->DebSrcEntries.push_back(entry); + else + d->DebEntries.push_back(entry); +} + /*}}}*/ - /*}}}*/ -bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const +bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{{{*/ { indexRecords * const iR = new indexRecords(Dist); if (Trusted == ALWAYS_TRUSTED) @@ -282,7 +245,8 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const return true; } - + /*}}}*/ +// ReleaseIndex::*Trusted setters and checkers /*{{{*/ void debReleaseIndex::SetTrusted(bool const Trusted) { if (Trusted == true) @@ -290,7 +254,6 @@ void debReleaseIndex::SetTrusted(bool const Trusted) else this->Trusted = NEVER_TRUSTED; } - bool debReleaseIndex::IsTrusted() const { if (Trusted == ALWAYS_TRUSTED) @@ -303,19 +266,13 @@ bool debReleaseIndex::IsTrusted() const if(URI.substr(0,strlen("cdrom:")) == "cdrom:") return true; - string VerifiedSigFile = _config->FindDir("Dir::State::lists") + - URItoFileName(MetaIndexURI("Release")) + ".gpg"; - - if (FileExists(VerifiedSigFile)) + if (FileExists(MetaIndexFile("Release.gpg"))) return true; - VerifiedSigFile = _config->FindDir("Dir::State::lists") + - URItoFileName(MetaIndexURI("InRelease")); - - return FileExists(VerifiedSigFile); + return FileExists(MetaIndexFile("InRelease")); } - -std::vector *debReleaseIndex::GetIndexFiles() + /*}}}*/ +std::vector *debReleaseIndex::GetIndexFiles() /*{{{*/ { if (Indexes != NULL) return Indexes; @@ -335,23 +292,9 @@ std::vector *debReleaseIndex::GetIndexFiles() } return Indexes; } + /*}}}*/ -void debReleaseIndex::PushSectionEntry(vector const &Archs, const debSectionEntry *Entry) { - for (vector::const_iterator a = Archs.begin(); - a != Archs.end(); ++a) - ArchEntries[*a].push_back(new debSectionEntry(Entry->Section, Entry->IsSrc)); - delete Entry; -} - -void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry *Entry) { - ArchEntries[Arch].push_back(Entry); -} - -debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section, - bool const &IsSrc): Section(Section), IsSrc(IsSrc) -{} - -static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile) +static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/ { ReleaseFile = That->MetaIndexFile("InRelease"); bool releaseExists = false; @@ -365,7 +308,7 @@ static bool ReleaseFileName(debReleaseIndex const * const That, std::string &Rel } return releaseExists; } - + /*}}}*/ bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/ { std::string ReleaseFile; @@ -459,46 +402,46 @@ pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool con } /*}}}*/ -debDebFileMetaIndex::~debDebFileMetaIndex() {} - -class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type +static std::vector parsePlusMinusOptions(std::string const &Name, /*{{{*/ + std::map const &Options, std::vector const &defaultValues) { - protected: + std::map::const_iterator val = Options.find(Name); + std::vector Values; + if (val != Options.end()) + Values = VectorizeString(val->second, ','); + else + Values = defaultValues; - bool CreateItemInternal(vector &List, string const &URI, - string const &Dist, string const &Section, - bool const &IsSrc, map const &Options) const + if ((val = Options.find(Name + "+")) != Options.end()) { - // parse arch=, arch+= and arch-= settings - map::const_iterator arch = Options.find("arch"); - vector Archs; - if (arch != Options.end()) - Archs = VectorizeString(arch->second, ','); - else - Archs = APT::Configuration::getArchitectures(); - - if ((arch = Options.find("arch+")) != Options.end()) - { - std::vector const plusArch = VectorizeString(arch->second, ','); - for (std::vector::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus) - if (std::find(Archs.begin(), Archs.end(), *plus) == Archs.end()) - Archs.push_back(*plus); - } - if ((arch = Options.find("arch-")) != Options.end()) + std::vector const plusArch = VectorizeString(val->second, ','); + for (std::vector::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus) + if (std::find(Values.begin(), Values.end(), *plus) == Values.end()) + Values.push_back(*plus); + } + if ((val = Options.find(Name + "-")) != Options.end()) + { + std::vector const minusArch = VectorizeString(val->second, ','); + for (std::vector::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus) { - std::vector const minusArch = VectorizeString(arch->second, ','); - for (std::vector::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus) - { - std::vector::iterator kill = std::find(Archs.begin(), Archs.end(), *minus); - if (kill != Archs.end()) - Archs.erase(kill); - } + std::vector::iterator kill = std::find(Values.begin(), Values.end(), *minus); + if (kill != Values.end()) + Values.erase(kill); } + } + return Values; +} + /*}}}*/ +class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ +{ + protected: - map::const_iterator const trusted = Options.find("trusted"); - + bool CreateItemInternal(std::vector &List, std::string const &URI, + std::string const &Dist, std::string const &Section, + bool const &IsSrc, std::map const &Options) const + { debReleaseIndex *Deb = NULL; - for (vector::const_iterator I = List.begin(); + for (std::vector::const_iterator I = List.begin(); I != List.end(); ++I) { // We only worry about debian entries here @@ -523,87 +466,86 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type List.push_back(Deb); } - if (IsSrc == true) - Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); - else - { - if (Dist[Dist.size() - 1] == '/') - Deb->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section, IsSrc)); - else - Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); - } + Deb->AddComponent( + IsSrc, + Section, + parsePlusMinusOptions("target", Options, _config->FindVector(std::string("APT::Acquire::Targets::") + Name, "", true)), + parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()), + parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)) + ); + std::map::const_iterator const trusted = Options.find("trusted"); if (trusted != Options.end()) Deb->SetTrusted(StringToBool(trusted->second, false)); return true; } -}; - -debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile) - : metaIndex(DebFile, "local-uri", "deb-dist"), d(NULL), DebFile(DebFile) -{ - DebIndex = new debDebPkgFileIndex(DebFile); - Indexes = new vector(); - Indexes->push_back(DebIndex); -} - -class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian + debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label) + { + } +}; + /*}}}*/ +class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/ { public: - bool CreateItem(vector &List, string const &URI, - string const &Dist, string const &Section, - std::map const &Options) const + bool CreateItem(std::vector &List, std::string const &URI, + std::string const &Dist, std::string const &Section, + std::map const &Options) const { return CreateItemInternal(List, URI, Dist, Section, false, Options); } - debSLTypeDeb() + debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree") { - Name = "deb"; - Label = "Standard Debian binary tree"; - } + } }; - -class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian + /*}}}*/ +class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/ { public: - bool CreateItem(vector &List, string const &URI, - string const &Dist, string const &Section, - std::map const &Options) const + bool CreateItem(std::vector &List, std::string const &URI, + std::string const &Dist, std::string const &Section, + std::map const &Options) const { return CreateItemInternal(List, URI, Dist, Section, true, Options); } - - debSLTypeDebSrc() + + debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree") { - Name = "deb-src"; - Label = "Standard Debian source tree"; - } + } }; + /*}}}*/ -class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type +debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile) /*{{{*/ + : metaIndex(DebFile, "local-uri", "deb-dist"), d(NULL), DebFile(DebFile) +{ + DebIndex = new debDebPkgFileIndex(DebFile); + Indexes = new std::vector(); + Indexes->push_back(DebIndex); +} +debDebFileMetaIndex::~debDebFileMetaIndex() {} + /*}}}*/ +class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type /*{{{*/ { public: - bool CreateItem(vector &List, string const &URI, - string const &/*Dist*/, string const &/*Section*/, - std::map const &/*Options*/) const + bool CreateItem(std::vector &List, std::string const &URI, + std::string const &/*Dist*/, std::string const &/*Section*/, + std::map const &/*Options*/) const { metaIndex *mi = new debDebFileMetaIndex(URI); List.push_back(mi); return true; } - - debSLTypeDebFile() + + debSLTypeDebFile() : Type("deb-file", "Debian local deb file") { - Name = "deb-file"; - Label = "Debian Deb File"; - } + } }; + /*}}}*/ APT_HIDDEN debSLTypeDeb _apt_DebType; APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 648c22436..9b60b6137 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -1,4 +1,3 @@ -// ijones, walters #ifndef PKGLIB_DEBMETAINDEX_H #define PKGLIB_DEBMETAINDEX_H @@ -22,26 +21,20 @@ class debDebPkgFileIndex; class IndexTarget; class pkgCacheGenerator; class OpProgress; +class debReleaseIndexPrivate; -class APT_HIDDEN debReleaseIndex : public metaIndex { - public: +class APT_HIDDEN debReleaseIndex : public metaIndex +{ + debReleaseIndexPrivate * const d; - class debSectionEntry - { - public: - debSectionEntry (std::string const &Section, bool const &IsSrc); - std::string const Section; - bool const IsSrc; - }; - - private: - /** \brief dpointer placeholder (for later in case we need it) */ - void * const d; - std::map > ArchEntries; enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted; public: + APT_HIDDEN std::string MetaIndexInfo(const char *Type) const; + APT_HIDDEN std::string MetaIndexFile(const char *Types) const; + APT_HIDDEN std::string MetaIndexURI(const char *Type) const; + debReleaseIndex(std::string const &URI, std::string const &Dist); debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted); virtual ~debReleaseIndex(); @@ -54,22 +47,17 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - std::string MetaIndexInfo(const char *Type) const; - std::string MetaIndexFile(const char *Types) const; - std::string MetaIndexURI(const char *Type) const; - -#if APT_PKG_ABI >= 413 - virtual -#endif - std::string LocalFileName() const; + virtual std::string LocalFileName() const; virtual std::vector *GetIndexFiles(); void SetTrusted(bool const Trusted); virtual bool IsTrusted() const; - void PushSectionEntry(std::vector const &Archs, const debSectionEntry *Entry); - void PushSectionEntry(std::string const &Arch, const debSectionEntry *Entry); + void AddComponent(bool const isSrc, std::string const &Name, + std::vector const &Targets, + std::vector const &Architectures, + std::vector Languages); }; class APT_HIDDEN debDebFileMetaIndex : public metaIndex -- cgit v1.2.3 From 268ffcebb9ae4278b1e3c3f89f8167f229164dbd Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 22 Jun 2015 12:34:11 +0200 Subject: detect and error out on conflicting Trusted settings A specific trust state can be enforced via a sources.list option, but it effects all entries handled by the same Release file, not just the entry it was given on so we enforce acknowledgement of this by requiring the same value to be (not) set on all such entries. --- apt-pkg/deb/debmetaindex.cc | 43 ++++++++++++++++++++++++++++--------------- apt-pkg/deb/debmetaindex.h | 8 +++++--- 2 files changed, 33 insertions(+), 18 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index f690a8d64..1f725ba05 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -29,6 +29,8 @@ #include #include +#include + class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ { public: @@ -42,6 +44,11 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ std::vector DebEntries; std::vector DebSrcEntries; + + debReleaseIndex::TriState Trusted; + + debReleaseIndexPrivate() : Trusted(debReleaseIndex::TRI_UNSET) {} + debReleaseIndexPrivate(bool const pTrusted) : Trusted(pTrusted ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) {} }; /*}}}*/ // ReleaseIndex::MetaIndex* - display helpers /*{{{*/ @@ -101,12 +108,11 @@ std::string debReleaseIndex::LocalFileName() const /*{{{*/ /*}}}*/ // ReleaseIndex Con- and Destructors /*{{{*/ debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) : - metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()), Trusted(CHECK_TRUST) + metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) {} debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted) : - metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) { - SetTrusted(Trusted); -} + metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate(Trusted)) +{} debReleaseIndex::~debReleaseIndex() { if (d != NULL) delete d; @@ -225,9 +231,9 @@ void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{{{*/ { indexRecords * const iR = new indexRecords(Dist); - if (Trusted == ALWAYS_TRUSTED) + if (d->Trusted == TRI_YES) iR->SetTrusted(true); - else if (Trusted == NEVER_TRUSTED) + else if (d->Trusted == TRI_NO) iR->SetTrusted(false); // special case for --print-uris @@ -246,19 +252,21 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{ return true; } /*}}}*/ -// ReleaseIndex::*Trusted setters and checkers /*{{{*/ -void debReleaseIndex::SetTrusted(bool const Trusted) +// ReleaseIndex::IsTrusted /*{{{*/ +bool debReleaseIndex::SetTrusted(TriState const Trusted) { - if (Trusted == true) - this->Trusted = ALWAYS_TRUSTED; - else - this->Trusted = NEVER_TRUSTED; + if (d->Trusted == TRI_UNSET) + d->Trusted = Trusted; + else if (d->Trusted != Trusted) + // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite + return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); + return true; } bool debReleaseIndex::IsTrusted() const { - if (Trusted == ALWAYS_TRUSTED) + if (d->Trusted == TRI_YES) return true; - else if (Trusted == NEVER_TRUSTED) + else if (d->Trusted == TRI_NO) return false; @@ -476,7 +484,12 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ std::map::const_iterator const trusted = Options.find("trusted"); if (trusted != Options.end()) - Deb->SetTrusted(StringToBool(trusted->second, false)); + { + if (Deb->SetTrusted(StringToBool(trusted->second, false) ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) == false) + return false; + } + else if (Deb->SetTrusted(debReleaseIndex::TRI_DONTCARE) == false) + return false; return true; } diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 9b60b6137..a6db4e287 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -27,8 +27,6 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { debReleaseIndexPrivate * const d; - enum APT_HIDDEN { ALWAYS_TRUSTED, NEVER_TRUSTED, CHECK_TRUST } Trusted; - public: APT_HIDDEN std::string MetaIndexInfo(const char *Type) const; @@ -51,7 +49,11 @@ class APT_HIDDEN debReleaseIndex : public metaIndex virtual std::vector *GetIndexFiles(); - void SetTrusted(bool const Trusted); + enum APT_HIDDEN TriState { + TRI_YES, TRI_DONTCARE, TRI_NO, TRI_UNSET + }; + bool SetTrusted(TriState const Trusted); + virtual bool IsTrusted() const; void AddComponent(bool const isSrc, std::string const &Name, -- cgit v1.2.3 From 5ad0096a4e19e191b59634e8a8817995ec4045ad Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 23 Jun 2015 15:16:08 +0200 Subject: merge indexRecords into metaIndex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit indexRecords was used to parse the Release file – mostly the hashes – while metaIndex deals with downloading the Release file, storing all indexes coming from this release and … parsing the Release file, but this time mostly for the other fields. That wasn't a problem in metaIndex as this was done in the type specific subclass, but indexRecords while allowing to override the parsing method did expect by default a specific format. APT isn't really supporting different types at the moment, but this is a violation of the abstraction we have everywhere else and, which is the actual reason for this merge: Options e.g. coming from the sources.list come to metaIndex naturally, which needs to wrap them up and bring them into indexRecords, so the acquire system is told about it as they don't get to see the metaIndex, but they don't really belong in indexRecords as this is just for storing data loaded from the Release file… the result is a complete mess. I am not saying it is a lot prettier after the merge, but at least adding new options is now slightly easier and there is just one place responsible for parsing the Release file. That can't hurt. --- apt-pkg/deb/debmetaindex.cc | 231 +++++++++++++++++++++++++++++++++++++------- apt-pkg/deb/debmetaindex.h | 29 ++++-- 2 files changed, 215 insertions(+), 45 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 1f725ba05..f0b859eb4 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -45,10 +44,7 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ std::vector DebEntries; std::vector DebSrcEntries; - debReleaseIndex::TriState Trusted; - - debReleaseIndexPrivate() : Trusted(debReleaseIndex::TRI_UNSET) {} - debReleaseIndexPrivate(bool const pTrusted) : Trusted(pTrusted ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) {} + debReleaseIndexPrivate() {} }; /*}}}*/ // ReleaseIndex::MetaIndex* - display helpers /*{{{*/ @@ -92,27 +88,15 @@ std::string debReleaseIndex::MetaIndexURI(const char *Type) const return Res; } /*}}}*/ -std::string debReleaseIndex::LocalFileName() const /*{{{*/ -{ - // see if we have a InRelease file - std::string PathInRelease = MetaIndexFile("InRelease"); - if (FileExists(PathInRelease)) - return PathInRelease; - - // and if not return the normal one - if (FileExists(PathInRelease)) - return MetaIndexFile("Release"); - - return ""; -} - /*}}}*/ // ReleaseIndex Con- and Destructors /*{{{*/ debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) : metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) {} -debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted) : - metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate(Trusted)) -{} +debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) : + metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate()) +{ + Trusted = pTrusted ? TRI_YES : TRI_NO; +} debReleaseIndex::~debReleaseIndex() { if (d != NULL) delete d; @@ -227,22 +211,197 @@ void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{ } /*}}}*/ +bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/ +{ + LoadedSuccessfully = TRI_NO; + FileFd Fd; + if (OpenMaybeClearSignedFile(Filename, Fd) == false) + return false; + + pkgTagFile TagFile(&Fd, Fd.Size()); + if (_error->PendingError() == true) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str()); + return false; + } + + pkgTagSection Section; + const char *Start, *End; + if (TagFile.Step(Section) == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str()); + return false; + } + // FIXME: find better tag name + SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false); + + Suite = Section.FindS("Suite"); + Codename = Section.FindS("Codename"); + + bool FoundHashSum = false; + for (int i=0;HashString::SupportedHashes()[i] != NULL; i++) + { + if (!Section.Find(HashString::SupportedHashes()[i], Start, End)) + continue; + + std::string Name; + std::string Hash; + unsigned long long Size; + while (Start < End) + { + if (!parseSumData(Start, End, Name, Hash, Size)) + return false; + + if (Entries.find(Name) == Entries.end()) + { + metaIndex::checkSum *Sum = new metaIndex::checkSum; + Sum->MetaKeyFilename = Name; + Sum->Size = Size; + Sum->Hashes.FileSize(Size); + APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);) + Entries[Name] = Sum; + } + Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash)); + FoundHashSum = true; + } + } + + if(FoundHashSum == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); + return false; + } + + std::string const StrDate = Section.FindS("Date"); + if (RFC1123StrToTime(StrDate.c_str(), Date) == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; + } -bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{{{*/ + std::string const Label = Section.FindS("Label"); + std::string const StrValidUntil = Section.FindS("Valid-Until"); + + // if we have a Valid-Until header in the Release file, use it as default + if (StrValidUntil.empty() == false) + { + if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); + return false; + } + } + // get the user settings for this archive and use what expires earlier + int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); + if (Label.empty() == false) + MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); + int MinAge = _config->FindI("Acquire::Min-ValidTime", 0); + if (Label.empty() == false) + MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge); + + LoadedSuccessfully = TRI_YES; + if(MaxAge == 0 && + (MinAge == 0 || ValidUntil == 0)) // No user settings, use the one from the Release file + return true; + + if (MinAge != 0 && ValidUntil != 0) { + time_t const min_date = Date + MinAge; + if (ValidUntil < min_date) + ValidUntil = min_date; + } + if (MaxAge != 0) { + time_t const max_date = Date + MaxAge; + if (ValidUntil == 0 || ValidUntil > max_date) + ValidUntil = max_date; + } + + return true; +} + /*}}}*/ +metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/ +{ + if (Trusted == TRI_NO) + return new debReleaseIndex(URI, Dist, false); + else if (Trusted == TRI_YES) + return new debReleaseIndex(URI, Dist, true); + else + return new debReleaseIndex(URI, Dist); +} + /*}}}*/ +bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/ + std::string &Name, std::string &Hash, unsigned long long &Size) { - indexRecords * const iR = new indexRecords(Dist); - if (d->Trusted == TRI_YES) - iR->SetTrusted(true); - else if (d->Trusted == TRI_NO) - iR->SetTrusted(false); + Name = ""; + Hash = ""; + Size = 0; + /* Skip over the first blank */ + while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r') + && Start < End) + Start++; + if (Start >= End) + return false; - // special case for --print-uris + /* Move EntryEnd to the end of the first entry (the hash) */ + const char *EntryEnd = Start; + while ((*EntryEnd != '\t' && *EntryEnd != ' ') + && EntryEnd < End) + EntryEnd++; + if (EntryEnd == End) + return false; + + Hash.append(Start, EntryEnd-Start); + + /* Skip over intermediate blanks */ + Start = EntryEnd; + while (*Start == '\t' || *Start == ' ') + Start++; + if (Start >= End) + return false; + + EntryEnd = Start; + /* Find the end of the second entry (the size) */ + while ((*EntryEnd != '\t' && *EntryEnd != ' ' ) + && EntryEnd < End) + EntryEnd++; + if (EntryEnd == End) + return false; + + Size = strtoull (Start, NULL, 10); + + /* Skip over intermediate blanks */ + Start = EntryEnd; + while (*Start == '\t' || *Start == ' ') + Start++; + if (Start >= End) + return false; + + EntryEnd = Start; + /* Find the end of the third entry (the filename) */ + while ((*EntryEnd != '\t' && *EntryEnd != ' ' && + *EntryEnd != '\n' && *EntryEnd != '\r') + && EntryEnd < End) + EntryEnd++; + + Name.append(Start, EntryEnd-Start); + Start = EntryEnd; //prepare for the next round + return true; +} + /*}}}*/ + +bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/ +{ std::vector const targets = GetIndexTargets(); #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), - targets, iR); + targets, this); #undef APT_TARGET + // special case for --print-uris if (GetAll) { for (std::vector::const_iterator Target = targets.begin(); Target != targets.end(); ++Target) @@ -253,20 +412,20 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const/*{ } /*}}}*/ // ReleaseIndex::IsTrusted /*{{{*/ -bool debReleaseIndex::SetTrusted(TriState const Trusted) +bool debReleaseIndex::SetTrusted(TriState const pTrusted) { - if (d->Trusted == TRI_UNSET) - d->Trusted = Trusted; - else if (d->Trusted != Trusted) + if (Trusted == TRI_UNSET) + Trusted = pTrusted; + else if (Trusted != pTrusted) // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); return true; } bool debReleaseIndex::IsTrusted() const { - if (d->Trusted == TRI_YES) + if (Trusted == TRI_YES) return true; - else if (d->Trusted == TRI_NO) + else if (Trusted == TRI_NO) return false; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index a6db4e287..19fe6806c 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -27,6 +27,8 @@ class APT_HIDDEN debReleaseIndex : public metaIndex { debReleaseIndexPrivate * const d; + APT_HIDDEN bool parseSumData(const char *&Start, const char *End, std::string &Name, + std::string &Hash, unsigned long long &Size); public: APT_HIDDEN std::string MetaIndexInfo(const char *Type) const; @@ -38,20 +40,18 @@ class APT_HIDDEN debReleaseIndex : public metaIndex virtual ~debReleaseIndex(); virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; - virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) const; + virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false); virtual std::vector GetIndexTargets() const; virtual std::string Describe() const; virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const; virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - virtual std::string LocalFileName() const; + virtual bool Load(std::string const &Filename, std::string * const ErrorText); + virtual metaIndex * UnloadedClone() const; virtual std::vector *GetIndexFiles(); - enum APT_HIDDEN TriState { - TRI_YES, TRI_DONTCARE, TRI_NO, TRI_UNSET - }; bool SetTrusted(TriState const Trusted); virtual bool IsTrusted() const; @@ -64,15 +64,15 @@ class APT_HIDDEN debReleaseIndex : public metaIndex class APT_HIDDEN debDebFileMetaIndex : public metaIndex { - private: - void * const d; +private: + void * const d; std::string DebFile; debDebPkgFileIndex *DebIndex; - public: +public: virtual std::string ArchiveURI(std::string const& /*File*/) const { return DebFile; } - virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) const { + virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) { return true; } virtual std::vector GetIndexTargets() const { @@ -84,6 +84,17 @@ class APT_HIDDEN debDebFileMetaIndex : public metaIndex virtual bool IsTrusted() const { return true; } + virtual bool Load(std::string const &, std::string * const ErrorText) + { + LoadedSuccessfully = TRI_NO; + if (ErrorText != NULL) + strprintf(*ErrorText, "Unparseable metaindex as it represents the standalone deb file %s", DebFile.c_str()); + return false; + } + virtual metaIndex * UnloadedClone() const + { + return NULL; + } debDebFileMetaIndex(std::string const &DebFile); virtual ~debDebFileMetaIndex(); -- cgit v1.2.3 From 0741daeb7ab870b4dd62a93fa12a1cf6330f9a72 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 23 Jun 2015 17:26:57 +0200 Subject: add sources.list Check-Valid-Until and Valid-Until-{Max,Min} options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These options could be set via configuration before, but the connection to the actual sources is so strong that they should really be set in the sources.list instead – especially as this can be done a lot more specific rather than e.g. disabling Valid-Until for all sources at once. Valid-Until-* names are chosen instead of the Min/Max-ValidTime as this seems like a better name and their use in the wild is probably low enough that this isn't going to confuse anyone if we have to names for the same thing in different areas. In the longrun, the config options should be removed, but for now documentation hinting at the new options is good enough as these are the kind of options you set once across many systems with different apt versions, so the new way should work everywhere first before we deprecate the old way. --- apt-pkg/deb/debmetaindex.cc | 134 +++++++++++++++++++++++++++++++------------- apt-pkg/deb/debmetaindex.h | 3 + 2 files changed, 98 insertions(+), 39 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index f0b859eb4..5d7e539c7 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -44,7 +44,11 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ std::vector DebEntries; std::vector DebSrcEntries; - debReleaseIndexPrivate() {} + metaIndex::TriState CheckValidUntil; + time_t ValidUntilMin; + time_t ValidUntilMax; + + debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {} }; /*}}}*/ // ReleaseIndex::MetaIndex* - display helpers /*{{{*/ @@ -283,43 +287,56 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro return false; } - std::string const Label = Section.FindS("Label"); - std::string const StrValidUntil = Section.FindS("Valid-Until"); + bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true); + if (d->CheckValidUntil == metaIndex::TRI_NO) + CheckValidUntil = false; + else if (d->CheckValidUntil == metaIndex::TRI_YES) + CheckValidUntil = true; - // if we have a Valid-Until header in the Release file, use it as default - if (StrValidUntil.empty() == false) + if (CheckValidUntil == true) { - if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) + std::string const Label = Section.FindS("Label"); + std::string const StrValidUntil = Section.FindS("Valid-Until"); + + // if we have a Valid-Until header in the Release file, use it as default + if (StrValidUntil.empty() == false) { - if (ErrorText != NULL) - strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); - return false; + if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); + return false; + } + } + // get the user settings for this archive and use what expires earlier + time_t MaxAge = d->ValidUntilMax; + if (MaxAge == 0) + { + MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); + if (Label.empty() == false) + MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); + } + time_t MinAge = d->ValidUntilMin; + if (MinAge == 0) + { + MinAge = _config->FindI("Acquire::Min-ValidTime", 0); + if (Label.empty() == false) + MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge); } - } - // get the user settings for this archive and use what expires earlier - int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); - if (Label.empty() == false) - MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); - int MinAge = _config->FindI("Acquire::Min-ValidTime", 0); - if (Label.empty() == false) - MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge); - - LoadedSuccessfully = TRI_YES; - if(MaxAge == 0 && - (MinAge == 0 || ValidUntil == 0)) // No user settings, use the one from the Release file - return true; - if (MinAge != 0 && ValidUntil != 0) { - time_t const min_date = Date + MinAge; - if (ValidUntil < min_date) - ValidUntil = min_date; - } - if (MaxAge != 0) { - time_t const max_date = Date + MaxAge; - if (ValidUntil == 0 || ValidUntil > max_date) - ValidUntil = max_date; + if (MinAge != 0 && ValidUntil != 0) { + time_t const min_date = Date + MinAge; + if (ValidUntil < min_date) + ValidUntil = min_date; + } + if (MaxAge != 0) { + time_t const max_date = Date + MaxAge; + if (ValidUntil == 0 || ValidUntil > max_date) + ValidUntil = max_date; + } } + LoadedSuccessfully = TRI_YES; return true; } /*}}}*/ @@ -411,7 +428,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/ return true; } /*}}}*/ -// ReleaseIndex::IsTrusted /*{{{*/ +// ReleaseIndex::Set* TriState options /*{{{*/ bool debReleaseIndex::SetTrusted(TriState const pTrusted) { if (Trusted == TRI_UNSET) @@ -421,6 +438,32 @@ bool debReleaseIndex::SetTrusted(TriState const pTrusted) return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); return true; } +bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil) +{ + if (d->CheckValidUntil == TRI_UNSET) + d->CheckValidUntil = pCheckValidUntil; + else if (d->CheckValidUntil != pCheckValidUntil) + return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str()); + return true; +} +bool debReleaseIndex::SetValidUntilMin(time_t const Valid) +{ + if (d->ValidUntilMin == 0) + d->ValidUntilMin = Valid; + else if (d->ValidUntilMin != Valid) + return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str()); + return true; +} +bool debReleaseIndex::SetValidUntilMax(time_t const Valid) +{ + if (d->ValidUntilMax == 0) + d->ValidUntilMax = Valid; + else if (d->ValidUntilMax != Valid) + return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str()); + return true; +} + /*}}}*/ +// ReleaseIndex::IsTrusted /*{{{*/ bool debReleaseIndex::IsTrusted() const { if (Trusted == TRI_YES) @@ -601,6 +644,22 @@ static std::vector parsePlusMinusOptions(std::string const &Name, / /*}}}*/ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ { + metaIndex::TriState GetTriStateOption(std::mapconst &Options, char const * const name) const + { + std::map::const_iterator const opt = Options.find(name); + if (opt != Options.end()) + return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO; + return metaIndex::TRI_DONTCARE; + } + + time_t GetTimeOption(std::mapconst &Options, char const * const name) const + { + std::map::const_iterator const opt = Options.find(name); + if (opt == Options.end()) + return 0; + return strtoull(opt->second.c_str(), NULL, 10); + } + protected: bool CreateItemInternal(std::vector &List, std::string const &URI, @@ -641,13 +700,10 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)) ); - std::map::const_iterator const trusted = Options.find("trusted"); - if (trusted != Options.end()) - { - if (Deb->SetTrusted(StringToBool(trusted->second, false) ? debReleaseIndex::TRI_YES : debReleaseIndex::TRI_NO) == false) - return false; - } - else if (Deb->SetTrusted(debReleaseIndex::TRI_DONTCARE) == false) + if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false || + Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false || + Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false || + Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false) return false; return true; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 19fe6806c..879eb3bfc 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -53,6 +53,9 @@ class APT_HIDDEN debReleaseIndex : public metaIndex virtual std::vector *GetIndexFiles(); bool SetTrusted(TriState const Trusted); + bool SetCheckValidUntil(TriState const Trusted); + bool SetValidUntilMin(time_t const Valid); + bool SetValidUntilMax(time_t const Valid); virtual bool IsTrusted() const; -- cgit v1.2.3 From b0d408547734100bf86781615f546487ecf390d9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 24 Jun 2015 19:31:22 +0200 Subject: implement Signed-By option for sources.list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Limits which key(s) can be used to sign a repository. Not immensely useful from a security perspective all by itself, but if the user has additional measures in place to confine a repository (like pinning) an attacker who gets the key for such a repository is limited to its potential and can't use the key to sign its attacks for an other (maybe less limited) repository… (yes, this is as weak as it sounds, but having the capability might come in handy for implementing other stuff later). --- apt-pkg/deb/debmetaindex.cc | 35 +++++++++++++++++++++++++++++++++++ apt-pkg/deb/debmetaindex.h | 1 + 2 files changed, 36 insertions(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 5d7e539c7..4bb03a942 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -461,6 +461,29 @@ bool debReleaseIndex::SetValidUntilMax(time_t const Valid) else if (d->ValidUntilMax != Valid) return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str()); return true; +} +bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy) +{ + if (SignedBy.empty() == true && pSignedBy.empty() == false) + { + if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things + ; // absolute path to a keyring file + else + { + // we could go all fancy and allow short/long/string matches as gpgv/apt-key does, + // but fingerprints are harder to fake than the others and this option is set once, + // not interactively all the time so easy to type is not really a concern. + std::string finger = pSignedBy; + finger.erase(std::remove(finger.begin(), finger.end(), ' '), finger.end()); + std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper); + if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos) + return _error->Error(_("Invalid value set for option %s concerning source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint"); + } + SignedBy = pSignedBy; + } + else if (SignedBy != pSignedBy) + return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI.c_str(), Dist.c_str()); + return true; } /*}}}*/ // ReleaseIndex::IsTrusted /*{{{*/ @@ -706,6 +729,18 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false) return false; + std::map::const_iterator const signedby = Options.find("signed-by"); + if (signedby == Options.end()) + { + if (Deb->SetSignedBy("") == false) + return false; + } + else + { + if (Deb->SetSignedBy(signedby->second) == false) + return false; + } + return true; } diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 879eb3bfc..bf5b7c1ce 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -56,6 +56,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex bool SetCheckValidUntil(TriState const Trusted); bool SetValidUntilMin(time_t const Valid); bool SetValidUntilMax(time_t const Valid); + bool SetSignedBy(std::string const &SignedBy); virtual bool IsTrusted() const; -- cgit v1.2.3 From 653ef26c70dc9c0e2cbfdd4e79117876bb63e87d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 30 Jun 2015 10:53:51 +0200 Subject: allow individual targets to be kept compressed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is an option to keep all targets (Packages, Sources, …) compressed for a while now, but the all-or-nothing approach is a bit limited for our purposes with additional targets as some of them are very big (Contents) and rarely used in comparison, so keeping them compressed by default can make sense, while others are still unpacked. Most interesting is the copy-change maybe: Copy is used by the acquire system as an uncompressor and it is hence expected that it returns the hashes for the "output", not the input. Now, in the case of keeping a file compressed, the output is never written to disk, but generated in memory and we should still validated it, so for compressed files copy is expected to return the hashes of the uncompressed file. We used to use the config option to enable on-the-fly decompress in the method, but in reality copy is never used in a way where it shouldn't decompress a compressed file to get its hashes, so we can save us the trouble of sending this information to the method and just do it always. --- apt-pkg/deb/debmetaindex.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 4bb03a942..10ab0f844 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -123,6 +123,7 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const Release = (Dist == "/") ? "" : Dist; std::string const Site = ::URI::ArchiveOnly(URI); + bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false); for (std::vector::const_iterator E = entries.begin(); E != entries.end(); ++E) { for (std::vector::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T) @@ -131,7 +132,8 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); std::string const tplShortDesc = APT_T_CONFIG("ShortDescription"); std::string const tplLongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); - bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true); + bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::Optional", true); + bool const KeepCompressed = _config->FindB(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex); #undef APT_T_CONFIG if (tplMetaKey.empty()) continue; @@ -173,6 +175,7 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, LongDesc, Options.find("BASE_URI")->second + MetaKey, IsOptional, + KeepCompressed, Options ); IndexTargets.push_back(Target); @@ -413,7 +416,7 @@ bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/ { std::vector const targets = GetIndexTargets(); -#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) +#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map()) pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), targets, this); -- cgit v1.2.3 From 3b3028467ceccca0b73a8f53051c0fa4de313111 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 9 Jul 2015 00:35:40 +0200 Subject: add c++11 override marker to overridden methods C++11 adds the 'override' specifier to mark that a method is overriding a base class method and error out if not. We hide it in the APT_OVERRIDE macro to ensure that we keep compiling in pre-c++11 standards. Reported-By: clang-modernize -add-override -override-macros Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 10 ++++---- apt-pkg/deb/debindexfile.h | 56 ++++++++++++++++++++++----------------------- apt-pkg/deb/deblistparser.h | 34 +++++++++++++-------------- apt-pkg/deb/debmetaindex.cc | 6 ++--- apt-pkg/deb/debmetaindex.h | 34 +++++++++++++-------------- apt-pkg/deb/debrecords.h | 32 +++++++++++++------------- apt-pkg/deb/debsrcrecords.h | 24 +++++++++---------- apt-pkg/deb/debsystem.h | 16 ++++++------- apt-pkg/deb/debversion.h | 4 ++-- apt-pkg/deb/dpkgpm.h | 12 +++++----- 10 files changed, 114 insertions(+), 114 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index c5086b04b..972feba7f 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -482,7 +482,7 @@ class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -497,7 +497,7 @@ class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -506,7 +506,7 @@ class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debDebFileRecordParser(File.FileName()); }; @@ -515,7 +515,7 @@ class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type { public: - virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const + virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const APT_OVERRIDE { return new debDscRecordParser(DscFile, NULL); }; @@ -524,7 +524,7 @@ class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type { public: - virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const + virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const APT_OVERRIDE { return new debDscRecordParser(SourceDir + string("/debian/control"), NULL); }; diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 1de609a7b..71ca22e4d 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -38,14 +38,14 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile virtual const Type *GetType() const APT_CONST; // Interface for acquire - virtual std::string Describe(bool /*Short*/) const {return File;}; + virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE {return File;}; // Interface for the Cache Generator - virtual bool Exists() const; - virtual bool HasPackages() const {return true;}; - virtual unsigned long Size() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; + virtual bool Exists() const APT_OVERRIDE; + virtual bool HasPackages() const APT_OVERRIDE {return true;}; + virtual unsigned long Size() const APT_OVERRIDE; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; + virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; debStatusIndex(std::string File); virtual ~debStatusIndex(); @@ -59,12 +59,12 @@ class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile virtual const Type *GetType() const APT_CONST; // Stuff for accessing files on remote items - virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const; + virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const APT_OVERRIDE; // Interface for the Cache Generator - virtual bool HasPackages() const {return true;}; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; + virtual bool HasPackages() const APT_OVERRIDE {return true;}; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; + virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; debPackagesIndex(IndexTarget const &Target, bool const Trusted); virtual ~debPackagesIndex(); @@ -78,9 +78,9 @@ class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile virtual const Type *GetType() const APT_CONST; // Interface for the Cache Generator - virtual bool HasPackages() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; + virtual bool HasPackages() const APT_OVERRIDE; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; + virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; debTranslationsIndex(IndexTarget const &Target); virtual ~debTranslationsIndex(); @@ -95,13 +95,13 @@ class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile // Stuff for accessing files on remote items virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record, - pkgSrcRecords::File const &File) const; + pkgSrcRecords::File const &File) const APT_OVERRIDE; // Interface for the record parsers - virtual pkgSrcRecords::Parser *CreateSrcParser() const; + virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE; // Interface for the Cache Generator - virtual bool HasPackages() const {return false;}; + virtual bool HasPackages() const APT_OVERRIDE {return false;}; debSourcesIndex(IndexTarget const &Target, bool const Trusted); virtual ~debSourcesIndex(); @@ -117,7 +117,7 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile public: virtual const Type *GetType() const APT_CONST; - virtual std::string Describe(bool /*Short*/) const { + virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE { return DebFile; } @@ -130,16 +130,16 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile static bool GetContent(std::ostream &content, std::string const &debfile); // Interface for the Cache Generator - virtual bool Exists() const; - virtual bool HasPackages() const { + virtual bool Exists() const APT_OVERRIDE; + virtual bool HasPackages() const APT_OVERRIDE { return true; }; - virtual unsigned long Size() const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const; + virtual unsigned long Size() const APT_OVERRIDE; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; + virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; // Interface for acquire - virtual std::string ArchiveURI(std::string /*File*/) const; + virtual std::string ArchiveURI(std::string /*File*/) const APT_OVERRIDE; debDebPkgFileIndex(std::string DebFile); virtual ~debDebPkgFileIndex(); @@ -152,11 +152,11 @@ class APT_HIDDEN debDscFileIndex : public pkgIndexFile std::string DscFile; public: virtual const Type *GetType() const APT_CONST; - virtual pkgSrcRecords::Parser *CreateSrcParser() const; - virtual bool Exists() const; - virtual bool HasPackages() const {return false;}; - virtual unsigned long Size() const; - virtual std::string Describe(bool /*Short*/) const { + virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE; + virtual bool Exists() const APT_OVERRIDE; + virtual bool HasPackages() const APT_OVERRIDE {return false;}; + virtual unsigned long Size() const APT_OVERRIDE; + virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE { return DscFile; }; diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 3fd040bdd..4bc3c2341 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -62,24 +62,24 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser APT_PUBLIC static unsigned char GetPrio(std::string Str); // These all operate against the current section - virtual std::string Package(); - virtual std::string Architecture(); - virtual bool ArchitectureAll(); - virtual std::string Version(); - virtual bool NewVersion(pkgCache::VerIterator &Ver); - virtual std::string Description(std::string const &lang); - virtual std::vector AvailableDescriptionLanguages(); - virtual MD5SumValue Description_md5(); - virtual unsigned short VersionHash(); + virtual std::string Package() APT_OVERRIDE; + virtual std::string Architecture() APT_OVERRIDE; + virtual bool ArchitectureAll() APT_OVERRIDE; + virtual std::string Version() APT_OVERRIDE; + virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE; + virtual std::string Description(std::string const &lang) APT_OVERRIDE; + virtual std::vector AvailableDescriptionLanguages() APT_OVERRIDE; + virtual MD5SumValue Description_md5() APT_OVERRIDE; + virtual unsigned short VersionHash() APT_OVERRIDE; #if APT_PKG_ABI >= 413 - virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver); + virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE; #endif virtual bool UsePackage(pkgCache::PkgIterator &Pkg, - pkgCache::VerIterator &Ver); - virtual map_filesize_t Offset() {return iOffset;}; - virtual map_filesize_t Size() {return Section.size();}; + pkgCache::VerIterator &Ver) APT_OVERRIDE; + virtual map_filesize_t Offset() APT_OVERRIDE {return iOffset;}; + virtual map_filesize_t Size() APT_OVERRIDE {return Section.size();}; - virtual bool Step(); + virtual bool Step() APT_OVERRIDE; bool LoadReleaseInfo(pkgCache::RlsFileIterator &FileI,FileFd &File, std::string const §ion); @@ -111,15 +111,15 @@ class APT_HIDDEN debDebFileParser : public debListParser public: debDebFileParser(FileFd *File, std::string const &DebFile); virtual bool UsePackage(pkgCache::PkgIterator &Pkg, - pkgCache::VerIterator &Ver); + pkgCache::VerIterator &Ver) APT_OVERRIDE; }; class APT_HIDDEN debTranslationsParser : public debListParser { public: // a translation can never be a real package - virtual std::string Architecture() { return ""; } - virtual std::string Version() { return ""; } + virtual std::string Architecture() APT_OVERRIDE { return ""; } + virtual std::string Version() APT_OVERRIDE { return ""; } debTranslationsParser(FileFd *File, std::string const &Arch = "") : debListParser(File, Arch) {}; diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 10ab0f844..46a7181fc 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -758,7 +758,7 @@ class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/ bool CreateItem(std::vector &List, std::string const &URI, std::string const &Dist, std::string const &Section, - std::map const &Options) const + std::map const &Options) const APT_OVERRIDE { return CreateItemInternal(List, URI, Dist, Section, false, Options); } @@ -774,7 +774,7 @@ class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/ bool CreateItem(std::vector &List, std::string const &URI, std::string const &Dist, std::string const &Section, - std::map const &Options) const + std::map const &Options) const APT_OVERRIDE { return CreateItemInternal(List, URI, Dist, Section, true, Options); } @@ -800,7 +800,7 @@ class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type /*{{{*/ bool CreateItem(std::vector &List, std::string const &URI, std::string const &/*Dist*/, std::string const &/*Section*/, - std::map const &/*Options*/) const + std::map const &/*Options*/) const APT_OVERRIDE { metaIndex *mi = new debDebFileMetaIndex(URI); List.push_back(mi); diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index bf5b7c1ce..8c13237cb 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -39,18 +39,18 @@ class APT_HIDDEN debReleaseIndex : public metaIndex debReleaseIndex(std::string const &URI, std::string const &Dist, bool const Trusted); virtual ~debReleaseIndex(); - virtual std::string ArchiveURI(std::string const &File) const {return URI + File;}; - virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false); - virtual std::vector GetIndexTargets() const; + virtual std::string ArchiveURI(std::string const &File) const APT_OVERRIDE {return URI + File;}; + virtual bool GetIndexes(pkgAcquire *Owner, bool const &GetAll=false) APT_OVERRIDE; + virtual std::vector GetIndexTargets() const APT_OVERRIDE; - virtual std::string Describe() const; - virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const; + virtual std::string Describe() const APT_OVERRIDE; + virtual pkgCache::RlsFileIterator FindInCache(pkgCache &Cache, bool const ModifyCheck) const APT_OVERRIDE; + virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; - virtual bool Load(std::string const &Filename, std::string * const ErrorText); - virtual metaIndex * UnloadedClone() const; + virtual bool Load(std::string const &Filename, std::string * const ErrorText) APT_OVERRIDE; + virtual metaIndex * UnloadedClone() const APT_OVERRIDE; - virtual std::vector *GetIndexFiles(); + virtual std::vector *GetIndexFiles() APT_OVERRIDE; bool SetTrusted(TriState const Trusted); bool SetCheckValidUntil(TriState const Trusted); @@ -58,7 +58,7 @@ class APT_HIDDEN debReleaseIndex : public metaIndex bool SetValidUntilMax(time_t const Valid); bool SetSignedBy(std::string const &SignedBy); - virtual bool IsTrusted() const; + virtual bool IsTrusted() const APT_OVERRIDE; void AddComponent(bool const isSrc, std::string const &Name, std::vector const &Targets, @@ -73,29 +73,29 @@ private: std::string DebFile; debDebPkgFileIndex *DebIndex; public: - virtual std::string ArchiveURI(std::string const& /*File*/) const { + virtual std::string ArchiveURI(std::string const& /*File*/) const APT_OVERRIDE { return DebFile; } - virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) { + virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) APT_OVERRIDE { return true; } - virtual std::vector GetIndexTargets() const { + virtual std::vector GetIndexTargets() const APT_OVERRIDE { return std::vector(); } - virtual std::vector *GetIndexFiles() { + virtual std::vector *GetIndexFiles() APT_OVERRIDE { return Indexes; } - virtual bool IsTrusted() const { + virtual bool IsTrusted() const APT_OVERRIDE { return true; } - virtual bool Load(std::string const &, std::string * const ErrorText) + virtual bool Load(std::string const &, std::string * const ErrorText) APT_OVERRIDE { LoadedSuccessfully = TRI_NO; if (ErrorText != NULL) strprintf(*ErrorText, "Unparseable metaindex as it represents the standalone deb file %s", DebFile.c_str()); return false; } - virtual metaIndex * UnloadedClone() const + virtual metaIndex * UnloadedClone() const APT_OVERRIDE { return NULL; } diff --git a/apt-pkg/deb/debrecords.h b/apt-pkg/deb/debrecords.h index 4d0b713d4..7fc82a88d 100644 --- a/apt-pkg/deb/debrecords.h +++ b/apt-pkg/deb/debrecords.h @@ -33,23 +33,23 @@ class APT_HIDDEN debRecordParserBase : public pkgRecords::Parser public: // These refer to the archive file for the Version - virtual std::string FileName(); - virtual std::string SourcePkg(); - virtual std::string SourceVer(); + virtual std::string FileName() APT_OVERRIDE; + virtual std::string SourcePkg() APT_OVERRIDE; + virtual std::string SourceVer() APT_OVERRIDE; - virtual HashStringList Hashes() const; + virtual HashStringList Hashes() const APT_OVERRIDE; // These are some general stats about the package - virtual std::string Maintainer(); - virtual std::string ShortDesc(std::string const &lang); - virtual std::string LongDesc(std::string const &lang); - virtual std::string Name(); - virtual std::string Homepage(); + virtual std::string Maintainer() APT_OVERRIDE; + virtual std::string ShortDesc(std::string const &lang) APT_OVERRIDE; + virtual std::string LongDesc(std::string const &lang) APT_OVERRIDE; + virtual std::string Name() APT_OVERRIDE; + virtual std::string Homepage() APT_OVERRIDE; // An arbitrary custom field - virtual std::string RecordField(const char *fieldName); + virtual std::string RecordField(const char *fieldName) APT_OVERRIDE; - virtual void GetRec(const char *&Start,const char *&Stop); + virtual void GetRec(const char *&Start,const char *&Stop) APT_OVERRIDE; debRecordParserBase(); virtual ~debRecordParserBase(); @@ -62,8 +62,8 @@ class APT_HIDDEN debRecordParser : public debRecordParserBase FileFd File; pkgTagFile Tags; - virtual bool Jump(pkgCache::VerFileIterator const &Ver); - virtual bool Jump(pkgCache::DescFileIterator const &Desc); + virtual bool Jump(pkgCache::VerFileIterator const &Ver) APT_OVERRIDE; + virtual bool Jump(pkgCache::DescFileIterator const &Desc) APT_OVERRIDE; public: debRecordParser(std::string FileName,pkgCache &Cache); @@ -80,11 +80,11 @@ class APT_HIDDEN debDebFileRecordParser : public debRecordParserBase APT_HIDDEN bool LoadContent(); protected: // single file files, so no jumping whatsoever - bool Jump(pkgCache::VerFileIterator const &); - bool Jump(pkgCache::DescFileIterator const &); + bool Jump(pkgCache::VerFileIterator const &) APT_OVERRIDE; + bool Jump(pkgCache::DescFileIterator const &) APT_OVERRIDE; public: - virtual std::string FileName(); + virtual std::string FileName() APT_OVERRIDE; debDebFileRecordParser(std::string FileName); virtual ~debDebFileRecordParser(); diff --git a/apt-pkg/deb/debsrcrecords.h b/apt-pkg/deb/debsrcrecords.h index 64b07a1ec..89134af5f 100644 --- a/apt-pkg/deb/debsrcrecords.h +++ b/apt-pkg/deb/debsrcrecords.h @@ -36,24 +36,24 @@ class APT_HIDDEN debSrcRecordParser : public pkgSrcRecords::Parser public: - virtual bool Restart() {return Jump(0);}; - virtual bool Step() {iOffset = Tags.Offset(); return Tags.Step(Sect);}; - virtual bool Jump(unsigned long const &Off) {iOffset = Off; return Tags.Jump(Sect,Off);}; + virtual bool Restart() APT_OVERRIDE {return Jump(0);}; + virtual bool Step() APT_OVERRIDE {iOffset = Tags.Offset(); return Tags.Step(Sect);}; + virtual bool Jump(unsigned long const &Off) APT_OVERRIDE {iOffset = Off; return Tags.Jump(Sect,Off);}; - virtual std::string Package() const {return Sect.FindS("Package");}; - virtual std::string Version() const {return Sect.FindS("Version");}; - virtual std::string Maintainer() const {return Sect.FindS("Maintainer");}; - virtual std::string Section() const {return Sect.FindS("Section");}; - virtual const char **Binaries(); - virtual bool BuildDepends(std::vector &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true); - virtual unsigned long Offset() {return iOffset;}; - virtual std::string AsStr() + virtual std::string Package() const APT_OVERRIDE {return Sect.FindS("Package");}; + virtual std::string Version() const APT_OVERRIDE {return Sect.FindS("Version");}; + virtual std::string Maintainer() const APT_OVERRIDE {return Sect.FindS("Maintainer");}; + virtual std::string Section() const APT_OVERRIDE {return Sect.FindS("Section");}; + virtual const char **Binaries() APT_OVERRIDE; + virtual bool BuildDepends(std::vector &BuildDeps, bool const &ArchOnly, bool const &StripMultiArch = true) APT_OVERRIDE; + virtual unsigned long Offset() APT_OVERRIDE {return iOffset;}; + virtual std::string AsStr() APT_OVERRIDE { const char *Start=0,*Stop=0; Sect.GetSection(Start,Stop); return std::string(Start,Stop); }; - virtual bool Files(std::vector &F); + virtual bool Files(std::vector &F) APT_OVERRIDE; bool Files2(std::vector &F); debSrcRecordParser(std::string const &File,pkgIndexFile const *Index); diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h index e59bbebed..aed77520e 100644 --- a/apt-pkg/deb/debsystem.h +++ b/apt-pkg/deb/debsystem.h @@ -33,15 +33,15 @@ class debSystem : public pkgSystem public: - virtual bool Lock(); - virtual bool UnLock(bool NoErrors = false); - virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const; - virtual bool Initialize(Configuration &Cnf); - virtual bool ArchiveSupported(const char *Type); - virtual signed Score(Configuration const &Cnf); - virtual bool AddStatusFiles(std::vector &List); + virtual bool Lock() APT_OVERRIDE; + virtual bool UnLock(bool NoErrors = false) APT_OVERRIDE; + virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const APT_OVERRIDE; + virtual bool Initialize(Configuration &Cnf) APT_OVERRIDE; + virtual bool ArchiveSupported(const char *Type) APT_OVERRIDE; + virtual signed Score(Configuration const &Cnf) APT_OVERRIDE; + virtual bool AddStatusFiles(std::vector &List) APT_OVERRIDE; virtual bool FindIndex(pkgCache::PkgFileIterator File, - pkgIndexFile *&Found) const; + pkgIndexFile *&Found) const APT_OVERRIDE; debSystem(); virtual ~debSystem(); diff --git a/apt-pkg/deb/debversion.h b/apt-pkg/deb/debversion.h index 7befe6372..6d7eca7c1 100644 --- a/apt-pkg/deb/debversion.h +++ b/apt-pkg/deb/debversion.h @@ -27,11 +27,11 @@ class debVersioningSystem : public pkgVersioningSystem const char *B,const char *Bend) APT_PURE; virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer) APT_PURE; virtual APT_PURE int DoCmpReleaseVer(const char *A,const char *Aend, - const char *B,const char *Bend) + const char *B,const char *Bend) APT_OVERRIDE { return DoCmpVersion(A,Aend,B,Bend); } - virtual std::string UpstreamVersion(const char *A); + virtual std::string UpstreamVersion(const char *A) APT_OVERRIDE; debVersioningSystem(); }; diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index a1b36c6c0..82c1bef5d 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -120,14 +120,14 @@ class pkgDPkgPM : public pkgPackageManager void ProcessDpkgStatusLine(char *line); // The Actuall installation implementation - virtual bool Install(PkgIterator Pkg,std::string File); - virtual bool Configure(PkgIterator Pkg); - virtual bool Remove(PkgIterator Pkg,bool Purge = false); + virtual bool Install(PkgIterator Pkg,std::string File) APT_OVERRIDE; + virtual bool Configure(PkgIterator Pkg) APT_OVERRIDE; + virtual bool Remove(PkgIterator Pkg,bool Purge = false) APT_OVERRIDE; - virtual bool Go(APT::Progress::PackageManager *progress); - virtual bool Go(int StatusFd=-1); + virtual bool Go(APT::Progress::PackageManager *progress) APT_OVERRIDE; + virtual bool Go(int StatusFd=-1) APT_OVERRIDE; - virtual void Reset(); + virtual void Reset() APT_OVERRIDE; public: -- cgit v1.2.3 From c2a4a8dded2dfb56dbcab9689b6cb4b96c9999b6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 10 Jul 2015 00:07:37 +0200 Subject: rename 'apt-get files' to 'apt-get indextargets' 'files' is a bit too generic as a name for a command usually only used programmatically (if at all) by developers, so instead of "wasting" this generic name for this we use "indextargets" which is actually the name of the datastructure the displayed data is stored in. Along with this rename the config options are renamed accordingly. --- apt-pkg/deb/debmetaindex.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 46a7181fc..480317db3 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -128,12 +128,12 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, { for (std::vector::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T) { -#define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::" + (X)) +#define APT_T_CONFIG(X) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X)) std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); std::string const tplShortDesc = APT_T_CONFIG("ShortDescription"); - std::string const tplLongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); - bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::Optional", true); - bool const KeepCompressed = _config->FindB(std::string("APT::Acquire::Targets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex); + std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); + bool const IsOptional = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::Optional", true); + bool const KeepCompressed = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex); #undef APT_T_CONFIG if (tplMetaKey.empty()) continue; @@ -721,7 +721,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ Deb->AddComponent( IsSrc, Section, - parsePlusMinusOptions("target", Options, _config->FindVector(std::string("APT::Acquire::Targets::") + Name, "", true)), + parsePlusMinusOptions("target", Options, _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true)), parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()), parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)) ); -- cgit v1.2.3 From fd23676e809b7fa87ae138cc22d2c683d212950e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 13 Jul 2015 12:47:05 +0200 Subject: bunch of micro-optimizations for depcache DepCache functions are called a lot, so if we can squeeze some drops out of them for free we should do so. Takes also the opportunity to remove some whitespace errors from these functions. Git-Dch: Ignore --- apt-pkg/deb/deblistparser.cc | 11 +++++------ apt-pkg/deb/debversion.cc | 47 +++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 31 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 4e49e1c78..7c21bd8b3 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -209,23 +209,22 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) Ver->Priority = pkgCache::State::Extra; } - if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false) - return false; if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false) return false; - if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false) - return false; - if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false) + if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false) return false; if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false) return false; if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false) return false; + if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false) + return false; + if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false) + return false; if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false) return false; if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false) return false; - // Obsolete. if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false) return false; diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index a5eacb7f5..043025912 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -34,29 +34,26 @@ debVersioningSystem::debVersioningSystem() // debVS::CmpFragment - Compare versions /*{{{*/ // --------------------------------------------------------------------- -/* This compares a fragment of the version. This is a slightly adapted - version of what dpkg uses. */ -#define order(x) ((x) == '~' ? -1 \ - : isdigit((x)) ? 0 \ - : !(x) ? 0 \ - : isalpha((x)) ? (x) \ - : (x) + 256) -int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, - const char *B,const char *BEnd) +/* This compares a fragment of the version. This is a slightly adapted + version of what dpkg uses in dpkg/lib/dpkg/version.c. + In particular, the a | b = NULL check is removed as we check this in the + caller, we use an explicit end for a | b strings and we check ~ explicit. */ +static int order(char c) { - if (A >= AEnd && B >= BEnd) + if (isdigit(c)) return 0; - if (A >= AEnd) - { - if (*B == '~') return 1; + else if (isalpha(c)) + return c; + else if (c == '~') return -1; - } - if (B >= BEnd) - { - if (*A == '~') return -1; - return 1; - } - + else if (c) + return c + 256; + else + return 0; +} +int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, + const char *B,const char *BEnd) +{ /* Iterate over the whole string What this does is to split the whole string into groups of numeric and non numeric portions. For instance: @@ -77,19 +74,19 @@ int debVersioningSystem::CmpFragment(const char *A,const char *AEnd, int rc = order(*rhs); if (vc != rc) return vc - rc; - lhs++; rhs++; + ++lhs; ++rhs; } while (*lhs == '0') - lhs++; + ++lhs; while (*rhs == '0') - rhs++; + ++rhs; while (isdigit(*lhs) && isdigit(*rhs)) { if (!first_diff) first_diff = *lhs - *rhs; - lhs++; - rhs++; + ++lhs; + ++rhs; } if (isdigit(*lhs)) -- cgit v1.2.3 From 4dc77823d360158d6870a5710cc8c17064f1308f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 15 Jul 2015 13:21:21 +0200 Subject: remove the compatibility markers for 4.13 abi We aren't and we will not be really compatible again with the previous stable abi, so lets drop these markers (which never made it into a released version) for good as they have outlived their intend already. Git-Dch: Ignore --- apt-pkg/deb/deblistparser.cc | 5 ----- apt-pkg/deb/deblistparser.h | 2 -- apt-pkg/deb/dpkgpm.cc | 9 --------- 3 files changed, 16 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 7c21bd8b3..e57a3524f 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -141,7 +141,6 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) map_stringitem_t const idx = StoreString(pkgCacheGenerator::SECTION, Start, Stop - Start); Ver->Section = idx; } -#if APT_PKG_ABI >= 413 // Parse the source package name pkgCache::GrpIterator const G = Ver.ParentPkg().Group(); Ver->SourcePkgName = G->Name; @@ -193,7 +192,6 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) } } } -#endif Ver->MultiArch = ParseMultiArch(true); // Archive Size @@ -962,7 +960,6 @@ unsigned char debListParser::GetPrio(string Str) return Out; } /*}}}*/ -#if APT_PKG_ABI >= 413 bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/ pkgCache::VerIterator const &Ver) { @@ -982,8 +979,6 @@ bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/ return true; } /*}}}*/ -#endif - debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile) : debListParser(File, ""), DebFile(DebFile) diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 4bc3c2341..3884aafb9 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -71,9 +71,7 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser virtual std::vector AvailableDescriptionLanguages() APT_OVERRIDE; virtual MD5SumValue Description_md5() APT_OVERRIDE; virtual unsigned short VersionHash() APT_OVERRIDE; -#if APT_PKG_ABI >= 413 virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE; -#endif virtual bool UsePackage(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver) APT_OVERRIDE; virtual map_filesize_t Offset() APT_OVERRIDE {return iOffset;}; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 3594a6efe..c578cc338 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1846,16 +1846,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg) time_t now = time(NULL); fprintf(report, "Date: %s" , ctime(&now)); fprintf(report, "Package: %s %s\n", pkgname.c_str(), pkgver.c_str()); -#if APT_PKG_ABI >= 413 fprintf(report, "SourcePackage: %s\n", Ver.SourcePkgName()); -#else - pkgRecords Recs(Cache); - pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList()); - std::string srcpkgname = Parse.SourcePkg(); - if(srcpkgname.empty()) - srcpkgname = pkgname; - fprintf(report, "SourcePackage: %s\n", srcpkgname.c_str()); -#endif fprintf(report, "ErrorMessage:\n %s\n", errormsg); // ensure that the log is flushed -- cgit v1.2.3 From 8c7af4d4c95d0423fbd0f3baa979792504f4f45f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 16 Jul 2015 11:15:25 +0200 Subject: hide implicit deps in apt-cache again by default Before MultiArch implicits weren't a thing, so they were hidden by default by definition. Adding them for MultiArch solved many problems, but having no reliable way of detecting which dependency (and provides) is implicit or not causes problems everytime we want to output dependencies without confusing our observers with unneeded implementation details. The really notworthy point here is actually that we keep now a better record of how a dependency came to be so that we can later reason about it more easily, but that is hidden so deep down in the library internals that change is more the problems it solves than the change itself. --- apt-pkg/deb/deblistparser.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index e57a3524f..df0879641 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -812,7 +812,7 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, // … but this is probably the best thing to do. if (Arch == "native") Arch = _config->Find("APT::Architecture"); - if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false) + if (NewDepends(Ver,Package,Arch,Version,Op | pkgCache::Dep::ArchSpecific,Type) == false) return false; } else @@ -858,13 +858,13 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) } else if (archfound != string::npos) { string OtherArch = Package.substr(archfound+1, string::npos); Package = Package.substr(0, archfound); - if (NewProvides(Ver, Package, OtherArch, Version) == false) + if (NewProvides(Ver, Package, OtherArch, Version, pkgCache::Flag::ArchSpecific) == false) return false; } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) { if (NewProvidesAllArch(Ver, Package, Version) == false) return false; } else { - if (NewProvides(Ver, Package, Arch, Version) == false) + if (NewProvides(Ver, Package, Arch, Version, 0) == false) return false; } @@ -890,7 +890,7 @@ bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const for (std::vector::const_iterator a = Architectures.begin(); a != Architectures.end(); ++a) { - if (NewProvides(Ver, Package, *a, Version) == false) + if (NewProvides(Ver, Package, *a, Version, pkgCache::Flag::MultiArchImplicit) == false) return false; } return true; -- cgit v1.2.3 From ecc138f858fab61e0b888d3d13854d1422c3432b Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 16 Jul 2015 19:41:45 +0200 Subject: just-in-time creation for (implicit) Provides Expecting the worst is easy to code, but has its disadvantages e.g. by creating package structures which otherwise would have never existed. By creating the provides instead at the time a package structure is added we are well prepared for the introduction of partial architectures, massive amounts of M-A:foreign (and :allowed) and co as far as provides are concerned at least. We have something relatively similar for dependencies already. Many tests are added for both M-A states and the code cleaned to properly support implicit provides for foreign architectures and architectures we 'just' happen to parse. Git-Dch: Ignore --- apt-pkg/deb/deblistparser.cc | 20 ++++---------------- apt-pkg/deb/deblistparser.h | 1 - 2 files changed, 4 insertions(+), 17 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index df0879641..87aa99c6e 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -861,7 +861,7 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) if (NewProvides(Ver, Package, OtherArch, Version, pkgCache::Flag::ArchSpecific) == false) return false; } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) { - if (NewProvidesAllArch(Ver, Package, Version) == false) + if (NewProvidesAllArch(Ver, Package, Version, 0) == false) return false; } else { if (NewProvides(Ver, Package, Arch, Version, 0) == false) @@ -876,26 +876,14 @@ bool debListParser::ParseProvides(pkgCache::VerIterator &Ver) if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed) { string const Package = string(Ver.ParentPkg().Name()).append(":").append("any"); - return NewProvidesAllArch(Ver, Package, Ver.VerStr()); + return NewProvidesAllArch(Ver, Package, Ver.VerStr(), pkgCache::Flag::MultiArchImplicit); } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) - return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr()); + return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr(), pkgCache::Flag::MultiArchImplicit); return true; } /*}}}*/ -// ListParser::NewProvides - add provides for all architectures /*{{{*/ -bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package, - string const &Version) { - for (std::vector::const_iterator a = Architectures.begin(); - a != Architectures.end(); ++a) - { - if (NewProvides(Ver, Package, *a, Version, pkgCache::Flag::MultiArchImplicit) == false) - return false; - } - return true; -} - /*}}}*/ // ListParser::GrabWord - Matches a word and returns /*{{{*/ // --------------------------------------------------------------------- /* Looks for a word in a list of words - for ParseStatus */ @@ -991,7 +979,7 @@ bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg, bool res = debListParser::UsePackage(Pkg, Ver); // we use the full file path as a provides so that the file is found // by its name - if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr()) == false) + if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr(), 0) == false) return false; return res; } diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 3884aafb9..30e52718d 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -53,7 +53,6 @@ class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag, unsigned int Type); bool ParseProvides(pkgCache::VerIterator &Ver); - bool NewProvidesAllArch(pkgCache::VerIterator &Ver, std::string const &Package, std::string const &Version); static bool GrabWord(std::string Word,WordList *List,unsigned char &Out); APT_HIDDEN unsigned char ParseMultiArch(bool const showErrors); -- cgit v1.2.3 From bb0f6a34c4cebea7884de828c011dc85765ff820 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 17 Jul 2015 10:53:01 +0200 Subject: just-in-time creation for (explicit) negative deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we deal with provides in a more dynamic fashion the last remaining problem is explicit dependencies like 'Conflicts: foo' which have to apply to all architectures, but creating them all at the same time requires us to know all architectures ending up in the cache which isn't needed to be the same set as all foreign architectures. The effect is visible already now through as this prevents the creation of a bunch of virtual packages for arch:all packages and as such also many dependencies, just not very visible if you don't look at the stats… Git-Dch Ignore --- apt-pkg/deb/deblistparser.cc | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 87aa99c6e..1154016a9 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -790,43 +790,23 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, return _error->Error("Problem parsing dependency %s",Tag); size_t const found = Package.rfind(':'); - // If negative is unspecific it needs to apply on all architectures - if (MultiArchEnabled == true && found == string::npos && - (Type == pkgCache::Dep::Conflicts || - Type == pkgCache::Dep::DpkgBreaks || - Type == pkgCache::Dep::Replaces)) + if (found == string::npos || strcmp(Package.c_str() + found, ":any") == 0) { - for (std::vector::const_iterator a = Architectures.begin(); - a != Architectures.end(); ++a) - if (NewDepends(Ver,Package,*a,Version,Op,Type) == false) - return false; - if (NewDepends(Ver,Package,"none",Version,Op,Type) == false) + if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false) return false; } - else if (found != string::npos && - strcmp(Package.c_str() + found, ":any") != 0) + else { string Arch = Package.substr(found+1, string::npos); Package = Package.substr(0, found); // Such dependencies are not supposed to be accepted … - // … but this is probably the best thing to do. + // … but this is probably the best thing to do anyway if (Arch == "native") Arch = _config->Find("APT::Architecture"); if (NewDepends(Ver,Package,Arch,Version,Op | pkgCache::Dep::ArchSpecific,Type) == false) return false; } - else - { - if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false) - return false; - if ((Type == pkgCache::Dep::Conflicts || - Type == pkgCache::Dep::DpkgBreaks || - Type == pkgCache::Dep::Replaces) && - NewDepends(Ver, Package, - (pkgArch != "none") ? "none" : _config->Find("APT::Architecture"), - Version,Op,Type) == false) - return false; - } + if (Start == Stop) break; } -- cgit v1.2.3 From 5465192b9aeb1ccea778950ccf2d1b7b32f2cd91 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 18 Jul 2015 18:03:54 +0200 Subject: add volatile sources support in libapt-pkg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sources are usually defined in sources.list (and co) and are pretty stable, but once in a while a frontend might want to add an additional "source" like a local .deb file to install this package (No support for 'real' sources being added this way as this is a multistep process). We had a hack in place to allow apt-get and apt to pull this of for a short while now, but other frontends are either left in the cold by this and/or the code for it looks dirty with FIXMEs plastering it and has on top of this also some problems (like including these 'volatile' sources in the srcpkgcache.bin file). So the biggest part in this commit is actually the rewrite of the cache generation as it is now potentially a three step process. The biggest problem with adding support now through is that this makes a bunch of previously mostly unusable by externs and therefore hidden classes public, so a bit of further tuneing on this now public API is in order… --- apt-pkg/deb/debindexfile.cc | 27 +++++++++++---------------- apt-pkg/deb/debindexfile.h | 18 +++++++++--------- apt-pkg/deb/deblistparser.cc | 2 +- apt-pkg/deb/debmetaindex.cc | 29 ----------------------------- apt-pkg/deb/debmetaindex.h | 39 --------------------------------------- 5 files changed, 21 insertions(+), 94 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 972feba7f..e67233e5f 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -339,18 +339,16 @@ APT_CONST bool debStatusIndex::Exists() const } /*}}}*/ -// debDebPkgFile - Single .deb file /*{{{*/ -debDebPkgFileIndex::debDebPkgFileIndex(std::string DebFile) +// debDebPkgFileIndex - Single .deb file /*{{{*/ +debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile) : pkgIndexFile(true), d(NULL), DebFile(DebFile) { DebFileFullPath = flAbsPath(DebFile); } - std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const { return "file:" + DebFileFullPath; } - bool debDebPkgFileIndex::Exists() const { return FileExists(DebFile); @@ -403,6 +401,8 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const if (GetContent(content, DebFile) == false) return false; std::string const contentstr = content.str(); + if (contentstr.empty()) + return true; DebControl->Write(contentstr.c_str(), contentstr.length()); // rewind for the listparser DebControl->Seek(0); @@ -431,7 +431,7 @@ pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const return File; } - + return File; } unsigned long debDebPkgFileIndex::Size() const @@ -443,12 +443,11 @@ unsigned long debDebPkgFileIndex::Size() const } /*}}}*/ -// debDscFileIndex stuff -debDscFileIndex::debDscFileIndex(std::string &DscFile) +// debDscFileIndex - a .dsc file /*{{{*/ +debDscFileIndex::debDscFileIndex(std::string const &DscFile) : pkgIndexFile(true), d(NULL), DscFile(DscFile) { } - bool debDscFileIndex::Exists() const { return FileExists(DscFile); @@ -461,8 +460,6 @@ unsigned long debDscFileIndex::Size() const return buf.st_size; return 0; } - -// DscFileIndex::CreateSrcParser - Get a parser for the .dsc file /*{{{*/ pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const { if (!FileExists(DscFile)) @@ -471,18 +468,17 @@ pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const return new debDscRecordParser(DscFile,this); } /*}}}*/ + // Index File types for Debian /*{{{*/ class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type { public: - debIFTypeSrc() {Label = "Debian Source Index";}; }; class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type { public: - - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -496,8 +492,7 @@ class APT_HIDDEN debIFTypeTrans : public debIFTypePkg class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type { public: - - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -506,7 +501,7 @@ class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE { return new debDebFileRecordParser(File.FileName()); }; diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 71ca22e4d..4a818121a 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -27,7 +27,7 @@ class pkgAcquire; class pkgCacheGenerator; -class APT_HIDDEN debStatusIndex : public pkgIndexFile +class debStatusIndex : public pkgIndexFile { void * const d; protected: @@ -51,7 +51,7 @@ class APT_HIDDEN debStatusIndex : public pkgIndexFile virtual ~debStatusIndex(); }; -class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile +class debPackagesIndex : public pkgIndexTargetFile { void * const d; public: @@ -70,7 +70,7 @@ class APT_HIDDEN debPackagesIndex : public pkgIndexTargetFile virtual ~debPackagesIndex(); }; -class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile +class debTranslationsIndex : public pkgIndexTargetFile { void * const d; public: @@ -86,7 +86,7 @@ class APT_HIDDEN debTranslationsIndex : public pkgIndexTargetFile virtual ~debTranslationsIndex(); }; -class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile +class debSourcesIndex : public pkgIndexTargetFile { void * const d; public: @@ -107,7 +107,7 @@ class APT_HIDDEN debSourcesIndex : public pkgIndexTargetFile virtual ~debSourcesIndex(); }; -class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile +class debDebPkgFileIndex : public pkgIndexFile { private: void * const d; @@ -141,11 +141,11 @@ class APT_HIDDEN debDebPkgFileIndex : public pkgIndexFile // Interface for acquire virtual std::string ArchiveURI(std::string /*File*/) const APT_OVERRIDE; - debDebPkgFileIndex(std::string DebFile); + debDebPkgFileIndex(std::string const &DebFile); virtual ~debDebPkgFileIndex(); }; -class APT_HIDDEN debDscFileIndex : public pkgIndexFile +class debDscFileIndex : public pkgIndexFile { private: void * const d; @@ -160,11 +160,11 @@ class APT_HIDDEN debDscFileIndex : public pkgIndexFile return DscFile; }; - debDscFileIndex(std::string &DscFile); + debDscFileIndex(std::string const &DscFile); virtual ~debDscFileIndex(); }; -class APT_HIDDEN debDebianSourceDirIndex : public debDscFileIndex +class debDebianSourceDirIndex : public debDscFileIndex { public: virtual const Type *GetType() const APT_CONST; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 1154016a9..b7988d499 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -959,7 +959,7 @@ bool debDebFileParser::UsePackage(pkgCache::PkgIterator &Pkg, bool res = debListParser::UsePackage(Pkg, Ver); // we use the full file path as a provides so that the file is found // by its name - if(NewProvidesAllArch(Ver, DebFile, Ver.VerStr(), 0) == false) + if(NewProvides(Ver, DebFile, Pkg.Cache()->NativeArch(), Ver.VerStr(), 0) == false) return false; return res; } diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 480317db3..123c91648 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -785,34 +785,5 @@ class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/ }; /*}}}*/ -debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile) /*{{{*/ - : metaIndex(DebFile, "local-uri", "deb-dist"), d(NULL), DebFile(DebFile) -{ - DebIndex = new debDebPkgFileIndex(DebFile); - Indexes = new std::vector(); - Indexes->push_back(DebIndex); -} -debDebFileMetaIndex::~debDebFileMetaIndex() {} - /*}}}*/ -class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type /*{{{*/ -{ - public: - - bool CreateItem(std::vector &List, std::string const &URI, - std::string const &/*Dist*/, std::string const &/*Section*/, - std::map const &/*Options*/) const APT_OVERRIDE - { - metaIndex *mi = new debDebFileMetaIndex(URI); - List.push_back(mi); - return true; - } - - debSLTypeDebFile() : Type("deb-file", "Debian local deb file") - { - } -}; - /*}}}*/ - APT_HIDDEN debSLTypeDeb _apt_DebType; APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType; -APT_HIDDEN debSLTypeDebFile _apt_DebFileType; diff --git a/apt-pkg/deb/debmetaindex.h b/apt-pkg/deb/debmetaindex.h index 8c13237cb..e93959a21 100644 --- a/apt-pkg/deb/debmetaindex.h +++ b/apt-pkg/deb/debmetaindex.h @@ -17,7 +17,6 @@ class pkgAcquire; class pkgIndexFile; -class debDebPkgFileIndex; class IndexTarget; class pkgCacheGenerator; class OpProgress; @@ -66,42 +65,4 @@ class APT_HIDDEN debReleaseIndex : public metaIndex std::vector Languages); }; -class APT_HIDDEN debDebFileMetaIndex : public metaIndex -{ -private: - void * const d; - std::string DebFile; - debDebPkgFileIndex *DebIndex; -public: - virtual std::string ArchiveURI(std::string const& /*File*/) const APT_OVERRIDE { - return DebFile; - } - virtual bool GetIndexes(pkgAcquire* /*Owner*/, const bool& /*GetAll=false*/) APT_OVERRIDE { - return true; - } - virtual std::vector GetIndexTargets() const APT_OVERRIDE { - return std::vector(); - } - virtual std::vector *GetIndexFiles() APT_OVERRIDE { - return Indexes; - } - virtual bool IsTrusted() const APT_OVERRIDE { - return true; - } - virtual bool Load(std::string const &, std::string * const ErrorText) APT_OVERRIDE - { - LoadedSuccessfully = TRI_NO; - if (ErrorText != NULL) - strprintf(*ErrorText, "Unparseable metaindex as it represents the standalone deb file %s", DebFile.c_str()); - return false; - } - virtual metaIndex * UnloadedClone() const APT_OVERRIDE - { - return NULL; - } - debDebFileMetaIndex(std::string const &DebFile); - virtual ~debDebFileMetaIndex(); - -}; - #endif -- cgit v1.2.3 From c9443c01208377f0cba9706412ea3a98ad97b56d Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 20 Jul 2015 10:17:29 +0200 Subject: elimate duplicated code in pkgIndexFile subclasses Trade deduplication of code for a bunch of new virtuals, so it is actually visible how the different indexes behave cleaning up the interface at large in the process. Git-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 416 +++++++++++-------------------------------- apt-pkg/deb/debindexfile.h | 84 ++++----- apt-pkg/deb/deblistparser.cc | 7 +- apt-pkg/deb/deblistparser.h | 2 +- 4 files changed, 147 insertions(+), 362 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index e67233e5f..627cd36c5 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -36,27 +36,20 @@ #include #include #include +#include #include /*}}}*/ -using std::string; - -// SourcesIndex::debSourcesIndex - Constructor /*{{{*/ -// --------------------------------------------------------------------- -/* */ +// Sources Index /*{{{*/ debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) : - pkgIndexTargetFile(Target, Trusted), d(NULL) + pkgDebianIndexTargetFile(Target, Trusted), d(NULL) { } - /*}}}*/ -// SourcesIndex::SourceInfo - Short 1 liner describing a source /*{{{*/ -// --------------------------------------------------------------------- -/* The result looks like: - http://foo/debian/ stable/main src 1.1.1 (dsc) */ -string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, +std::string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, pkgSrcRecords::File const &File) const { - string Res = Target.Description; + // The result looks like: http://foo/debian/ stable/main src 1.1.1 (dsc) + std::string Res = Target.Description; Res.erase(Target.Description.rfind(' ')); Res += " "; @@ -67,294 +60,111 @@ string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record, Res += " (" + File.Type + ")"; return Res; } - /*}}}*/ -// SourcesIndex::CreateSrcParser - Get a parser for the source files /*{{{*/ -// --------------------------------------------------------------------- -/* */ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const { - string const SourcesURI = IndexFileName(); + std::string const SourcesURI = IndexFileName(); if (FileExists(SourcesURI)) return new debSrcRecordParser(SourcesURI, this); return NULL; +} +bool debSourcesIndex::OpenListFile(FileFd &, std::string const &) +{ + return true; +} +pkgCacheListParser * debSourcesIndex::CreateListParser(FileFd &) +{ + return NULL; +} +uint8_t debSourcesIndex::GetIndexFlags() const +{ + return 0; } /*}}}*/ - -// PackagesIndex::debPackagesIndex - Contructor /*{{{*/ -// --------------------------------------------------------------------- -/* */ +// Packages Index /*{{{*/ debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) : - pkgIndexTargetFile(Target, Trusted), d(NULL) + pkgDebianIndexTargetFile(Target, Trusted), d(NULL) { } - /*}}}*/ -// PackagesIndex::ArchiveInfo - Short version of the archive url /*{{{*/ -// --------------------------------------------------------------------- -/* This is a shorter version that is designed to be < 60 chars or so */ -string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator Ver) const +std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const { - std::string const Dist = Target.Option(IndexTarget::RELEASE); - string Res = Target.Option(IndexTarget::SITE) + " " + Dist; - std::string const Component = Target.Option(IndexTarget::COMPONENT); - if (Component.empty() == false) - Res += "/" + Component; + std::string Res = Target.Description; + Res.erase(Target.Description.rfind(' ')); Res += " "; Res += Ver.ParentPkg().Name(); Res += " "; + std::string const Dist = Target.Option(IndexTarget::RELEASE); if (Dist.empty() == false && Dist[Dist.size() - 1] != '/') Res.append(Ver.Arch()).append(" "); Res += Ver.VerStr(); return Res; } - /*}}}*/ -// PackagesIndex::Merge - Load the index file into a cache /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debPackagesIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const -{ - string const PackageFile = IndexFileName(); - FileFd Pkg(PackageFile,FileFd::ReadOnly, FileFd::Extension); - debListParser Parser(&Pkg, Target.Option(IndexTarget::ARCHITECTURE)); - - if (_error->PendingError() == true) - return _error->Error("Problem opening %s",PackageFile.c_str()); - if (Prog != NULL) - Prog->SubProgress(0, Target.Description); - - - std::string const URI = Target.Option(IndexTarget::REPO_URI); - std::string Dist = Target.Option(IndexTarget::RELEASE); - if (Dist.empty()) - Dist = "/"; - ::URI Tmp(URI); - if (Gen.SelectFile(PackageFile, *this, Target.Option(IndexTarget::ARCHITECTURE), Target.Option(IndexTarget::COMPONENT)) == false) - return _error->Error("Problem with SelectFile %s",PackageFile.c_str()); - - // Store the IMS information - pkgCache::PkgFileIterator File = Gen.GetCurFile(); - pkgCacheGenerator::Dynamic DynFile(File); - File->Size = Pkg.FileSize(); - File->mtime = Pkg.ModificationTime(); - - if (Gen.MergeList(Parser) == false) - return _error->Error("Problem with MergeList %s",PackageFile.c_str()); - - return true; -} - /*}}}*/ -// PackagesIndex::FindInCache - Find this index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -pkgCache::PkgFileIterator debPackagesIndex::FindInCache(pkgCache &Cache) const +uint8_t debPackagesIndex::GetIndexFlags() const { - string const FileName = IndexFileName(); - pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; ++File) - { - if (File.FileName() == NULL || FileName != File.FileName()) - continue; - - struct stat St; - if (stat(File.FileName(),&St) != 0) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "PackagesIndex::FindInCache - stat failed on " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "PackagesIndex::FindInCache - size (" << St.st_size << " <> " << File->Size - << ") or mtime (" << St.st_mtime << " <> " << File->mtime - << ") doesn't match for " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - return File; - } - - return File; + return 0; } /*}}}*/ - -// TranslationsIndex::debTranslationsIndex - Contructor /*{{{*/ +// Translation-* Index /*{{{*/ debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) : - pkgIndexTargetFile(Target, true), d(NULL) + pkgDebianIndexTargetFile(Target, true), d(NULL) {} - /*}}}*/ -bool debTranslationsIndex::HasPackages() const /*{{{*/ +bool debTranslationsIndex::HasPackages() const { return Exists(); } - /*}}}*/ -// TranslationsIndex::Merge - Load the index file into a cache /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debTranslationsIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const -{ - // Check the translation file, if in use - string const TranslationFile = IndexFileName(); - if (FileExists(TranslationFile)) - { - FileFd Trans(TranslationFile,FileFd::ReadOnly, FileFd::Extension); - debTranslationsParser TransParser(&Trans); - if (_error->PendingError() == true) - return false; - - if (Prog != NULL) - Prog->SubProgress(0, Target.Description); - if (Gen.SelectFile(TranslationFile, *this, "", Target.Option(IndexTarget::COMPONENT), pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages) == false) - return _error->Error("Problem with SelectFile %s",TranslationFile.c_str()); - - // Store the IMS information - pkgCache::PkgFileIterator TransFile = Gen.GetCurFile(); - TransFile->Size = Trans.FileSize(); - TransFile->mtime = Trans.ModificationTime(); - - if (Gen.MergeList(TransParser) == false) - return _error->Error("Problem with MergeList %s",TranslationFile.c_str()); - } - +bool debTranslationsIndex::OpenListFile(FileFd &Pkg, std::string const &FileName) +{ + if (FileExists(FileName)) + return pkgDebianIndexTargetFile::OpenListFile(Pkg, FileName); return true; } - /*}}}*/ -// TranslationsIndex::FindInCache - Find this index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -pkgCache::PkgFileIterator debTranslationsIndex::FindInCache(pkgCache &Cache) const +uint8_t debTranslationsIndex::GetIndexFlags() const { - string FileName = IndexFileName(); - - pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; ++File) - { - if (FileName != File.FileName()) - continue; - - struct stat St; - if (stat(File.FileName(),&St) != 0) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "TranslationIndex::FindInCache - stat failed on " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "TranslationIndex::FindInCache - size (" << St.st_size << " <> " << File->Size - << ") or mtime (" << St.st_mtime << " <> " << File->mtime - << ") doesn't match for " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - return File; - } - return File; + return pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages; } - /*}}}*/ - -// StatusIndex::debStatusIndex - Constructor /*{{{*/ -// --------------------------------------------------------------------- -/* */ -debStatusIndex::debStatusIndex(string File) : pkgIndexFile(true), d(NULL), File(File) +std::string debTranslationsIndex::GetArchitecture() const { + return std::string(); } - /*}}}*/ -// StatusIndex::Size - Return the size of the index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -unsigned long debStatusIndex::Size() const +pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg) { - struct stat S; - if (stat(File.c_str(),&S) != 0) - return 0; - return S.st_size; -} - /*}}}*/ -// StatusIndex::Merge - Load the index file into a cache /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const -{ - FileFd Pkg(File,FileFd::ReadOnly, FileFd::Extension); - if (_error->PendingError() == true) - return false; - debListParser Parser(&Pkg); - if (_error->PendingError() == true) - return false; - - if (Prog != NULL) - Prog->SubProgress(0,File); - if (Gen.SelectFile(File, *this, "", "now", pkgCache::Flag::NotSource) == false) - return _error->Error("Problem with SelectFile %s",File.c_str()); - - // Store the IMS information - pkgCache::PkgFileIterator CFile = Gen.GetCurFile(); - pkgCacheGenerator::Dynamic DynFile(CFile); - CFile->Size = Pkg.FileSize(); - CFile->mtime = Pkg.ModificationTime(); - - if (Gen.MergeList(Parser) == false) - return _error->Error("Problem with MergeList %s",File.c_str()); - return true; + if (Pkg.IsOpen() == false) + return NULL; + _error->PushToStack(); + pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg); + bool const newError = _error->PendingError(); + _error->MergeWithStack(); + return newError ? NULL : Parser; } /*}}}*/ -// StatusIndex::FindInCache - Find this index /*{{{*/ -// --------------------------------------------------------------------- -/* */ -pkgCache::PkgFileIterator debStatusIndex::FindInCache(pkgCache &Cache) const +// dpkg/status Index /*{{{*/ +debStatusIndex::debStatusIndex(std::string const &File) : pkgDebianIndexRealFile(File, true), d(NULL) { - pkgCache::PkgFileIterator File = Cache.FileBegin(); - for (; File.end() == false; ++File) - { - if (this->File != File.FileName()) - continue; - - struct stat St; - if (stat(File.FileName(),&St) != 0) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "StatusIndex::FindInCache - stat failed on " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) - { - if (_config->FindB("Debug::pkgCacheGen", false)) - std::clog << "StatusIndex::FindInCache - size (" << St.st_size << " <> " << File->Size - << ") or mtime (" << St.st_mtime << " <> " << File->mtime - << ") doesn't match for " << File.FileName() << std::endl; - return pkgCache::PkgFileIterator(Cache); - } - return File; - } - return File; } - /*}}}*/ -// StatusIndex::Exists - Check if the index is available /*{{{*/ -// --------------------------------------------------------------------- -/* */ -APT_CONST bool debStatusIndex::Exists() const +std::string debStatusIndex::GetArchitecture() const { - // Abort if the file does not exist. - return true; + return std::string(); } - /*}}}*/ - -// debDebPkgFileIndex - Single .deb file /*{{{*/ -debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile) - : pkgIndexFile(true), d(NULL), DebFile(DebFile) +std::string debStatusIndex::GetComponent() const { - DebFileFullPath = flAbsPath(DebFile); + return "now"; } -std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const +uint8_t debStatusIndex::GetIndexFlags() const { - return "file:" + DebFileFullPath; + return pkgCache::Flag::NotSource; } -bool debDebPkgFileIndex::Exists() const + /*}}}*/ +// DebPkgFile Index - a single .deb file as an index /*{{{*/ +debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile) + : pkgDebianIndexRealFile(DebFile, true), d(NULL), DebFile(DebFile) { - return FileExists(DebFile); } bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &debfile) { + struct stat Buf; + if (stat(debfile.c_str(), &Buf) != 0) + return false; + // get the control data out of the deb file via dpkg-deb -I std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb"); std::vector Args; @@ -381,91 +191,73 @@ bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &de ExecWait(Child, "Popen"); content << "Filename: " << debfile << "\n"; - struct stat Buf; - if (stat(debfile.c_str(), &Buf) != 0) - return false; content << "Size: " << Buf.st_size << "\n"; return true; } -bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const +bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName) { - if(Prog) - Prog->SubProgress(0, "Reading deb file"); - // write the control data to a tempfile - SPtr DebControl = GetTempFile("deb-file-" + flNotDir(DebFile)); - if(DebControl == NULL) + if (GetTempFile("deb-file-" + flNotDir(FileName), true, &Pkg) == NULL) return false; std::ostringstream content; - if (GetContent(content, DebFile) == false) + if (GetContent(content, FileName) == false) return false; std::string const contentstr = content.str(); if (contentstr.empty()) return true; - DebControl->Write(contentstr.c_str(), contentstr.length()); - // rewind for the listparser - DebControl->Seek(0); - - // and give it to the list parser - debDebFileParser Parser(DebControl, DebFile); - if(Gen.SelectFile(DebFile, *this, "", "now", pkgCache::Flag::LocalSource) == false) - return _error->Error("Problem with SelectFile %s", DebFile.c_str()); - - pkgCache::PkgFileIterator File = Gen.GetCurFile(); - File->Size = DebControl->Size(); - File->mtime = DebControl->ModificationTime(); - - if (Gen.MergeList(Parser) == false) - return _error->Error("Problem with MergeLister for %s", DebFile.c_str()); - + if (Pkg.Write(contentstr.c_str(), contentstr.length()) == false || Pkg.Seek(0) == false) + return false; return true; } +pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg) +{ + if (Pkg.IsOpen() == false) + return NULL; + _error->PushToStack(); + pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile); + bool const newError = _error->PendingError(); + _error->MergeWithStack(); + return newError ? NULL : Parser; +} +uint8_t debDebPkgFileIndex::GetIndexFlags() const +{ + return pkgCache::Flag::LocalSource; +} +std::string debDebPkgFileIndex::GetArchitecture() const +{ + return std::string(); +} +std::string debDebPkgFileIndex::GetComponent() const +{ + return "local-deb"; +} pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const { + std::string const FileName = IndexFileName(); pkgCache::PkgFileIterator File = Cache.FileBegin(); for (; File.end() == false; ++File) { - if (File.FileName() == NULL || DebFile != File.FileName()) + if (File.FileName() == NULL || FileName != File.FileName()) continue; - - return File; + // we can't do size checks here as file size != content size + return File; } return File; } -unsigned long debDebPkgFileIndex::Size() const -{ - struct stat buf; - if(stat(DebFile.c_str(), &buf) != 0) - return 0; - return buf.st_size; -} - /*}}}*/ -// debDscFileIndex - a .dsc file /*{{{*/ + /*}}}*/ +// DscFile Index - a single .dsc file as an index /*{{{*/ debDscFileIndex::debDscFileIndex(std::string const &DscFile) - : pkgIndexFile(true), d(NULL), DscFile(DscFile) + : pkgDebianIndexRealFile(DscFile, true), d(NULL) { } -bool debDscFileIndex::Exists() const -{ - return FileExists(DscFile); -} - -unsigned long debDscFileIndex::Size() const -{ - struct stat buf; - if(stat(DscFile.c_str(), &buf) == 0) - return buf.st_size; - return 0; -} pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const { - if (!FileExists(DscFile)) + if (Exists() == false) return NULL; - - return new debDscRecordParser(DscFile,this); + return new debDscRecordParser(File, this); } /*}}}*/ @@ -478,7 +270,7 @@ class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -492,7 +284,7 @@ class APT_HIDDEN debIFTypeTrans : public debIFTypePkg class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE { return new debRecordParser(File.FileName(),*File.Cache()); }; @@ -501,7 +293,7 @@ class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type { public: - virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const APT_OVERRIDE + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE { return new debDebFileRecordParser(File.FileName()); }; @@ -510,7 +302,7 @@ class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type { public: - virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const APT_OVERRIDE + virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &DscFile) const APT_OVERRIDE { return new debDscRecordParser(DscFile, NULL); }; @@ -519,9 +311,9 @@ class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type { public: - virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const APT_OVERRIDE + virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &SourceDir) const APT_OVERRIDE { - return new debDscRecordParser(SourceDir + string("/debian/control"), NULL); + return new debDscRecordParser(SourceDir + std::string("/debian/control"), NULL); }; debIFTypeDebianSourceDir() {Label = "Debian control file";}; }; diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 4a818121a..02708b558 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -26,69 +26,73 @@ class OpProgress; class pkgAcquire; class pkgCacheGenerator; - -class debStatusIndex : public pkgIndexFile +class debStatusIndex : public pkgDebianIndexRealFile { void * const d; - protected: - std::string File; +protected: + virtual std::string GetArchitecture() const APT_OVERRIDE; + virtual std::string GetComponent() const APT_OVERRIDE; + virtual uint8_t GetIndexFlags() const APT_OVERRIDE; - public: +public: virtual const Type *GetType() const APT_CONST; - // Interface for acquire - virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE {return File;}; - // Interface for the Cache Generator - virtual bool Exists() const APT_OVERRIDE; virtual bool HasPackages() const APT_OVERRIDE {return true;}; - virtual unsigned long Size() const APT_OVERRIDE; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; + // Abort if the file does not exist. + virtual bool Exists() const APT_OVERRIDE {return true;}; - debStatusIndex(std::string File); + debStatusIndex(std::string const &File); virtual ~debStatusIndex(); }; -class debPackagesIndex : public pkgIndexTargetFile +class debPackagesIndex : public pkgDebianIndexTargetFile { void * const d; - public: +protected: + virtual uint8_t GetIndexFlags() const; +public: virtual const Type *GetType() const APT_CONST; // Stuff for accessing files on remote items - virtual std::string ArchiveInfo(pkgCache::VerIterator Ver) const APT_OVERRIDE; + virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const APT_OVERRIDE; // Interface for the Cache Generator virtual bool HasPackages() const APT_OVERRIDE {return true;}; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; debPackagesIndex(IndexTarget const &Target, bool const Trusted); virtual ~debPackagesIndex(); }; -class debTranslationsIndex : public pkgIndexTargetFile +class debTranslationsIndex : public pkgDebianIndexTargetFile { void * const d; - public: +protected: + virtual std::string GetArchitecture() const APT_OVERRIDE; + virtual uint8_t GetIndexFlags() const APT_OVERRIDE; + virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE; + APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; + +public: virtual const Type *GetType() const APT_CONST; // Interface for the Cache Generator virtual bool HasPackages() const APT_OVERRIDE; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; - virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; debTranslationsIndex(IndexTarget const &Target); virtual ~debTranslationsIndex(); }; -class debSourcesIndex : public pkgIndexTargetFile +class debSourcesIndex : public pkgDebianIndexTargetFile { void * const d; + virtual uint8_t GetIndexFlags() const; + virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE; + APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; + public: virtual const Type *GetType() const APT_CONST; @@ -107,19 +111,20 @@ class debSourcesIndex : public pkgIndexTargetFile virtual ~debSourcesIndex(); }; -class debDebPkgFileIndex : public pkgIndexFile +class debDebPkgFileIndex : public pkgDebianIndexRealFile { - private: void * const d; std::string DebFile; - std::string DebFileFullPath; - public: - virtual const Type *GetType() const APT_CONST; +protected: + virtual std::string GetComponent() const APT_OVERRIDE; + virtual std::string GetArchitecture() const APT_OVERRIDE; + virtual uint8_t GetIndexFlags() const APT_OVERRIDE; + virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE; + APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; - virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE { - return DebFile; - } +public: + virtual const Type *GetType() const APT_CONST; /** get the control (file) content of the deb file * @@ -130,35 +135,22 @@ class debDebPkgFileIndex : public pkgIndexFile static bool GetContent(std::ostream &content, std::string const &debfile); // Interface for the Cache Generator - virtual bool Exists() const APT_OVERRIDE; - virtual bool HasPackages() const APT_OVERRIDE { - return true; - }; - virtual unsigned long Size() const APT_OVERRIDE; - virtual bool Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const APT_OVERRIDE; + virtual bool HasPackages() const APT_OVERRIDE {return true;} virtual pkgCache::PkgFileIterator FindInCache(pkgCache &Cache) const APT_OVERRIDE; // Interface for acquire - virtual std::string ArchiveURI(std::string /*File*/) const APT_OVERRIDE; debDebPkgFileIndex(std::string const &DebFile); virtual ~debDebPkgFileIndex(); }; -class debDscFileIndex : public pkgIndexFile +class debDscFileIndex : public pkgDebianIndexRealFile { - private: void * const d; - std::string DscFile; public: virtual const Type *GetType() const APT_CONST; virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE; - virtual bool Exists() const APT_OVERRIDE; virtual bool HasPackages() const APT_OVERRIDE {return false;}; - virtual unsigned long Size() const APT_OVERRIDE; - virtual std::string Describe(bool /*Short*/) const APT_OVERRIDE { - return DscFile; - }; debDscFileIndex(std::string const &DscFile); virtual ~debDscFileIndex(); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index b7988d499..cb2b15668 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -50,8 +50,9 @@ static debListParser::WordList PrioList[] = { /* Provide an architecture and only this one and "all" will be accepted in Step(), if no Architecture is given we will accept every arch we would accept in general with checkArchitecture() */ -debListParser::debListParser(FileFd *File, string const &Arch) : d(NULL), Tags(File), - Arch(Arch) { +debListParser::debListParser(FileFd *File, string const &Arch) : + pkgCacheListParser(), d(NULL), Tags(File), Arch(Arch) +{ if (Arch == "native") this->Arch = _config->Find("APT::Architecture"); Architectures = APT::Configuration::getArchitectures(); @@ -931,7 +932,7 @@ unsigned char debListParser::GetPrio(string Str) bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/ pkgCache::VerIterator const &Ver) { - if (pkgCacheGenerator::ListParser::SameVersion(Hash, Ver) == false) + if (pkgCacheListParser::SameVersion(Hash, Ver) == false) return false; // status file has no (Download)Size, but all others are fair game // status file is parsed last, so the first version we encounter is diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 30e52718d..975620070 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -26,7 +26,7 @@ class FileFd; -class APT_HIDDEN debListParser : public pkgCacheGenerator::ListParser +class APT_HIDDEN debListParser : public pkgCacheListParser { public: -- cgit v1.2.3 From 7f8c0eed6983db7b8959f1498fc8bc80c98d719e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 20 Jul 2015 12:32:46 +0200 Subject: parse packages from all architectures into the cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we can dynamically create dependencies and provides as needed rather than requiring to know with which architectures we will deal before running we can allow the listparser to parse all records rather than skipping records of "unknown" architectures. This can e.g. happen if a user has foreign architecture packages in his status file without dpkg knowing about this architecture (or apt configured in this way). A sideeffect is that now arch:all packages are (correctly) recorded as available from any Packages file, not just from the native one – which has its downsides for the resolver as mixed-arch source packages can appear in different architectures at different times, but that is the problem of the resolver and dealing with it in the parser is at best a hack (and also depends on a helpful repository). Another sideeffect is that his allows :none packages to appear in Packages files again as we don't do any kind of checks now, but given that they aren't really supported (anymore) by anyone we can live with that. --- apt-pkg/deb/deblistparser.cc | 39 ++++----------------------------------- apt-pkg/deb/deblistparser.h | 9 +++------ 2 files changed, 7 insertions(+), 41 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index cb2b15668..c7c4ffe77 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -50,13 +50,9 @@ static debListParser::WordList PrioList[] = { /* Provide an architecture and only this one and "all" will be accepted in Step(), if no Architecture is given we will accept every arch we would accept in general with checkArchitecture() */ -debListParser::debListParser(FileFd *File, string const &Arch) : - pkgCacheListParser(), d(NULL), Tags(File), Arch(Arch) +debListParser::debListParser(FileFd *File) : + pkgCacheListParser(), d(NULL), Tags(File) { - if (Arch == "native") - this->Arch = _config->Find("APT::Architecture"); - Architectures = APT::Configuration::getArchitectures(); - MultiArchEnabled = Architectures.size() > 1; } /*}}}*/ // ListParser::Package - Return the package name /*{{{*/ @@ -887,34 +883,7 @@ bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out) bool debListParser::Step() { iOffset = Tags.Offset(); - while (Tags.Step(Section) == true) - { - /* See if this is the correct Architecture, if it isn't then we - drop the whole section. A missing arch tag only happens (in theory) - inside the Status file, so that is a positive return */ - string const Architecture = Section.FindS("Architecture"); - - if (Arch.empty() == true || Arch == "any" || MultiArchEnabled == false) - { - if (APT::Configuration::checkArchitecture(Architecture) == true) - return true; - /* parse version stanzas without an architecture only in the status file - (and as misfortune bycatch flat-archives) */ - if ((Arch.empty() == true || Arch == "any") && Architecture.empty() == true) - return true; - } - else - { - if (Architecture == Arch) - return true; - - if (Architecture == "all" && Arch == _config->Find("APT::Architecture")) - return true; - } - - iOffset = Tags.Offset(); - } - return false; + return Tags.Step(Section); } /*}}}*/ // ListParser::GetPrio - Convert the priority from a string /*{{{*/ @@ -950,7 +919,7 @@ bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/ /*}}}*/ debDebFileParser::debDebFileParser(FileFd *File, std::string const &DebFile) - : debListParser(File, ""), DebFile(DebFile) + : debListParser(File), DebFile(DebFile) { } diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 975620070..747e022d8 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -45,9 +45,6 @@ class APT_HIDDEN debListParser : public pkgCacheListParser pkgTagFile Tags; pkgTagSection Section; map_filesize_t iOffset; - std::string Arch; - std::vector Architectures; - bool MultiArchEnabled; virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver); bool ParseDepends(pkgCache::VerIterator &Ver,const char *Tag, @@ -96,7 +93,7 @@ class APT_HIDDEN debListParser : public pkgCacheListParser APT_PUBLIC static const char *ConvertRelation(const char *I,unsigned int &Op); - debListParser(FileFd *File, std::string const &Arch = ""); + debListParser(FileFd *File); virtual ~debListParser(); }; @@ -118,8 +115,8 @@ class APT_HIDDEN debTranslationsParser : public debListParser virtual std::string Architecture() APT_OVERRIDE { return ""; } virtual std::string Version() APT_OVERRIDE { return ""; } - debTranslationsParser(FileFd *File, std::string const &Arch = "") - : debListParser(File, Arch) {}; + debTranslationsParser(FileFd *File) + : debListParser(File) {}; }; #endif -- cgit v1.2.3 From cc480836c739e36dc0c741fa333248c0a8150ec7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 20 Jul 2015 13:34:25 +0200 Subject: drop obsolete explicit :none handling in pkgCacheGen We archieve the same without the special handling now, so drop this code. Makes supporting this abdomination a little longer bearable as well. Git-Dch: Ignore --- apt-pkg/deb/deblistparser.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index c7c4ffe77..a908057d7 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -69,7 +69,8 @@ string debListParser::Package() { // --------------------------------------------------------------------- /* This will return the Architecture of the package this section describes */ string debListParser::Architecture() { - return Section.FindS("Architecture"); + std::string const Arch = Section.FindS("Architecture"); + return Arch.empty() ? "none" : Arch; } /*}}}*/ // ListParser::ArchitectureAll /*{{{*/ -- cgit v1.2.3 From 22df31be37d56c07ed029f5a4d5041f21070d2d6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 10 Aug 2015 11:31:28 +0200 Subject: no value for MultiArch field is 'no', not 'none' Git-Dch: Ignore --- apt-pkg/deb/deblistparser.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index a908057d7..489d0434e 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -95,14 +95,14 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ unsigned char MA; string const MultiArch = Section.FindS("Multi-Arch"); if (MultiArch.empty() == true || MultiArch == "no") - MA = pkgCache::Version::None; + MA = pkgCache::Version::No; else if (MultiArch == "same") { if (ArchitectureAll() == true) { if (showErrors == true) _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same", Section.FindS("Package").c_str()); - MA = pkgCache::Version::None; + MA = pkgCache::Version::No; } else MA = pkgCache::Version::Same; @@ -116,7 +116,7 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ if (showErrors == true) _error->Warning("Unknown Multi-Arch type '%s' for package '%s'", MultiArch.c_str(), Section.FindS("Package").c_str()); - MA = pkgCache::Version::None; + MA = pkgCache::Version::No; } if (ArchitectureAll() == true) -- cgit v1.2.3 From 6d7122b5356c0b4d8f51aafdfc1c232392fca695 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 11 Aug 2015 15:58:03 +0200 Subject: Annotate more methods with APT_OVERRIDE Gbp-Dch: ignore Reported-By: g++ -Wsuggest-override Thanks: g++ -Wsuggest-override --- apt-pkg/deb/debindexfile.h | 18 +++++++++--------- apt-pkg/deb/debversion.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.h b/apt-pkg/deb/debindexfile.h index 02708b558..dc75a01ab 100644 --- a/apt-pkg/deb/debindexfile.h +++ b/apt-pkg/deb/debindexfile.h @@ -36,7 +36,7 @@ protected: public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; // Interface for the Cache Generator virtual bool HasPackages() const APT_OVERRIDE {return true;}; @@ -51,10 +51,10 @@ class debPackagesIndex : public pkgDebianIndexTargetFile { void * const d; protected: - virtual uint8_t GetIndexFlags() const; + virtual uint8_t GetIndexFlags() const APT_OVERRIDE; public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; // Stuff for accessing files on remote items virtual std::string ArchiveInfo(pkgCache::VerIterator const &Ver) const APT_OVERRIDE; @@ -77,7 +77,7 @@ protected: public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; // Interface for the Cache Generator virtual bool HasPackages() const APT_OVERRIDE; @@ -89,13 +89,13 @@ public: class debSourcesIndex : public pkgDebianIndexTargetFile { void * const d; - virtual uint8_t GetIndexFlags() const; + virtual uint8_t GetIndexFlags() const APT_OVERRIDE; virtual bool OpenListFile(FileFd &Pkg, std::string const &FileName) APT_OVERRIDE; APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; // Stuff for accessing files on remote items virtual std::string SourceInfo(pkgSrcRecords::Parser const &Record, @@ -124,7 +124,7 @@ protected: APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; /** get the control (file) content of the deb file * @@ -148,7 +148,7 @@ class debDscFileIndex : public pkgDebianIndexRealFile { void * const d; public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; virtual pkgSrcRecords::Parser *CreateSrcParser() const APT_OVERRIDE; virtual bool HasPackages() const APT_OVERRIDE {return false;}; @@ -159,7 +159,7 @@ class debDscFileIndex : public pkgDebianIndexRealFile class debDebianSourceDirIndex : public debDscFileIndex { public: - virtual const Type *GetType() const APT_CONST; + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; }; #endif diff --git a/apt-pkg/deb/debversion.h b/apt-pkg/deb/debversion.h index 6d7eca7c1..db70c8797 100644 --- a/apt-pkg/deb/debversion.h +++ b/apt-pkg/deb/debversion.h @@ -24,8 +24,8 @@ class debVersioningSystem : public pkgVersioningSystem // Compare versions.. virtual int DoCmpVersion(const char *A,const char *Aend, - const char *B,const char *Bend) APT_PURE; - virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer) APT_PURE; + const char *B,const char *Bend) APT_OVERRIDE APT_PURE; + virtual bool CheckDep(const char *PkgVer,int Op,const char *DepVer) APT_OVERRIDE APT_PURE; virtual APT_PURE int DoCmpReleaseVer(const char *A,const char *Aend, const char *B,const char *Bend) APT_OVERRIDE { -- cgit v1.2.3 From a4256c6bb57dbb59767824133a9a42eceeadc522 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 14 Oct 2014 13:52:33 +0200 Subject: Do not set unhonored DPKG_NO_TSTP variable for dpkg Support for that variable was removed in dpkg in 1.15.6, in commit 6f037003e8b96878b485efb7cbd1f846e3bf4e97. Closes: #765366 --- apt-pkg/deb/dpkgpm.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c578cc338..644e4d8e4 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1545,9 +1545,6 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) _exit(100); } - /* No Job Control Stop Env is a magic dpkg var that prevents it - from using sigstop */ - putenv((char *)"DPKG_NO_TSTP=yes"); execvp(Args[0], (char**) &Args[0]); cerr << "Could not exec dpkg!" << endl; _exit(100); -- cgit v1.2.3 From 88a8975f156e452d9f3ebe76822b236e8962ebba Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 17 Aug 2015 12:01:45 +0200 Subject: Cleanup includes after running iwyu --- apt-pkg/deb/debindexfile.cc | 11 +---------- apt-pkg/deb/deblistparser.cc | 2 -- apt-pkg/deb/debmetaindex.cc | 3 --- apt-pkg/deb/debversion.cc | 1 - apt-pkg/deb/dpkgpm.cc | 2 -- 5 files changed, 1 insertion(+), 18 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index 627cd36c5..d3599b353 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -16,27 +16,18 @@ #include #include #include -#include #include -#include -#include -#include -#include #include #include -#include #include #include -#include #include #include -#include #include #include -#include #include -#include + #include /*}}}*/ diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 489d0434e..42eca8677 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -18,10 +18,8 @@ #include #include #include -#include #include #include -#include #include #include #include diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 123c91648..b2e9eeb00 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -20,12 +20,9 @@ #include #include #include -#include #include -#include #include -#include #include #include diff --git a/apt-pkg/deb/debversion.cc b/apt-pkg/deb/debversion.cc index 043025912..48462c6a2 100644 --- a/apt-pkg/deb/debversion.cc +++ b/apt-pkg/deb/debversion.cc @@ -16,7 +16,6 @@ #include #include -#include #include #include /*}}}*/ diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 644e4d8e4..6ae85d2ea 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -27,7 +26,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From ac7f8f7916f16905d8eeb0133bc650d89726d0f4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 17 Aug 2015 14:29:02 +0200 Subject: Fix all the wrong removals of includes that iwyu got wrong Git-Dch: ignore --- apt-pkg/deb/debindexfile.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index d3599b353..c43ee7b91 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -27,6 +27,7 @@ #include #include #include +#include #include /*}}}*/ -- cgit v1.2.3