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 class edspSystemPrivate
{
33 std::string tempStatesFile
;
34 std::string tempPrefsFile
;
37 edspSystemPrivate() {}
39 void Initialize(Configuration
&Cnf
)
42 Cnf
.Set("Dir::State::extended_states", "/dev/null");
43 Cnf
.Set("Dir::Etc::preferences", "/dev/null");
44 std::string
const tmp
= GetTempDir();
46 snprintf(tmpname
, sizeof(tmpname
), "%s/apt-edsp-solver-XXXXXX", tmp
.c_str());
47 if (NULL
== mkdtemp(tmpname
))
50 tempStatesFile
= flCombine(tempDir
, "extended_states");
51 Cnf
.Set("Dir::State::extended_states", tempStatesFile
);
52 tempPrefsFile
= flCombine(tempDir
, "apt_preferences");
53 Cnf
.Set("Dir::Etc::preferences", tempPrefsFile
);
61 RemoveFile("DeInitialize", tempStatesFile
);
62 RemoveFile("DeInitialize", tempPrefsFile
);
63 rmdir(tempDir
.c_str());
66 ~edspSystemPrivate() { DeInitialize(); }
68 // System::edspSystem - Constructor /*{{{*/
69 edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS
), d(new edspSystemPrivate()), StatusFile(NULL
)
73 // System::~debSystem - Destructor /*{{{*/
74 edspSystem::~edspSystem()
80 // System::Lock - Get the lock /*{{{*/
81 bool edspSystem::Lock()
86 // System::UnLock - Drop a lock /*{{{*/
87 bool edspSystem::UnLock(bool /*NoErrors*/)
92 // System::CreatePM - Create the underlying package manager /*{{{*/
93 // ---------------------------------------------------------------------
94 /* we can't use edsp input as input for real installations - just a
95 simulation can work, but everything else will fail bigtime */
96 pkgPackageManager
*edspSystem::CreatePM(pkgDepCache
* /*Cache*/) const
101 // System::Initialize - Setup the configuration space.. /*{{{*/
102 bool edspSystem::Initialize(Configuration
&Cnf
)
105 Cnf
.Set("Dir::Etc::preferencesparts", "/dev/null");
106 Cnf
.Set("Dir::State::status","/dev/null");
107 Cnf
.Set("Dir::State::lists","/dev/null");
109 Cnf
.Set("Debug::NoLocking", "true");
110 Cnf
.Set("APT::Get::Simulate", "true");
119 // System::ArchiveSupported - Is a file format supported /*{{{*/
120 bool edspSystem::ArchiveSupported(const char * /*Type*/)
125 // System::Score - Never use the EDSP system automatically /*{{{*/
126 signed edspSystem::Score(Configuration
const &)
131 bool edspSystem::AddStatusFiles(std::vector
<pkgIndexFile
*> &List
) /*{{{*/
135 if (_config
->Find("edsp::scenario", "") == "/nonexistent/stdin")
136 StatusFile
= new edspIndex("/nonexistent/stdin");
138 StatusFile
= new edspIndex(_config
->FindFile("edsp::scenario"));
140 List
.push_back(StatusFile
);
144 // System::FindIndex - Get an index file for status files /*{{{*/
145 bool edspSystem::FindIndex(pkgCache::PkgFileIterator File
,
146 pkgIndexFile
*&Found
) const
150 if (StatusFile
->FindInCache(*File
.Cache()) == File
)
160 APT_HIDDEN edspSystem edspSys
;