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