]> git.saurik.com Git - apt.git/blame - apt-pkg/edsp/edspsystem.cc
algorithms: Replace qsort() by thread-safe std::sort()
[apt.git] / apt-pkg / edsp / edspsystem.cc
CommitLineData
6d38011b
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
e0a78caa 5 This system provides the abstraction to use the scenario file as the
6d38011b
DK
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).
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include <config.h>
13
453b82a3 14#include <apt-pkg/configuration.h>
6d38011b
DK
15#include <apt-pkg/debversion.h>
16#include <apt-pkg/edspindexfile.h>
453b82a3 17#include <apt-pkg/edspsystem.h>
453b82a3
DK
18#include <apt-pkg/pkgcache.h>
19#include <apt-pkg/cacheiterators.h>
188a6fcf 20#include <apt-pkg/fileutl.h>
453b82a3
DK
21
22#include <stddef.h>
188a6fcf
DK
23#include <unistd.h>
24
453b82a3
DK
25#include <string>
26#include <vector>
ea542140 27
6d38011b
DK
28 /*}}}*/
29
188a6fcf
DK
30class edspSystemPrivate {
31 std::string tempDir;
32 std::string tempStatesFile;
33 std::string tempPrefsFile;
34
35public:
36 edspSystemPrivate() {}
37
38 void Initialize(Configuration &Cnf)
39 {
40 DeInitialize();
41 Cnf.Set("Dir::State::extended_states", "/dev/null");
42 Cnf.Set("Dir::Etc::preferences", "/dev/null");
43 std::string const tmp = GetTempDir();
44 char tmpname[100];
45 snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str());
46 if (NULL == mkdtemp(tmpname))
47 return;
48 tempDir = 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);
53 }
54
55 void DeInitialize()
56 {
57 if (tempDir.empty())
58 return;
59
60 unlink(tempStatesFile.c_str());
61 unlink(tempPrefsFile.c_str());
62 rmdir(tempDir.c_str());
63 }
64
65 ~edspSystemPrivate() { DeInitialize(); }
66};
6c55f07a 67// System::edspSystem - Constructor /*{{{*/
188a6fcf 68edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(new edspSystemPrivate()), StatusFile(NULL)
6d38011b 69{
6d38011b
DK
70}
71 /*}}}*/
72// System::~debSystem - Destructor /*{{{*/
73edspSystem::~edspSystem()
74{
75 delete StatusFile;
188a6fcf 76 delete d;
6d38011b
DK
77}
78 /*}}}*/
79// System::Lock - Get the lock /*{{{*/
80bool edspSystem::Lock()
81{
82 return true;
83}
84 /*}}}*/
85// System::UnLock - Drop a lock /*{{{*/
65512241 86bool edspSystem::UnLock(bool /*NoErrors*/)
6d38011b
DK
87{
88 return true;
89}
90 /*}}}*/
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 */
65512241 95pkgPackageManager *edspSystem::CreatePM(pkgDepCache * /*Cache*/) const
6d38011b
DK
96{
97 return NULL;
98}
99 /*}}}*/
100// System::Initialize - Setup the configuration space.. /*{{{*/
101bool edspSystem::Initialize(Configuration &Cnf)
102{
188a6fcf
DK
103 d->Initialize(Cnf);
104 Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
6d38011b
DK
105 Cnf.Set("Dir::State::status","/dev/null");
106 Cnf.Set("Dir::State::lists","/dev/null");
107
108 Cnf.Set("Debug::NoLocking", "true");
109 Cnf.Set("APT::Get::Simulate", "true");
110
111 if (StatusFile) {
112 delete StatusFile;
113 StatusFile = 0;
114 }
115 return true;
116}
117 /*}}}*/
118// System::ArchiveSupported - Is a file format supported /*{{{*/
65512241 119bool edspSystem::ArchiveSupported(const char * /*Type*/)
6d38011b
DK
120{
121 return false;
122}
123 /*}}}*/
c9443c01
DK
124// System::Score - Never use the EDSP system automatically /*{{{*/
125signed edspSystem::Score(Configuration const &)
6d38011b 126{
6d38011b
DK
127 return -1000;
128}
129 /*}}}*/
5465192b 130bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
6d38011b
DK
131{
132 if (StatusFile == 0)
41ceaf02 133 {
7f58427b
DK
134 if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
135 StatusFile = new edspIndex("/nonexistent/stdin");
41ceaf02 136 else
85bcab87 137 StatusFile = new edspIndex(_config->FindFile("edsp::scenario"));
41ceaf02 138 }
6d38011b
DK
139 List.push_back(StatusFile);
140 return true;
141}
142 /*}}}*/
143// System::FindIndex - Get an index file for status files /*{{{*/
144bool edspSystem::FindIndex(pkgCache::PkgFileIterator File,
145 pkgIndexFile *&Found) const
146{
147 if (StatusFile == 0)
148 return false;
149 if (StatusFile->FindInCache(*File.Cache()) == File)
150 {
151 Found = StatusFile;
152 return true;
153 }
154
155 return false;
156}
157 /*}}}*/
dce45dbe
DK
158
159APT_HIDDEN edspSystem edspSys;