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