2
#include "rcacheactor.h"
3
#include "rpackagelister.h"
6
#include <apt-pkg/error.h>
7
#include <apt-pkg/tagfile.h>
8
#include <apt-pkg/strutl.h>
9
#include <apt-pkg/configuration.h>
13
void RCacheActor::notifyCachePostChange()
15
//cout << "RCacheActor::notifyCachePostChange()" << endl;
16
vector<RPackage *> toKeep;
17
vector<RPackage *> toInstall;
18
vector<RPackage *> toReInstall;
19
vector<RPackage *> toUpgrade;
20
vector<RPackage *> toRemove;
21
vector<RPackage *> toDowngrade;
22
vector<RPackage *> notAuthenticated;
23
vector<RPackage *> exclude; // empty
25
//cout << "_laststate: " << _laststate << endl;
26
if (_laststate == NULL)
29
if (_lister->getStateChanges(*_laststate, toKeep, toInstall, toReInstall,
30
toUpgrade, toRemove, toDowngrade,
33
if (toKeep.empty() == false)
34
run(toKeep, ACTION_KEEP);
35
if (toInstall.empty() == false)
36
run(toInstall, ACTION_INSTALL);
37
if (toReInstall.empty() == false)
38
run(toReInstall, ACTION_REINSTALL);
39
if (toUpgrade.empty() == false)
40
run(toUpgrade, ACTION_INSTALL);
41
if (toDowngrade.empty() == false)
42
run(toDowngrade, ACTION_INSTALL);
43
if (toRemove.empty() == false)
44
run(toRemove, ACTION_REMOVE);
52
RCacheActorRecommends::RCacheActorRecommends(RPackageLister *lister,
56
FileFd F(FileName, FileFd::ReadOnly);
57
if (_error->PendingError()) {
58
_error->Error("could not open recommends file %s", FileName.c_str());
62
pkgTagSection Section;
67
while (Tags.Step(Section)) {
68
string Name = Section.FindS("Name");
69
string Match = Section.FindS("Match");
70
string Recommends = Section.FindS("Recommends");
71
if (Name.empty() == true || Recommends.empty() == true)
74
ListType *List = NULL;
75
if (Match.empty() == true || Match == "exact") {
77
} else if (Match == "wildcard") {
78
List = &_map_wildcard[Name];
79
} else if (Match == "regex") {
80
regex_t *ptrn = new regex_t;
81
if (regcomp(ptrn, Name.c_str(),
82
REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) {
84
Warning("Bad regular expression '%s' in Recommends file.",
88
List = &_map_regex[ptrn];
92
const char *C = Recommends.c_str();
95
if (ParseQuoteWord(C, S))
102
RCacheActorRecommends::~RCacheActorRecommends()
104
for (RegexMapType::const_iterator RMapI = _map_regex.begin();
105
RMapI != _map_regex.end(); RMapI++) {
110
void RCacheActorRecommends::setLanguageCache()
112
string LangList = _config->Find("Volatile::Languages", "");
113
if (LangList == _langLast)
118
if (LangList.empty())
121
_langLast = LangList;
123
const char *C = LangList.c_str();
126
if (ParseQuoteWord(C, S)) {
127
string::size_type end;
129
if (end != string::npos)
130
S.erase(end, string::npos);
131
_langCache.push_back(S);
133
if (end != string::npos) {
134
S.erase(end, string::npos);
135
_langCache.push_back(S);
141
void RCacheActorRecommends::notifyCachePostChange()
143
if (_config->FindB("Synaptic::UseRecommends", true) == true)
144
RCacheActor::notifyCachePostChange();
147
void RCacheActorRecommends::run(vector<RPackage *> &PkgList, int Action)
151
const ListType *List;
152
MapType::const_iterator MapI;
153
for (vector<RPackage *>::const_iterator PkgI = PkgList.begin();
154
PkgI != PkgList.end(); PkgI++) {
155
name = (*PkgI)->name();
157
MapI = _map.find(name);
158
if (MapI != _map.end()) {
159
List = &MapI->second;
161
if (_map_wildcard.empty() == false) {
162
for (MapI = _map_wildcard.begin();
163
MapI != _map_wildcard.end(); MapI++) {
164
if (fnmatch(MapI->first.c_str(), name, 0) == 0) {
165
List = &MapI->second;
170
if (List == NULL && _map_regex.empty() == false) {
171
for (RegexMapType::const_iterator RMapI = _map_regex.begin();
172
RMapI != _map_regex.end(); RMapI++) {
173
if (regexec(RMapI->first, name, 0, 0, 0) == 0) {
174
List = &RMapI->second;
181
for (ListType::const_iterator ListI = List->begin();
182
ListI != List->end(); ListI++) {
183
const string &Recommends = *ListI;
184
if (actOnPkg(Recommends, Action) == false
185
&& Recommends.find("$(LANG)") != string::npos) {
186
for (vector < string >::const_iterator LI = _langCache.begin();
187
LI != _langCache.end(); LI++) {
188
string Parsed = SubstVar(Recommends, "$(LANG)", *LI);
189
actOnPkg(Parsed, Action);