[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#470035: Add a hook to customize what MarkInstall recursively installs.



Package: apt
Version: 0.7.12
Severity: wishlist
Tags: patch

  In some cases, it would be useful to be able to control how
MarkInstall recurs over the package graph.  For instance, aptitude
allows users to mark versions that they never want to have automatically
installed, but MarkInstall will happily go ahead and install them.

  The attached patch adds a new virtual method on pkgDepCache that's
used to determine whether MarkInstall should follow a dependency to
install a particular package version or to remove a package.  By default
there are no restrictions (the current behavior).

  Daniel
=== modified file 'apt-pkg/depcache.cc'
--- apt-pkg/depcache.cc	2007-12-30 20:51:43 +0000
+++ apt-pkg/depcache.cc	2008-03-08 18:46:53 +0000
@@ -968,7 +968,8 @@
 	    }
 	 }
 	 
-	 if (InstPkg.end() == false) 
+	 if (InstPkg.end() == false &&
+	     AutoInstOk(InstPkg, (*this)[InstPkg].CandidateVerIter(*this), Start))
 	 {
 	    if(_config->FindB("Debug::pkgDepCache::AutoInstall",false) == true)
 	       std::clog << "Installing " << InstPkg.Name() 
@@ -980,7 +981,8 @@
  	       if(_config->FindB("Debug::pkgDepCache::AutoInstall",false) == true)
  		  std::clog << "Setting NOT as auto-installed (direct "
 			    << Start.DepType() << " of pkg in APT::Never-MarkAuto-Section)" << std::endl;
- 	       MarkInstall(InstPkg,true,Depth + 1, true);
+
+	       MarkInstall(InstPkg,true,Depth + 1, true);
  	    }
  	    else 
  	    {
@@ -1006,15 +1008,26 @@
 	    PkgIterator Pkg = Ver.ParentPkg();
 
 	    if (Start->Type != Dep::DpkgBreaks)
-	       MarkDelete(Pkg);
+	      {
+		if(AutoInstOk(Pkg, VerIterator(*this), Start))
+		  MarkDelete(Pkg);
+	      }
 	    else
-	       if (PkgState[Pkg->ID].CandidateVer != *I)
+	       if (PkgState[Pkg->ID].CandidateVer != *I &&
+		   AutoInstOk(Pkg, VerIterator(*this, PkgState[Pkg->ID].CandidateVer), Start))
 		  MarkInstall(Pkg,true,Depth + 1, false, ForceImportantDeps);
 	 }
 	 continue;
       }      
    }
 }
+
+bool pkgDepCache::AutoInstOk(const PkgIterator &pkg,
+			     const VerIterator &ver,
+			     const DepIterator &dep)
+{
+  return true;
+}
 									/*}}}*/
 // DepCache::SetReInstall - Set the reinstallation flag			/*{{{*/
 // ---------------------------------------------------------------------

=== modified file 'apt-pkg/depcache.h'
--- apt-pkg/depcache.h	2007-06-19 09:49:08 +0000
+++ apt-pkg/depcache.h	2008-03-08 18:46:43 +0000
@@ -360,6 +360,20 @@
     */
    virtual bool MarkFollowsSuggests();
 
+   /** \return \b true if it's OK for MarkInstall to recursively
+    *  install the given version of the given package.
+    *
+    *  \param p  the package that MarkInstall wants to install.
+    *  \param v  the version being installed, or an end iterator
+    *            if p is being removed.
+    *  \param d  the dependency being fixed.
+    *
+    *  The default implementation unconditionally returns \b true.
+    */
+   virtual bool AutoInstOk(const PkgIterator &p,
+			   const VerIterator &v,
+			   const DepIterator &d);
+
    /** \brief Update the Marked and Garbage fields of all packages.
     *
     *  This routine is implicitly invoked after all state manipulators


Reply to: