]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/edsp/edspsystem.cc
Add missing includes and external definitions
[apt.git] / apt-pkg / edsp / edspsystem.cc
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
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).
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
12#include <config.h>
13
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>
21
22#include <stddef.h>
23#include <stdlib.h>
24#include <unistd.h>
25
26#include <string>
27#include <vector>
28
29 /*}}}*/
30
31// System::System - Constructor /*{{{*/
32edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &debVS)
33{
34}
35edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
36{
37}
38eippSystem::eippSystem() : edspLikeSystem("Debian APT planner interface")
39{
40}
41 /*}}}*/
42// System::Lock - Get the lock /*{{{*/
43bool edspLikeSystem::Lock()
44{
45 return true;
46}
47 /*}}}*/
48// System::UnLock - Drop a lock /*{{{*/
49bool edspLikeSystem::UnLock(bool /*NoErrors*/)
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 */
58pkgPackageManager *edspLikeSystem::CreatePM(pkgDepCache * /*Cache*/) const
59{
60 return nullptr;
61}
62 /*}}}*/
63// System::Initialize - Setup the configuration space.. /*{{{*/
64bool edspLikeSystem::Initialize(Configuration &Cnf)
65{
66 Cnf.Set("Dir::Log", "/dev/null");
67 // state is included completely in the input files
68 Cnf.Set("Dir::Etc::preferences", "/dev/null");
69 Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
70 Cnf.Set("Dir::State::status","/dev/null");
71 Cnf.Set("Dir::State::extended_states","/dev/null");
72 Cnf.Set("Dir::State::lists","/dev/null");
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
77 Cnf.Set("Debug::NoLocking", "true");
78 Cnf.Set("APT::Get::Simulate", "true");
79
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);
97 return true;
98}
99 /*}}}*/
100// System::ArchiveSupported - Is a file format supported /*{{{*/
101bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
102{
103 return false;
104}
105 /*}}}*/
106// System::Score - Never use the EDSP system automatically /*{{{*/
107signed edspLikeSystem::Score(Configuration const &)
108{
109 return -1000;
110}
111 /*}}}*/
112// System::FindIndex - Get an index file for status files /*{{{*/
113bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File,
114 pkgIndexFile *&Found) const
115{
116 if (StatusFile == 0)
117 return false;
118 if (StatusFile->FindInCache(*File.Cache()) == File)
119 {
120 Found = StatusFile.get();
121 return true;
122 }
123
124 return false;
125}
126 /*}}}*/
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 /*}}}*/
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 /*}}}*/
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}
164eippSystem::~eippSystem() {}
165
166APT_HIDDEN edspSystem edspSys;
167APT_HIDDEN eippSystem eippSys;