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>
30 class edspSystemPrivate
{
32 std::string tempStatesFile
;
33 std::string tempPrefsFile
;
36 edspSystemPrivate() {}
38 void Initialize(Configuration
&Cnf
)
41 Cnf
.Set("Dir::State::extended_states", "/dev/null");
42 Cnf
.Set("Dir::Etc::preferences", "/dev/null");
43 std::string
const tmp
= GetTempDir();
45 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-edsp-solver-XXXXXX", tmp
.c_str());
46 if (NULL
== mkdtemp(tmpname
))
49 tempStatesFile
= flCombine(tempDir
, "extended_states");
50 Cnf
.Set("Dir::State::extended_states", tempStatesFile
);
51 tempPrefsFile
= flCombine(tempDir
, "apt_preferences");
52 Cnf
.Set("Dir::Etc::preferences", tempPrefsFile
);
60 RemoveFile("DeInitialize", tempStatesFile
);
61 RemoveFile("DeInitialize", tempPrefsFile
);
62 rmdir(tempDir
.c_str());
65 ~edspSystemPrivate() { DeInitialize(); }
67 // System::edspSystem - Constructor /*{{{*/
68 edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS
), d(new edspSystemPrivate()), StatusFile(NULL
)
72 // System::~debSystem - Destructor /*{{{*/
73 edspSystem::~edspSystem()
79 // System::Lock - Get the lock /*{{{*/
80 bool edspSystem::Lock()
85 // System::UnLock - Drop a lock /*{{{*/
86 bool edspSystem::UnLock(bool /*NoErrors*/)
91 // System::CreatePM - Create the underlying package manager /*{{{*/
92 // ---------------------------------------------------------------------
93 /* we can't use edsp input as input for real installations - just a
94 simulation can work, but everything else will fail bigtime */
95 pkgPackageManager
*edspSystem::CreatePM(pkgDepCache
* /*Cache*/) const
100 // System::Initialize - Setup the configuration space.. /*{{{*/
101 bool edspSystem::Initialize(Configuration
&Cnf
)
104 Cnf
.Set("Dir::Etc::preferencesparts", "/dev/null");
105 Cnf
.Set("Dir::State::status","/dev/null");
106 Cnf
.Set("Dir::State::lists","/dev/null");
108 Cnf
.Set("Debug::NoLocking", "true");
109 Cnf
.Set("APT::Get::Simulate", "true");
118 // System::ArchiveSupported - Is a file format supported /*{{{*/
119 bool edspSystem::ArchiveSupported(const char * /*Type*/)
124 // System::Score - Never use the EDSP system automatically /*{{{*/
125 signed edspSystem::Score(Configuration
const &)
130 bool edspSystem::AddStatusFiles(std::vector
<pkgIndexFile
*> &List
) /*{{{*/
134 if (_config
->Find("edsp::scenario", "") == "/nonexistent/stdin")
135 StatusFile
= new edspIndex("/nonexistent/stdin");
137 StatusFile
= new edspIndex(_config
->FindFile("edsp::scenario"));
139 List
.push_back(StatusFile
);
143 // System::FindIndex - Get an index file for status files /*{{{*/
144 bool edspSystem::FindIndex(pkgCache::PkgFileIterator File
,
145 pkgIndexFile
*&Found
) const
149 if (StatusFile
->FindInCache(*File
.Cache()) == File
)
159 APT_HIDDEN edspSystem edspSys
;