1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
/* ######################################################################
Set of methods to help writing and reading everything needed for EDSP
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
#include <apt-pkg/edsp.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/version.h>
#include <apt-pkg/policy.h>
#include <apti18n.h>
#include <limits>
#include <stdio.h>
/*}}}*/
// EDSP::WriteScenario - to the given file descriptor /*{{{*/
bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output)
{
// we could use pkgCache::DepType and ::Priority, but these would be lokalized strings…
const char * const PrioMap[] = {0, "important", "required", "standard",
"optional", "extra"};
const char * const DepMap[] = {"", "Depends", "PreDepends", "Suggests",
"Recommends" , "Conflicts", "Replaces",
"Obsoletes", "Breaks", "Enhances"};
for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
{
for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
{
fprintf(output, "Package: %s\n", Pkg.Name());
fprintf(output, "Architecture: %s\n", Ver.Arch());
fprintf(output, "Version: %s\n", Ver.VerStr());
if (Pkg.CurrentVer() == Ver)
fprintf(output, "Installed: yes\n");
if (Pkg->SelectedState == pkgCache::State::Hold)
fprintf(output, "Hold: yes\n");
fprintf(output, "APT-ID: %u\n", Ver->ID);
fprintf(output, "Priority: %s\n", PrioMap[Ver->Priority]);
if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
fprintf(output, "Essential: yes\n");
fprintf(output, "Section: %s\n", Ver.Section());
if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed)
fprintf(output, "Multi-Arch: allowed\n");
else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign)
fprintf(output, "Multi-Arch: foreign\n");
else if (Ver->MultiArch == pkgCache::Version::Same)
fprintf(output, "Multi-Arch: same\n");
signed short Pin = std::numeric_limits<signed short>::min();
for (pkgCache::VerFileIterator File = Ver.FileList(); File.end() == false; ++File) {
signed short const p = Cache.GetPolicy().GetPriority(File.File());
if (Pin < p)
Pin = p;
}
fprintf(output, "APT-Pin: %d\n", Pin);
if (Cache.GetCandidateVer(Pkg) == Ver)
fprintf(output, "APT-Candidate: yes\n");
if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto)
fprintf(output, "APT-Automatic: yes\n");
std::string dependencies[pkgCache::Dep::Enhances + 1];
bool orGroup = false;
for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep)
{
// Ignore implicit dependencies for multiarch here
if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0)
continue;
if (orGroup == false)
dependencies[Dep->Type].append(", ");
dependencies[Dep->Type].append(Dep.TargetPkg().Name());
if (Dep->Version != 0)
dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")");
if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or)
{
dependencies[Dep->Type].append(" | ");
orGroup = true;
}
else
orGroup = false;
}
for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i)
if (dependencies[i].empty() == false)
fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2);
string provides;
for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv)
{
// Ignore implicit provides for multiarch here
if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0)
continue;
provides.append(", ").append(Prv.Name());
}
if (provides.empty() == false)
fprintf(output, "Provides: %s\n", provides.c_str()+2);
fprintf(output, "\n");
}
}
return true;
}
/*}}}*/
// EDSP::WriteRequest - to the given file descriptor /*{{{*/
bool EDSP::WriteRequest(pkgDepCache &Cache, FILE* output, bool const Upgrade,
bool const DistUpgrade, bool const AutoRemove)
{
string del, inst;
for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
{
string* req;
if (Cache[Pkg].Delete() == true)
req = &del;
else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
req = &inst;
else
continue;
req->append(", ").append(Pkg.FullName());
}
fprintf(output, "Request: EDSP 0.2\n");
if (del.empty() == false)
fprintf(output, "Remove: %s\n", del.c_str()+2);
if (inst.empty() == false)
fprintf(output, "Install: %s\n", inst.c_str()+2);
if (Upgrade == true)
fprintf(output, "Upgrade: yes\n");
if (DistUpgrade == true)
fprintf(output, "Dist-Upgrade: yes\n");
if (AutoRemove == true)
fprintf(output, "Autoremove: yes\n");
if (_config->FindB("APT::Solver::Strict-Pinning", true) == false)
fprintf(output, "Strict-Pinning: no\n");
string solverpref("APT::Solver::");
solverpref.append(_config->Find("APT::Solver::Name", "internal")).append("::Preferences");
if (_config->Exists(solverpref) == false)
fprintf(output, "Preferences: %s\n", _config->Find(solverpref,"").c_str());
return true;
}
/*}}}*/
bool EDSP::ReadResponse(FILE* input, pkgDepCache &Cache) { return false; }
bool EDSP::ReadRequest(FILE* input, std::list<std::string> &install,
std::list<std::string> &remove)
{ return false; }
bool EDSP::ApplyRequest(std::list<std::string> const &install,
std::list<std::string> const &remove,
pkgDepCache &Cache)
{ return false; }
// EDSP::WriteSolution - to the given file descriptor /*{{{*/
bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output)
{
bool const Debug = _config->FindB("Debug::EDSPWriter::WriteSolution", false);
for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg)
{
if (Cache[Pkg].Delete() == true)
fprintf(output, "Remove: %d\n", Cache.GetCandidateVer(Pkg)->ID);
else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true)
fprintf(output, "Install: %d\n", Cache.GetCandidateVer(Pkg)->ID);
else
continue;
if (Debug == true)
fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Cache.GetCandidateVer(Pkg).VerStr());
fprintf(output, "\n");
}
return true;
}
/*}}}*/
bool EDSP::WriteError(std::string const &message, FILE* output) { return false; }
|