]> git.saurik.com Git - apt.git/blame - apt-pkg/edsp/edspsystem.cc
Add missing includes and external definitions
[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
d59671c9
DK
31// System::System - Constructor /*{{{*/
32edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &debVS)
6d38011b 33{
6d38011b 34}
d59671c9 35edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
6d38011b 36{
f74d99c6 37}
8e99b22c 38eippSystem::eippSystem() : edspLikeSystem("Debian APT planner interface")
f74d99c6 39{
6d38011b
DK
40}
41 /*}}}*/
42// System::Lock - Get the lock /*{{{*/
d59671c9 43bool edspLikeSystem::Lock()
6d38011b
DK
44{
45 return true;
46}
47 /*}}}*/
48// System::UnLock - Drop a lock /*{{{*/
d59671c9 49bool edspLikeSystem::UnLock(bool /*NoErrors*/)
6d38011b
DK
50{
51 return true;
52}
53 /*}}}*/
54// System::CreatePM - Create the underlying package manager /*{{{*/
55// ---------------------------------------------------------------------
56/* we can't use edsp input as input for real installations - just a
57 simulation can work, but everything else will fail bigtime */
d59671c9 58pkgPackageManager *edspLikeSystem::CreatePM(pkgDepCache * /*Cache*/) const
6d38011b 59{
d59671c9 60 return nullptr;
6d38011b
DK
61}
62 /*}}}*/
63// System::Initialize - Setup the configuration space.. /*{{{*/
d59671c9 64bool edspLikeSystem::Initialize(Configuration &Cnf)
6d38011b 65{
385d9f2f 66 Cnf.Set("Dir::Log", "/dev/null");
35f3ed06 67 // state is included completely in the input files
385d9f2f 68 Cnf.Set("Dir::Etc::preferences", "/dev/null");
188a6fcf 69 Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
6d38011b 70 Cnf.Set("Dir::State::status","/dev/null");
385d9f2f 71 Cnf.Set("Dir::State::extended_states","/dev/null");
6d38011b 72 Cnf.Set("Dir::State::lists","/dev/null");
35f3ed06
DK
73 // do not store an mmap cache
74 Cnf.Set("Dir::Cache::pkgcache", "");
75 Cnf.Set("Dir::Cache::srcpkgcache", "");
76 // the protocols only propose actions, not do them
6d38011b
DK
77 Cnf.Set("Debug::NoLocking", "true");
78 Cnf.Set("APT::Get::Simulate", "true");
35f3ed06 79
d59671c9
DK
80 StatusFile.reset(nullptr);
81 return true;
82}
83bool edspSystem::Initialize(Configuration &Cnf)
84{
85 if (edspLikeSystem::Initialize(Cnf) == false)
86 return false;
87 std::string const tmp = GetTempDir();
88 char tmpname[300];
89 snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str());
90 if (nullptr == mkdtemp(tmpname))
91 return false;
92 tempDir = tmpname;
93 tempStatesFile = flCombine(tempDir, "extended_states");
94 Cnf.Set("Dir::State::extended_states", tempStatesFile);
95 tempPrefsFile = flCombine(tempDir, "apt_preferences");
96 Cnf.Set("Dir::Etc::preferences", tempPrefsFile);
6d38011b
DK
97 return true;
98}
99 /*}}}*/
100// System::ArchiveSupported - Is a file format supported /*{{{*/
d59671c9 101bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
6d38011b
DK
102{
103 return false;
104}
105 /*}}}*/
c9443c01 106// System::Score - Never use the EDSP system automatically /*{{{*/
d59671c9 107signed edspLikeSystem::Score(Configuration const &)
6d38011b 108{
6d38011b
DK
109 return -1000;
110}
111 /*}}}*/
6d38011b 112// System::FindIndex - Get an index file for status files /*{{{*/
d59671c9 113bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File,
6d38011b
DK
114 pkgIndexFile *&Found) const
115{
116 if (StatusFile == 0)
117 return false;
118 if (StatusFile->FindInCache(*File.Cache()) == File)
119 {
d59671c9 120 Found = StatusFile.get();
6d38011b
DK
121 return true;
122 }
123
124 return false;
125}
126 /*}}}*/
d59671c9
DK
127bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
128{
129 if (StatusFile == nullptr)
130 {
131 if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
132 StatusFile.reset(new edspIndex("/nonexistent/stdin"));
133 else
134 StatusFile.reset(new edspIndex(_config->FindFile("edsp::scenario")));
135 }
136 List.push_back(StatusFile.get());
137 return true;
138}
139 /*}}}*/
f74d99c6
DK
140bool eippSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
141{
142 if (StatusFile == nullptr)
143 {
144 if (_config->Find("eipp::scenario", "") == "/nonexistent/stdin")
145 StatusFile.reset(new eippIndex("/nonexistent/stdin"));
146 else
147 StatusFile.reset(new eippIndex(_config->FindFile("eipp::scenario")));
148 }
149 List.push_back(StatusFile.get());
150 return true;
151}
152 /*}}}*/
d59671c9
DK
153
154edspLikeSystem::~edspLikeSystem() {}
155edspSystem::~edspSystem()
156{
157 if (tempDir.empty())
158 return;
159
160 RemoveFile("~edspSystem", tempStatesFile);
161 RemoveFile("~edspSystem", tempPrefsFile);
162 rmdir(tempDir.c_str());
163}
f74d99c6 164eippSystem::~eippSystem() {}
dce45dbe
DK
165
166APT_HIDDEN edspSystem edspSys;
f74d99c6 167APT_HIDDEN eippSystem eippSys;