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