[devel] [PATCH for apt] Properly process duplicated 3rd-party packages

Aleksei Nikiforov darktemplar на altlinux.org
Пт Янв 31 16:53:09 MSK 2020


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 <sstream>
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



Подробная информация о списке рассылки Devel