1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 This system provides the abstraction to use the scenario file as the
6 only source of package information to be able to feed the created file
7 back to APT for its own consumption (eat your own dogfood).
9 ##################################################################### */
11 // Include Files /*{{{*/
14 #include <apt-pkg/configuration.h>
15 #include <apt-pkg/debversion.h>
16 #include <apt-pkg/edspindexfile.h>
17 #include <apt-pkg/edspsystem.h>
18 #include <apt-pkg/pkgcache.h>
19 #include <apt-pkg/cacheiterators.h>
20 #include <apt-pkg/fileutl.h>
31 // System::System - Constructor /*{{{*/
32 edspLikeSystem::edspLikeSystem(char const * const Label
) : pkgSystem(Label
, &debVS
)
35 edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
38 eippSystem::eippSystem() : edspLikeSystem("Debian APT planner interface")
42 // System::Lock - Get the lock /*{{{*/
43 bool edspLikeSystem::Lock()
48 // System::UnLock - Drop a lock /*{{{*/
49 bool edspLikeSystem::UnLock(bool /*NoErrors*/)
54 // System::CreatePM - Create the underlying package manager /*{{{*/
55 // ---------------------------------------------------------------------
56 /* we can't use edsp input as input for real installations - just a
57 simulation can work, but everything else will fail bigtime */
58 pkgPackageManager
*edspLikeSystem::CreatePM(pkgDepCache
* /*Cache*/) const
63 // System::Initialize - Setup the configuration space.. /*{{{*/
64 bool edspLikeSystem::Initialize(Configuration
&Cnf
)
66 Cnf
.Set("Dir::Log", "/dev/null");
67 // state is included completely in the input files
68 Cnf
.Set("Dir::Etc::preferences", "/dev/null");
69 Cnf
.Set("Dir::Etc::preferencesparts", "/dev/null");
70 Cnf
.Set("Dir::State::status","/dev/null");
71 Cnf
.Set("Dir::State::extended_states","/dev/null");
72 Cnf
.Set("Dir::State::lists","/dev/null");
73 // do not store an mmap cache
74 Cnf
.Set("Dir::Cache::pkgcache", "");
75 Cnf
.Set("Dir::Cache::srcpkgcache", "");
76 // the protocols only propose actions, not do them
77 Cnf
.Set("Debug::NoLocking", "true");
78 Cnf
.Set("APT::Get::Simulate", "true");
80 StatusFile
.reset(nullptr);
83 bool edspSystem::Initialize(Configuration
&Cnf
)
85 if (edspLikeSystem::Initialize(Cnf
) == false)
87 std::string
const tmp
= GetTempDir();
89 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-edsp-solver-XXXXXX", tmp
.c_str());
90 if (nullptr == mkdtemp(tmpname
))
93 tempStatesFile
= flCombine(tempDir
, "extended_states");
94 Cnf
.Set("Dir::State::extended_states", tempStatesFile
);
95 tempPrefsFile
= flCombine(tempDir
, "apt_preferences");
96 Cnf
.Set("Dir::Etc::preferences", tempPrefsFile
);
100 // System::ArchiveSupported - Is a file format supported /*{{{*/
101 bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
106 // System::Score - Never use the EDSP system automatically /*{{{*/
107 signed edspLikeSystem::Score(Configuration
const &)
112 // System::FindIndex - Get an index file for status files /*{{{*/
113 bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File
,
114 pkgIndexFile
*&Found
) const
118 if (StatusFile
->FindInCache(*File
.Cache()) == File
)
120 Found
= StatusFile
.get();
127 bool edspSystem::AddStatusFiles(std::vector
<pkgIndexFile
*> &List
) /*{{{*/
129 if (StatusFile
== nullptr)
131 if (_config
->Find("edsp::scenario", "") == "/nonexistent/stdin")
132 StatusFile
.reset(new edspIndex("/nonexistent/stdin"));
134 StatusFile
.reset(new edspIndex(_config
->FindFile("edsp::scenario")));
136 List
.push_back(StatusFile
.get());
140 bool eippSystem::AddStatusFiles(std::vector
<pkgIndexFile
*> &List
) /*{{{*/
142 if (StatusFile
== nullptr)
144 if (_config
->Find("eipp::scenario", "") == "/nonexistent/stdin")
145 StatusFile
.reset(new eippIndex("/nonexistent/stdin"));
147 StatusFile
.reset(new eippIndex(_config
->FindFile("eipp::scenario")));
149 List
.push_back(StatusFile
.get());
154 edspLikeSystem::~edspLikeSystem() {}
155 edspSystem::~edspSystem()
160 RemoveFile("~edspSystem", tempStatesFile
);
161 RemoveFile("~edspSystem", tempPrefsFile
);
162 rmdir(tempDir
.c_str());
164 eippSystem::~eippSystem() {}
166 APT_HIDDEN edspSystem edspSys
;
167 APT_HIDDEN eippSystem eippSys
;