]> git.saurik.com Git - apt.git/blob - apt-pkg/edsp/edspsystem.cc
download arch:all also for NATIVE_ARCHITECTURE indextargets
[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 <stdlib.h>
24 #include <unistd.h>
25
26 #include <string>
27 #include <vector>
28
29 /*}}}*/
30
31 class edspSystemPrivate {
32 std::string tempDir;
33 std::string tempStatesFile;
34 std::string tempPrefsFile;
35
36 public:
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
61 RemoveFile("DeInitialize", tempStatesFile);
62 RemoveFile("DeInitialize", tempPrefsFile);
63 rmdir(tempDir.c_str());
64 }
65
66 ~edspSystemPrivate() { DeInitialize(); }
67 };
68 // System::edspSystem - Constructor /*{{{*/
69 edspSystem::edspSystem() : pkgSystem("Debian APT solver interface", &debVS), d(new edspSystemPrivate()), StatusFile(NULL)
70 {
71 }
72 /*}}}*/
73 // System::~debSystem - Destructor /*{{{*/
74 edspSystem::~edspSystem()
75 {
76 delete StatusFile;
77 delete d;
78 }
79 /*}}}*/
80 // System::Lock - Get the lock /*{{{*/
81 bool edspSystem::Lock()
82 {
83 return true;
84 }
85 /*}}}*/
86 // System::UnLock - Drop a lock /*{{{*/
87 bool edspSystem::UnLock(bool /*NoErrors*/)
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 */
96 pkgPackageManager *edspSystem::CreatePM(pkgDepCache * /*Cache*/) const
97 {
98 return NULL;
99 }
100 /*}}}*/
101 // System::Initialize - Setup the configuration space.. /*{{{*/
102 bool edspSystem::Initialize(Configuration &Cnf)
103 {
104 d->Initialize(Cnf);
105 Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
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 /*{{{*/
120 bool edspSystem::ArchiveSupported(const char * /*Type*/)
121 {
122 return false;
123 }
124 /*}}}*/
125 // System::Score - Never use the EDSP system automatically /*{{{*/
126 signed edspSystem::Score(Configuration const &)
127 {
128 return -1000;
129 }
130 /*}}}*/
131 bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
132 {
133 if (StatusFile == 0)
134 {
135 if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
136 StatusFile = new edspIndex("/nonexistent/stdin");
137 else
138 StatusFile = new edspIndex(_config->FindFile("edsp::scenario"));
139 }
140 List.push_back(StatusFile);
141 return true;
142 }
143 /*}}}*/
144 // System::FindIndex - Get an index file for status files /*{{{*/
145 bool 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 /*}}}*/
159
160 APT_HIDDEN edspSystem edspSys;