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