edspsystem.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. This system provides the abstraction to use the scenario file as the
  5. only source of package information to be able to feed the created file
  6. back to APT for its own consumption (eat your own dogfood).
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <config.h>
  11. #include <apt-pkg/configuration.h>
  12. #include <apt-pkg/debversion.h>
  13. #include <apt-pkg/edspindexfile.h>
  14. #include <apt-pkg/edspsystem.h>
  15. #include <apt-pkg/pkgcache.h>
  16. #include <apt-pkg/cacheiterators.h>
  17. #include <apt-pkg/fileutl.h>
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <string>
  22. #include <vector>
  23. /*}}}*/
  24. // System::System - Constructor /*{{{*/
  25. edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &debVS)
  26. {
  27. }
  28. edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
  29. {
  30. }
  31. eippSystem::eippSystem() : edspLikeSystem("Debian APT planner interface")
  32. {
  33. }
  34. /*}}}*/
  35. // System::Lock - Get the lock /*{{{*/
  36. bool edspLikeSystem::Lock()
  37. {
  38. return true;
  39. }
  40. /*}}}*/
  41. // System::UnLock - Drop a lock /*{{{*/
  42. bool edspLikeSystem::UnLock(bool /*NoErrors*/)
  43. {
  44. return true;
  45. }
  46. /*}}}*/
  47. // System::CreatePM - Create the underlying package manager /*{{{*/
  48. // ---------------------------------------------------------------------
  49. /* we can't use edsp input as input for real installations - just a
  50. simulation can work, but everything else will fail bigtime */
  51. pkgPackageManager *edspLikeSystem::CreatePM(pkgDepCache * /*Cache*/) const
  52. {
  53. return nullptr;
  54. }
  55. /*}}}*/
  56. // System::Initialize - Setup the configuration space.. /*{{{*/
  57. bool edspLikeSystem::Initialize(Configuration &Cnf)
  58. {
  59. Cnf.Set("Dir::Log", "/dev/null");
  60. // state is included completely in the input files
  61. Cnf.Set("Dir::Etc::preferences", "/dev/null");
  62. Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
  63. Cnf.Set("Dir::State::status","/dev/null");
  64. Cnf.Set("Dir::State::extended_states","/dev/null");
  65. Cnf.Set("Dir::State::lists","/dev/null");
  66. // do not store an mmap cache
  67. Cnf.Set("Dir::Cache::pkgcache", "");
  68. Cnf.Set("Dir::Cache::srcpkgcache", "");
  69. // the protocols only propose actions, not do them
  70. Cnf.Set("Debug::NoLocking", "true");
  71. Cnf.Set("APT::Get::Simulate", "true");
  72. StatusFile.reset(nullptr);
  73. return true;
  74. }
  75. bool edspSystem::Initialize(Configuration &Cnf)
  76. {
  77. if (edspLikeSystem::Initialize(Cnf) == false)
  78. return false;
  79. std::string const tmp = GetTempDir();
  80. char tmpname[300];
  81. snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str());
  82. if (nullptr == mkdtemp(tmpname))
  83. return false;
  84. tempDir = tmpname;
  85. tempStatesFile = flCombine(tempDir, "extended_states");
  86. Cnf.Set("Dir::State::extended_states", tempStatesFile);
  87. tempPrefsFile = flCombine(tempDir, "apt_preferences");
  88. Cnf.Set("Dir::Etc::preferences", tempPrefsFile);
  89. return true;
  90. }
  91. /*}}}*/
  92. // System::ArchiveSupported - Is a file format supported /*{{{*/
  93. bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
  94. {
  95. return false;
  96. }
  97. /*}}}*/
  98. // System::Score - Never use the EDSP system automatically /*{{{*/
  99. signed edspLikeSystem::Score(Configuration const &)
  100. {
  101. return -1000;
  102. }
  103. /*}}}*/
  104. // System::FindIndex - Get an index file for status files /*{{{*/
  105. bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File,
  106. pkgIndexFile *&Found) const
  107. {
  108. if (StatusFile == 0)
  109. return false;
  110. if (StatusFile->FindInCache(*File.Cache()) == File)
  111. {
  112. Found = StatusFile.get();
  113. return true;
  114. }
  115. return false;
  116. }
  117. /*}}}*/
  118. bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
  119. {
  120. if (StatusFile == nullptr)
  121. {
  122. if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
  123. StatusFile.reset(new edspIndex("/nonexistent/stdin"));
  124. else
  125. StatusFile.reset(new edspIndex(_config->FindFile("edsp::scenario")));
  126. }
  127. List.push_back(StatusFile.get());
  128. return true;
  129. }
  130. /*}}}*/
  131. bool eippSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
  132. {
  133. if (StatusFile == nullptr)
  134. {
  135. if (_config->Find("eipp::scenario", "") == "/nonexistent/stdin")
  136. StatusFile.reset(new eippIndex("/nonexistent/stdin"));
  137. else
  138. StatusFile.reset(new eippIndex(_config->FindFile("eipp::scenario")));
  139. }
  140. List.push_back(StatusFile.get());
  141. return true;
  142. }
  143. /*}}}*/
  144. edspLikeSystem::~edspLikeSystem() {}
  145. edspSystem::~edspSystem()
  146. {
  147. if (tempDir.empty())
  148. return;
  149. RemoveFile("~edspSystem", tempStatesFile);
  150. RemoveFile("~edspSystem", tempPrefsFile);
  151. rmdir(tempDir.c_str());
  152. }
  153. eippSystem::~eippSystem() {}
  154. APT_HIDDEN edspSystem edspSys;
  155. APT_HIDDEN eippSystem eippSys;