]> git.saurik.com Git - apt.git/blob - apt-pkg/edsp/edspsystem.cc
get right of the hardcoded string-length compares
[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 // System::System - Constructor /*{{{*/
32 edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &debVS)
33 {
34 }
35 edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface")
36 {
37 }
38 /*}}}*/
39 // System::Lock - Get the lock /*{{{*/
40 bool edspLikeSystem::Lock()
41 {
42 return true;
43 }
44 /*}}}*/
45 // System::UnLock - Drop a lock /*{{{*/
46 bool edspLikeSystem::UnLock(bool /*NoErrors*/)
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 */
55 pkgPackageManager *edspLikeSystem::CreatePM(pkgDepCache * /*Cache*/) const
56 {
57 return nullptr;
58 }
59 /*}}}*/
60 // System::Initialize - Setup the configuration space.. /*{{{*/
61 bool edspLikeSystem::Initialize(Configuration &Cnf)
62 {
63 Cnf.Set("Dir::Etc::preferencesparts", "/dev/null");
64 Cnf.Set("Dir::State::status","/dev/null");
65 Cnf.Set("Dir::State::lists","/dev/null");
66 Cnf.Set("Debug::NoLocking", "true");
67 Cnf.Set("APT::Get::Simulate", "true");
68 StatusFile.reset(nullptr);
69 return true;
70 }
71 bool edspSystem::Initialize(Configuration &Cnf)
72 {
73 if (edspLikeSystem::Initialize(Cnf) == false)
74 return false;
75 std::string const tmp = GetTempDir();
76 char tmpname[300];
77 snprintf(tmpname, sizeof(tmpname), "%s/apt-edsp-solver-XXXXXX", tmp.c_str());
78 if (nullptr == mkdtemp(tmpname))
79 return false;
80 tempDir = tmpname;
81 tempStatesFile = flCombine(tempDir, "extended_states");
82 Cnf.Set("Dir::State::extended_states", tempStatesFile);
83 tempPrefsFile = flCombine(tempDir, "apt_preferences");
84 Cnf.Set("Dir::Etc::preferences", tempPrefsFile);
85 return true;
86 }
87 /*}}}*/
88 // System::ArchiveSupported - Is a file format supported /*{{{*/
89 bool edspLikeSystem::ArchiveSupported(const char * /*Type*/)
90 {
91 return false;
92 }
93 /*}}}*/
94 // System::Score - Never use the EDSP system automatically /*{{{*/
95 signed edspLikeSystem::Score(Configuration const &)
96 {
97 return -1000;
98 }
99 /*}}}*/
100 // System::FindIndex - Get an index file for status files /*{{{*/
101 bool edspLikeSystem::FindIndex(pkgCache::PkgFileIterator File,
102 pkgIndexFile *&Found) const
103 {
104 if (StatusFile == 0)
105 return false;
106 if (StatusFile->FindInCache(*File.Cache()) == File)
107 {
108 Found = StatusFile.get();
109 return true;
110 }
111
112 return false;
113 }
114 /*}}}*/
115 bool edspSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List) /*{{{*/
116 {
117 if (StatusFile == nullptr)
118 {
119 if (_config->Find("edsp::scenario", "") == "/nonexistent/stdin")
120 StatusFile.reset(new edspIndex("/nonexistent/stdin"));
121 else
122 StatusFile.reset(new edspIndex(_config->FindFile("edsp::scenario")));
123 }
124 List.push_back(StatusFile.get());
125 return true;
126 }
127 /*}}}*/
128
129 edspLikeSystem::~edspLikeSystem() {}
130 edspSystem::~edspSystem()
131 {
132 if (tempDir.empty())
133 return;
134
135 RemoveFile("~edspSystem", tempStatesFile);
136 RemoveFile("~edspSystem", tempPrefsFile);
137 rmdir(tempDir.c_str());
138 }
139
140 APT_HIDDEN edspSystem edspSys;