Просмотр исходного кода

edsp: use a stanza based interface for solution writing

EDSP had a WriteSolution method to write out the entire solution based
on the inspection of a given pkgDepCache, but that is rather inflexible
both for EDSP itself and for other EDSP like-protocols. It seems better
to use a smaller scope in printing just a single stanza based on a given
version as there is more reuse potential.
David Kalnischkies лет назад: 10
Родитель
Сommit
71608330b9
4 измененных файлов с 34 добавлено и 39 удалено
  1. 6 27
      apt-pkg/edsp.cc
  2. 10 10
      apt-pkg/edsp.h
  3. 17 1
      cmdline/apt-internal-solver.cc
  4. 1 1
      debian/libapt-pkg5.0.symbols

+ 6 - 27
apt-pkg/edsp.cc

@@ -871,7 +871,7 @@ bool EDSP::ApplyRequest(std::list<std::string> const &install,
 	return true;
 }
 									/*}}}*/
-// EDSP::WriteSolution - to the given file descriptor			/*{{{*/
+// EDSP::WriteSolutionStanza - to the given file descriptor		/*{{{*/
 bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
 {
    bool const Debug = _config->FindB("Debug::EDSP::WriteSolution", false);
@@ -903,34 +903,13 @@ bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
 
    return true;
 }
-bool EDSP::WriteSolution(pkgDepCache &Cache, FileFd &output)
+bool EDSP::WriteSolutionStanza(FileFd &output, char const * const Type, pkgCache::VerIterator const &Ver)
 {
-   bool const Debug = _config->FindB("Debug::EDSP::WriteSolution", false);
    bool Okay = output.Failed() == false;
-   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false && likely(Okay); ++Pkg)
-   {
-      std::string action;
-      if (Cache[Pkg].Delete() == true)
-	 WriteOkay(Okay, output, "Remove: ", _system->GetVersionMapping(Pkg.CurrentVer()->ID), "\n");
-      else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
-	 WriteOkay(Okay, output, "Install: ", _system->GetVersionMapping(Cache.GetCandidateVersion(Pkg)->ID), "\n");
-      else if (Cache[Pkg].Garbage == true)
-	 WriteOkay(Okay, output, "Autoremove: ", _system->GetVersionMapping(Pkg.CurrentVer()->ID), "\n");
-      else
-	 continue;
-
-      if (Debug)
-      {
-	 WriteOkay(Okay, output, "Package: ", Pkg.FullName(), "\nVersion: ");
-	 if (Cache[Pkg].Delete() == true || Cache[Pkg].Garbage == true)
-	    WriteOkay(Okay, output, Pkg.CurrentVer().VerStr(), "\n\n");
-	 else
-	    WriteOkay(Okay, output, Cache.GetCandidateVersion(Pkg).VerStr(), "\n\n");
-      }
-      else
-	 WriteOkay(Okay, output, "\n");
-   }
-   return Okay;
+   WriteOkay(Okay, output, Type, ": ", _system->GetVersionMapping(Ver->ID));
+   if (_config->FindB("Debug::EDSP::WriteSolution", false) == true)
+      WriteOkay(Okay, output, "\nPackage: ", Ver.ParentPkg().FullName(), "\nVersion: ", Ver.VerStr());
+   return WriteOkay(Okay, output, "\n\n");
 }
 									/*}}}*/
 // EDSP::WriteProgess - pulse to the given file descriptor		/*{{{*/

+ 10 - 10
apt-pkg/edsp.h

@@ -158,20 +158,20 @@ namespace EDSP								/*{{{*/
 				 std::list<std::string> const &remove,
 				 pkgDepCache &Cache);
 
-	/** \brief encodes the changes in the Cache as a EDSP solution
+	/** \brief formats a solution stanza for the given version
 	 *
-	 *  The markers in the Cache are observed and send to given
-	 *  file. The solution isn't checked for consistency or alike,
-	 *  so even broken solutions can be written successfully,
-	 *  but the front-end revicing it will properly fail then.
+	 *  EDSP uses a simple format for reporting solutions:
+	 *  A single required field name with an ID as value.
+	 *  Additional fields might appear as debug aids.
 	 *
-	 *  \param Cache which represents the solution
-	 *  \param output to write the stanzas forming the solution to
+	 *  \param output to write the stanza forming the solution to
+	 *  \param Type of the stanza, used as field name
+	 *  \param Ver this stanza applies to
 	 *
-	 *  \return true if solution could be written, otherwise false
+	 *  \return true if stanza could be written, otherwise false
 	 */
-	bool WriteSolution(pkgDepCache &Cache, FileFd &output);
-	bool WriteSolution(pkgDepCache &Cache, FILE* output) APT_DEPRECATED_MSG("Use FileFd-based interface instead");
+	bool WriteSolutionStanza(FileFd &output, char const * const Type, pkgCache::VerIterator const &Ver);
+	bool WriteSolution(pkgDepCache &Cache, FILE* output) APT_DEPRECATED_MSG("Use FileFd-based single-stanza interface instead");
 
 	/** \brief sends a progress report
 	 *

+ 17 - 1
cmdline/apt-internal-solver.cc

@@ -63,6 +63,22 @@ static std::vector<aptDispatchWithHelp> GetCommands()			/*{{{*/
    return {};
 }
 									/*}}}*/
+static bool WriteSolution(pkgDepCache &Cache, FileFd &output)		/*{{{*/
+{
+   bool Okay = output.Failed() == false;
+   for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false && likely(Okay); ++Pkg)
+   {
+      std::string action;
+      if (Cache[Pkg].Delete() == true)
+	 Okay &= EDSP::WriteSolutionStanza(output, "Remove", Pkg.CurrentVer());
+      else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
+	 Okay &= EDSP::WriteSolutionStanza(output, "Install", Cache.GetCandidateVersion(Pkg));
+      else if (Cache[Pkg].Garbage == true)
+	 Okay &= EDSP::WriteSolutionStanza(output, "Autoremove", Pkg.CurrentVer());
+   }
+   return Okay;
+}
+									/*}}}*/
 int main(int argc,const char *argv[])					/*{{{*/
 {
 	// we really don't need anything
@@ -187,7 +203,7 @@ int main(int argc,const char *argv[])					/*{{{*/
 
 	EDSP::WriteProgress(95, "Write solution…", output);
 
-	if (EDSP::WriteSolution(CacheFile, output) == false)
+	if (WriteSolution(CacheFile, output) == false)
 		DIE("Failed to output the solution!");
 
 	EDSP::WriteProgress(100, "Done", output);

+ 1 - 1
debian/libapt-pkg5.0.symbols

@@ -1475,7 +1475,7 @@ libapt-pkg.so.5.0 libapt-pkg5.0 #MINVER#
  (c++)"EDSP::WriteProgress(unsigned short, char const*, FileFd&)@APTPKG_5.0" 1.3~exp2
  (c++)"EDSP::WriteRequest(pkgDepCache&, FileFd&, unsigned int, OpProgress*)@APTPKG_5.0" 1.3~exp2
  (c++)"EDSP::WriteScenario(pkgDepCache&, FileFd&, OpProgress*)@APTPKG_5.0" 1.3~exp2
- (c++)"EDSP::WriteSolution(pkgDepCache&, FileFd&)@APTPKG_5.0" 1.3~exp2
+ (c++)"EDSP::WriteSolutionStanza(FileFd&, char const*, pkgCache::VerIterator const&)@APTPKG_5.0" 1.3~exp2
  (c++)"int __gnu_cxx::__stoa<long, int, char, int>(long (*)(char const*, char**, int), char const*, char const*, unsigned long*, int)@APTPKG_5.0" 1.3~exp2
  (c++)"std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, std::_Get_time<char>)@APTPKG_5.0" 1.3~exp2
  (c++)"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::_Put_time<char>)@APTPKG_5.0" 1.3~exp2