ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] [PATCH for apt] Properly process duplicated 3rd-party packages
@ 2020-01-31 13:53 Aleksei Nikiforov
  0 siblings, 0 replies; only message in thread
From: Aleksei Nikiforov @ 2020-01-31 13:53 UTC (permalink / raw)
  To: devel; +Cc: Aleksei Nikiforov

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-31 13:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-31 13:53 [devel] [PATCH for apt] Properly process duplicated 3rd-party packages Aleksei Nikiforov

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git