From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Fri, 31 Jan 2020 16:53:09 +0300 Message-Id: <20200131135309.62873-1-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt] Properly process duplicated 3rd-party packages X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jan 2020 13:53:41 -0000 Archived-At: List-Archive: List-Post: If apt is configured via RPM::Allow-Duplicated configuration option to recognize 3rd-party duplicate packages, and such packages lack '%NAME = %EVR' provide or some similar form of provide with package name, apt currently can only find such package via full name form, which in addition to name may include %EVR, %DISTTAG and %BUILDTIME if such tags are present. This change would allow apt to find such packages using their names only. --- apt/apt-pkg/pkgcachegen.cc | 17 +++++++++++++++++ apt/apt-pkg/pkgcachegen.h | 4 +++- apt/apt-pkg/rpm/rpmlistparser.cc | 5 +++++ apt/apt-pkg/rpm/rpmlistparser.h | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apt/apt-pkg/pkgcachegen.cc b/apt/apt-pkg/pkgcachegen.cc index 56716b5..f6e2153 100644 --- a/apt/apt-pkg/pkgcachegen.cc +++ b/apt/apt-pkg/pkgcachegen.cc @@ -302,6 +302,23 @@ bool pkgCacheGenerator::MergeList(ListParser &List, Ver->ParentPkg = Pkg.Index(); Ver->Hash = Hash; + + if (List.IsDuplicatePackage()) + { + /* Some duplicated third-party packages don't have a provide + * in form of "name = version", so add one. + * It'll be useful when user tries to remove such package by it's name + * or interact with it in some other way. + * It may be a good idea to check if such virtual provide exists before adding one, + * but skipping this check shouldn't introduce a lot of additional overhead + * since only duplicate packages are affected, and there shouldn't be a lot of them. + */ + if (not List.NewProvides(Ver, PackageName.substr(0, PackageName.find('#')), Version)) + { + return _error->Error(_("Error occured while processing %s (NewProvides%d)"), PackageName.c_str(), 1); + } + } + if (List.NewVersion(Ver) == false) return _error->Error(_("Error occured while processing %s (NewVersion%d)"), PackageName.c_str(), 2); diff --git a/apt/apt-pkg/pkgcachegen.h b/apt/apt-pkg/pkgcachegen.h index 77075a6..9d42bbd 100644 --- a/apt/apt-pkg/pkgcachegen.h +++ b/apt/apt-pkg/pkgcachegen.h @@ -169,15 +169,17 @@ class pkgCacheGenerator::ListParser bool NewDepends(pkgCache::VerIterator &Ver, const string &Package, const string &Version,unsigned int Op, unsigned int Type); - bool NewProvides(pkgCache::VerIterator &Ver,const string &Package, const string &Version); public: + + bool NewProvides(pkgCache::VerIterator &Ver,const string &Package, const string &Version); // These all operate against the current section virtual string Package() = 0; virtual string Version() = 0; // CNC:2002-07-09 virtual string Architecture() {return string();}; + virtual bool IsDuplicatePackage() { return false; } virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; virtual unsigned short VersionHash() = 0; virtual bool UsePackage(pkgCache::PkgIterator &Pkg, diff --git a/apt/apt-pkg/rpm/rpmlistparser.cc b/apt/apt-pkg/rpm/rpmlistparser.cc index 9b2e9ad..abeabaa 100644 --- a/apt/apt-pkg/rpm/rpmlistparser.cc +++ b/apt/apt-pkg/rpm/rpmlistparser.cc @@ -197,6 +197,11 @@ string rpmListParser::Architecture() res = headerGetEntry(header, RPMTAG_ARCH, &type, (void **)&arch, &count); return string(res?arch:""); } + +bool rpmListParser::IsDuplicatePackage() +{ + return Duplicated; +} /*}}}*/ #include diff --git a/apt/apt-pkg/rpm/rpmlistparser.h b/apt/apt-pkg/rpm/rpmlistparser.h index 6862f09..c4e1c7c 100644 --- a/apt/apt-pkg/rpm/rpmlistparser.h +++ b/apt/apt-pkg/rpm/rpmlistparser.h @@ -63,6 +63,7 @@ class rpmListParser : public pkgCacheGenerator::ListParser virtual string Package() override; virtual string Version() override; virtual string Architecture() override; + virtual bool IsDuplicatePackage() override; virtual bool NewVersion(pkgCache::VerIterator &Ver) override; virtual unsigned short VersionHash() override; virtual bool UsePackage(pkgCache::PkgIterator &Pkg, -- 2.24.1