From: Julian Andres Klode <jak@debian.org>
Date: Wed, 26 Aug 2015 22:28:47 +0000 (+0200)
Subject: install: Set a local deb as the candidate for that package
X-Git-Tag: 1.1.exp11~4
X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/848fd2a65fa2aef296d44c9a19b89ac272ca12fe?hp=b6192267c23ffda1b9c8328537a5f2c83e176c26

install: Set a local deb as the candidate for that package

This ensures that we can install .deb files that are not the
candidate for a given package.
---

diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 844fcbc7e..3647ca99d 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -675,6 +675,18 @@ bool DoInstall(CommandLine &CmdL)
    
    std::map<unsigned short, APT::VersionSet> verset;
 
+   for (const char **I = CmdL.FileList; *I != 0; I++) {
+      // Check for local pkgs like in the loop above.
+      if(!FileExists(*I) || flExtension(*I) != "deb")
+	 continue;
+
+      pkgCache::PkgIterator pkg = Cache->FindPkg(*I);
+
+      // Set any version providing the .deb as the candidate.
+      for (auto Prv = pkg.ProvidesList(); Prv.end() == false; Prv++)
+	 Cache.GetDepCache()->SetCandidateVersion(Prv.OwnerVer());
+   }
+
    if(!DoCacheManipulationFromCommandLine(CmdL, Cache, verset, 0))
       return false;
 
diff --git a/test/integration/test-apt-get-install-deb b/test/integration/test-apt-get-install-deb
index bd720bede..65951cede 100755
--- a/test/integration/test-apt-get-install-deb
+++ b/test/integration/test-apt-get-install-deb
@@ -60,3 +60,21 @@ The following NEW packages will be installed:
 Remv foo:i386 [1.0]
 Inst foo (1.0 local-deb [amd64])
 Conf foo (1.0 local-deb [amd64])" aptget install ./incoming/foo_1.0_amd64.deb -s -q=0
+
+# Check that installing the local deb works if it is not the candidate
+echo "Package: foo
+Pin: version 1.0
+Pin-Priority: -1" > rootdir/etc/apt/preferences
+
+testsuccessequal "Reading package lists...
+Building dependency tree...
+Reading state information...
+Note, selecting 'foo' instead of './incoming/foo_1.0_amd64.deb'
+The following packages will be REMOVED:
+  foo:i386
+The following NEW packages will be installed:
+  foo
+0 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv foo:i386 [1.0]
+Inst foo (1.0 local-deb [amd64])
+Conf foo (1.0 local-deb [amd64])" aptget install ./incoming/foo_1.0_amd64.deb -s -q=0